RFR: 8372493: [asan] java/foreign/sharedclosejvmti/TestSharedCloseJvmti.java triggers heap-use-after-free
Jorn Vernee
jvernee at openjdk.org
Wed Dec 17 13:55:06 UTC 2025
ASAN correctly detected a use-after-free in this test.
The issue is that an async `ScopedAccessError` is thrown while executing java code as part of a JVMTI callback. This exception is meant to unwind out of a scoped memory access, to prevent access to memory that has already been freed. But, currently the native agent code is printing and clearing the exception, which doesn't prevent the memory access from occurring, leading to a use-after-free.
Ideally, the agent should propagate the exception to the place in the Java code where the JVMTI event happens, but it is not possible to exit the callback with a pending exception, and AFAICT there is no JVMTI API for propagating async exceptions that are thrown during a JVMTI callback. So, the only sane thing the test can do is exit the process, which is what I've implemented here.
This fixes the test, but it leaves the larger question of how JVMTI agents should deal with async exceptions unresolved.
-------------
Commit messages:
- Cleanup memory management code
- Terminate after receiving ScopedAccessError
Changes: https://git.openjdk.org/jdk/pull/28853/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28853&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8372493
Stats: 41 lines in 2 files changed: 27 ins; 5 del; 9 mod
Patch: https://git.openjdk.org/jdk/pull/28853.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28853/head:pull/28853
PR: https://git.openjdk.org/jdk/pull/28853
More information about the core-libs-dev
mailing list