-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
JDK-8295889: NMT preinit code does not handle allocation errors #10855
JDK-8295889: NMT preinit code does not handle allocation errors #10855
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
Linux x86 errors unrelated. I did build and test manually 32-bit on Ubuntu, all fine. |
Webrevs
|
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.
Doesn't seem unreasonable to check for OOM even though highly unlikely during VM init. But how would an overflow arise in practice? Seems like something more suited for an assertion.
Hi David, thanks for looking at this. Assert makes sense, I will do that. It can happen only by malpractice, if size is controlled via outside input. I cannot see a path where this would happen in VM preinit time though, so this is just theoretical. The issue was inspired by 8286519, where Harold did the same os::malloc. That made me look more closely at some corner cases and how they are handled. Another issue I work on is https://bugs.openjdk.org/browse/JDK-8295865. |
Overflow is really only a concern if the incoming value could be user-supplied/influenced. For pure VM code an assert would suffice to guard against accident (mainly via whitebox or other test code that might try to hit edge cases). |
// --------- NMTPreInitAllocation -------------- | ||
|
||
NMTPreInitAllocation* NMTPreInitAllocation::do_alloc(size_t payload_size) { | ||
const size_t outer_size = sizeof(NMTPreInitAllocation) + payload_size; | ||
guarantee(outer_size > payload_size, "Overflow"); |
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.
I was suggesting an assertion as this is a VM programming error we should catch during testing in't it?
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.
Guarantee as a protection against future bitrot. I am not even 100% sure there are not paths today that are controlled via outside input. I am even less sure about the future. Therefore I protect the release version too. Are you concerned about runtime costs? It is just a comparison.
OTOH I have no strong emotions here. If you insist, I can make it debug only.
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.
I'm more concerned that we don't know if this path may be influenced by external input. :(
These kind of "just in case" checks all add up.
But I won't insist on a change.
// --------- NMTPreInitAllocation -------------- | ||
|
||
NMTPreInitAllocation* NMTPreInitAllocation::do_alloc(size_t payload_size) { | ||
const size_t outer_size = sizeof(NMTPreInitAllocation) + payload_size; | ||
guarantee(outer_size > payload_size, "Overflow"); |
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.
I'm more concerned that we don't know if this path may be influenced by external input. :(
These kind of "just in case" checks all add up.
But I won't insist on a change.
@tstuefe This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 92 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
The only randomness source I can think of is arguments. Argument handling is done before parsing and therefore before NMT initialization in preinit time. It influences the number of allocated blocks as well as their size. So if someone were to pass an argument close to size_max to the VM, it would run into overflow :-) but that is not possible, of course.
True. But as this is security relevant, I'll leave it in. I rather shave off time somewhere else. E.g. in the real os::malloc, there are some optimizations we can do. E.g. getting rid of the atomic allocation counters in os.cpp since we do have NMT counting and malloc limits now. That is one thing I have on my list. |
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.
I would prefer more detailed guarantee output like for example
guarantee(outer_size > payload_size, "Overflow - %zu must be larger than payload size %zu", outer_size, payload_size);
But it is okay as it is too, approved.
Thanks Matthias! I expect this never to fire, and if it does, someone needs to dive in anyway. |
/integrate |
Going to push as commit cf121df.
Your commit was automatically rebased without conflicts. |
The NMT preinit allocator (used for os::malloc and friends before the VM is initialized) does not handle malloc errors, nor does it handle overflows due to large sizes (it uses malloc headers too). Both cases need to be handled.
However, we can keep matters very simple. No need to propagate errors up to the caller; we can just fatal out on errors here since, in this phase, there is no alternative for failed allocations.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10855/head:pull/10855
$ git checkout pull/10855
Update a local copy of the PR:
$ git checkout pull/10855
$ git pull https://git.openjdk.org/jdk pull/10855/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 10855
View PR using the GUI difftool:
$ git pr show -t 10855
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10855.diff