-
Notifications
You must be signed in to change notification settings - Fork 8.3k
lib/os/mempool: Fix corruption case with block splitting #16966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/os/mempool: Fix corruption case with block splitting #16966
Conversation
lib/os/mempool.c
Outdated
There was a problem hiding this comment.
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.
fe4621e to
fff4f07
Compare
|
Spread out formatting for clarity |
|
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). |
e7a94d9 to
b36f732
Compare
|
On Thu, 20 Jun 2019, Andy Ross wrote:
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).
I agree with the first patch, the block_fits() one, for now at least.
I also agreed with the second patch in principle. Now that I've
actually seen it I must retract that.
Your patch is not sufficient. You missed one header file. But more
importantly, you are missing some small but again fundamental details.
Please consider #16996 where I provided the complete explanation.
|
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>
b36f732 to
59c39b5
Compare
|
Yank duplicated fix. Rebase. |
|
In case my opinion is still required, I approve this PR as it is.
Please someone merge this ASAP. The potential for weird bugs is real without it.
|
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>
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