-
Notifications
You must be signed in to change notification settings - Fork 5.8k
JDK-8299790: os::print_hex_dump is racy #14895
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-8299790: os::print_hex_dump is racy #14895
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
b0e3065
to
d9d7a71
Compare
d9d7a71
to
1c78457
Compare
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.
Some comments...
Thank you @shipilev. I worked in your feedback and massaged the code a bit. |
Friendly ping... still need a second review. |
Oh, I don't even have the first one... @shipilev, any more suggestions? (this is not terribly important, no pressure) |
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.
Seems reasonable. Just one (hopefully) minor thing below.
Thanks.
@@ -34,6 +34,7 @@ | |||
#include "utilities/macros.hpp" | |||
#include "utilities/ostream.hpp" | |||
#include "unittest.hpp" | |||
#include "gmock/gmock.h" |
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.
Is this a leftover?
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.
Oops, thank you. That slipped by me, it's from an earlier experiment.
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.
It's a pity that we would read full intptr_t
for every unit, which would mean that reading byte-unit block of N bytes would issue 8*N SafeFetch reads. But I guess it is fine, given the old code did SafeFetch32
anyway.
That looks like fixing another implicit bug, if we are reading the unaligned 64-bit location at readable boundary: is_readable_pointer
would read 32-bits and return true
for first 4 bytes of the location, and then we go in and read 64 bits with print_hex_readable_pointer
with unitsize = 8
. Which might break if the last 4 bytes of that read are actually outside the readable range.
@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 45 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 |
I thought about this too but then refrained from implementing a "read intptr_t then print bytes" to keep the patch complexity low. I think another, simpler, patch would be worthwhile where we split print_hex_dump into two variants, one using SafeFetch and one just reading, and use the former one only if we are unsure about the memory content. E.g. at hs-err file dumping. There is no need to pay for SafeFetch when hexdumping e.g. for logging. Maybe for a future RFE.
Oh, I missed that. Nice :) Thanks for the review! |
@dholmes-ora are you okay with the patch in its current form? |
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 okay to me. Thanks
Thanks David! /integrate |
Going to push as commit 8f28809.
Your commit was automatically rebased without conflicts. |
Tiny fix for a tiny problem.
os::print_hex_dump
usesos::is_readable_pointer
to check the to-be-printed memory for readability;os::is_readable_pointer
usesSafeFetch
to probe the memory for access, which is good, but then, by the time we actually print that information, we reread the memory location again. It may be unreadable now (either because the region had been unmapped or protected by a concurrent thread), and we would crash the VM.The patch rewrites the function to not use
os::is_readable_pointer
, but to useSafeFetch
to read from memory directly and then use the result of that read for printing. That requires a bit of bit fiddling, since we only can read word-wise, but the hex-dump could be in units between bytes and qwords.Tests: manual and GHA-driven gtests on all platforms. The gtests test this function exhaustively.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14895/head:pull/14895
$ git checkout pull/14895
Update a local copy of the PR:
$ git checkout pull/14895
$ git pull https://git.openjdk.org/jdk.git pull/14895/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14895
View PR using the GUI difftool:
$ git pr show -t 14895
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14895.diff
Webrev
Link to Webrev Comment