Integrated: JDK-8299790: os::print_hex_dump is racy
Thomas Stuefe
stuefe at openjdk.org
Thu Aug 10 07:38:30 UTC 2023
On Sun, 16 Jul 2023 09:55:43 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> Tiny fix for a tiny problem.
>
> `os::print_hex_dump` uses `os::is_readable_pointer` to check the to-be-printed memory for readability; `os::is_readable_pointer` uses `SafeFetch` 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 use `SafeFetch` 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.
This pull request has now been integrated.
Changeset: 8f28809a
Author: Thomas Stuefe <stuefe at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/8f28809aa87b1026cdbdd1ea88da3c7f0c994697
Stats: 72 lines in 2 files changed: 45 ins; 4 del; 23 mod
8299790: os::print_hex_dump is racy
Reviewed-by: shade, dholmes
-------------
PR: https://git.openjdk.org/jdk/pull/14895
More information about the hotspot-runtime-dev
mailing list