Skip to content

Conversation

@andyross
Copy link
Contributor

The block_fits() predicate was borked. It would check that a block
fits within the bounds of the whole heap. But that's not enough:
because of alignment changes between levels the sub-blocks may be
adjusted forward. It needs to fit inside the PARENT block that it was
split from.

What could happen at runtime is that the last subblocks of a
misaligned parent block would overlap memory from subsequent blocks,
or even run off the end of the heap. That's bad.

Change the API of block_fits() a little so it can extract the parent
region and do this properly.

Fixes #15279. Passes test introduced in #16728 to demonstrate what
seems like the same issue.

Signed-off-by: Andy Ross andrew.j.ross@intel.com

lib/os/mempool.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest parens around lvl == 0 for clarity.
same deal with following line.
or just use a regular if { } else { }. I had to blink at this a lot to correctly parse it.

@andyross andyross force-pushed the mempool-block-fits branch from fe4621e to fff4f07 Compare June 20, 2019 19:14
@andyross
Copy link
Contributor Author

Spread out formatting for clarity

@andyross
Copy link
Contributor Author

One more tiny patch to address a buffer allocation bug @npitre pointed out (who I still can't seem to add as a reviewer, but who can surely just jump in).

@zephyrbot zephyrbot added the area: API Changes to public APIs label Jun 20, 2019
@andyross andyross force-pushed the mempool-block-fits branch from e7a94d9 to b36f732 Compare June 22, 2019 14:48
@npitre
Copy link

npitre commented Jun 22, 2019 via email

The block_fits() predicate was borked.  It would check that a block
fits within the bounds of the whole heap.  But that's not enough:
because of alignment changes between levels the sub-blocks may be
adjusted forward.  It needs to fit inside the PARENT block that it was
split from.

What could happen at runtime is that the last subblocks of a
misaligned parent block would overlap memory from subsequent blocks,
or even run off the end of the heap.  That's bad.

Change the API of block_fits() a little so it can extract the parent
region and do this properly.

Fixes zephyrproject-rtos#15279.  Passes test introduced in zephyrproject-rtos#16728 to demonstrate what
seems like the same issue.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
@andyross andyross force-pushed the mempool-block-fits branch from b36f732 to 59c39b5 Compare June 24, 2019 17:42
@andyross
Copy link
Contributor Author

Yank duplicated fix. Rebase.

@npitre
Copy link

npitre commented Jun 26, 2019 via email

@andrewboie andrewboie merged commit d0490fe into zephyrproject-rtos:master Jun 26, 2019
npitre pushed a commit to npitre/zephyr that referenced this pull request Jun 26, 2019
This test demonstrates a serious bugs that exist in the mem-pool code
as ovf Zephyr v1.14.0, and probably earlier versions too. This bug is
fixed with PR zephyrproject-rtos#16966.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: API Changes to public APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mempool alignment might cause a memory block allocated twice

4 participants