-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8349554: [UBSAN] os::attempt_reserve_memory_between reported applying non-zero offset to non-null pointer produced null pointer #23508
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
Conversation
… non-zero offset to non-null pointer produced null pointer
|
👋 Welcome back syan! A progress list of the required criteria for merging this PR into |
|
@sendaoYan 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 14 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 |
|
@sendaoYan The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
stefank
left a comment
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 not convinced that this is the nicest way to fix the issue. This change now makes it so that some of the addresses are typed as pointers and hi_end is typed as an integer. When doing these kind of changes I think it is important to take a step back and think about the types and see if there are ways to make them consistent in the changed functions.
I wonder if a change like:
- if ((uintptr_t)hi_end < bytes) {
+ if ((uintptr_t)hi_end <= bytes) {
Would silence the compiler as well? Given that it would filter away the problematic case that leads to a null pointer.
But even that compares an address with a range, which is also unfortunate (IMHO). So, I think it would be nicer to extract the max range and use that in the comparison:
uintptr_t max_range = hi_end - nullptr;
if (max_range <= bytes) {
Just to be a bit cleaner with the types.
Or maybe even use the lowest attach point instead of nullptr:
uintptr_t max_range = hi_end - lo_att;
if (max_range < bytes) {
and then we can keep < instead of <= because hi_end - bytes will then not evaluate to null.
Yes.
Should we change like below: |
Do you know if that only happens in our tests and not in normal JVM runs? If it is only in testing then it would be preferable to add preconditions to the function and then fix the testing to adhere to the preconditions. With that said, an easy fix would be to just continue the tradition of the function and have early returns when this happens: |
It happens in normal JVM runs. The command is: build/linux-x86_64-server-slowdebug/images/jdk/bin/java -Xlog:os+map=trace -Xshare:dump -XX:SharedArchiveFile=build/linux-x86_64-server-slowdebug/images/jdk/lib/server/classes_nocoops_coh.jsa -server -XX:-UseCompressedOops -XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders -Xmx128M -Xms128M -XX:+UseG1GCThe output snippet: The call trace: |
The expr So should change like: |
|
Sure. Let's leave any potential type cleanups for the future. |
Okey, PR has been updated. |
tstuefe
left a comment
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.
Good. Thanks for fixing this. @stefank thanks for looking at this.
stefank
left a comment
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.
Looks good. Thanks for fixing.
|
The following is not a request to change your PR. It's merely an explanation of what I think could be done to this function to get rid of some of the comparisons of bytes/ranges with pointers: This is completely untested |
|
Going to push as commit 8f6ccde.
Your commit was automatically rebased without conflicts. |
|
@sendaoYan Pushed as commit 8f6ccde. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi all,
Function 'os::attempt_reserve_memory_between(char*, char*, size_t, size_t, bool)' 'src/hotspot/share/runtime/os.cpp' reported "runtime error: applying non-zero offset to non-null pointer 0x000000001000 produced null pointer" by address sanitizer. Gtest in function 'os_attempt_reserve_memory_between_combos_vm_Test::TestBody' at file test/hotspot/gtest/runtime/test_os_reserve_between.cpp call 'os::attempt_reserve_memory_between (min=0x0, max=0x1000, bytes=4096, alignment=4096, randomize=true)' trigger this failure. Before this PR, the pointer var
hi_endget value frommax0x1000, and then apply offsetbytes, andmaxequalsbytes, thus address sanitizer report this failure.This PR change from
hi_end < bytestohi_end <= byteswill eliminate the undefined behaviour. Risk is low.Additional testing:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23508/head:pull/23508$ git checkout pull/23508Update a local copy of the PR:
$ git checkout pull/23508$ git pull https://git.openjdk.org/jdk.git pull/23508/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23508View PR using the GUI difftool:
$ git pr show -t 23508Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23508.diff
Using Webrev
Link to Webrev Comment