Replace sun.misc.Unsafe with MethodHandle for access control bypass#80
Open
chhsiao90 wants to merge 1 commit into
Open
Replace sun.misc.Unsafe with MethodHandle for access control bypass#80chhsiao90 wants to merge 1 commit into
chhsiao90 wants to merge 1 commit into
Conversation
… 9-21 Replace brittle reflection-based approaches with IMPL_LOOKUP obtained through sun.misc.Unsafe raw memory reads, which bypasses module system checks entirely and works across all Java 9-21 versions without --add-opens: - Java 9-15: replace Lookup constructor hack (setAccessible fails on Java 12+ due to AccessibleObject.override blacklist) with IMPL_LOOKUP - Java 16-21: replace objectFieldOffset(override)+putBoolean (fails on Java 21 where override is hidden from getDeclaredField) with IMPL_LOOKUP - Java 16+: MethodHandles.privateLookupIn when --add-opens is present - Java 22+ without --add-opens: throws UnsupportedOperationException - The --add-opens surefire profile activates only for Java 22+ sun.misc.Unsafe.theUnsafe is in the exported jdk.unsupported module so setAccessible always succeeds. staticFieldOffset/staticFieldBase/getObject operate at raw memory level, yielding the full-privileged IMPL_LOOKUP which can find and set AccessibleObject.override even when hidden. Also update minimum Java version from 1.6 to 1.8, add Java 21 to CI matrix, and update GitHub Actions to v4. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace brittle reflection-based approaches with IMPL_LOOKUP obtained
through sun.misc.Unsafe raw memory reads, which bypasses module system
checks entirely and works across all Java 9-21 versions without --add-opens:
Java 12+ due to AccessibleObject.override blacklist) with IMPL_LOOKUP
Java 21 where override is hidden from getDeclaredField) with IMPL_LOOKUP
sun.misc.Unsafe.theUnsafe is in the exported jdk.unsupported module so
setAccessible always succeeds. staticFieldOffset/staticFieldBase/getObject
operate at raw memory level, yielding the full-privileged IMPL_LOOKUP
which can find and set AccessibleObject.override even when hidden.
Also update minimum Java version from 1.6 to 1.8, add Java 21 to CI
matrix, and update GitHub Actions to v4.
Fixes: modelmapper/modelmapper#772