RFR: 8372493: [asan] java/foreign/sharedclosejvmti/TestSharedCloseJvmti.java triggers heap-use-after-free

Jorn Vernee jvernee at openjdk.org
Wed Dec 17 13:55:10 UTC 2025


On Tue, 16 Dec 2025 18:47:34 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> 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.

test/jdk/java/foreign/sharedclosejvmti/TestSharedCloseJvmti.java line 86:

> 84:                     SINK = segment.get(ValueLayout.JAVA_INT, 0); // should throw
> 85:                     System.err.println("No exception thrown during outer memory access");
> 86:                     System.exit(1);

This code is never executed because we terminate the process during the memory access before this, but this check was missing from the initial implementation of the test. This memory access should not complete normally.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28853#discussion_r2624388615


More information about the core-libs-dev mailing list