Fix Java bridge crash on Android 17 (API 37) arm64#398
Merged
Conversation
Two bugs make Java.perform() SIGBUS on API 37. _getArtMethodSpec() left kAccNterpEntryPointFastPathFlag unmasked, which the API 37 probe method carries, so the access_flags scan latched onto the next ArtMethod and corrupted the flag offset. makeArtThreadStateTransitionImpl()'s invokeCallback loads callback through a PC-relative literal flushed too late: the relocated ExceptionClear body pushes the pool out of ±1 MiB reach. Emit invokeCallback first, flush after its ret, enter via the relocated body.
f923041 to
67f1b11
Compare
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.
On a Pixel 10 Pro XL running Android 17 (SDK 37, arm64),
Java.perform()SIGBUSes the target process. Two independent bugs are involved. Both
reproduce on a stock frida-server; neither is device-specific beyond the
new ART build, and both are fixed here.
1. ArtMethod access-flags offset detection
_getArtMethodSpec()locatesArtMethod.access_flags_by masking theruntime-only nterp flags off a probe method (
Process.getElapsedCpuTime)and matching against
kAccPublic|kAccStatic|kAccFinal|kAccNative. The maskstripped
kAccNterpInvokeFastPathFlagbut notkAccNterpEntryPointFastPathFlag. On API 37 the probe method carries thelatter, so its real flags at offset 4 (
0x50300119) no longer matched, andthe scan latched onto the next ArtMethod's flags one 32-byte stride over
(offset 36), corrupting the flag offset for every method.
Fix: also mask
kAccNterpEntryPointFastPathFlag.2. Unresolved literal pool in the thread-state-transition thunk
makeArtThreadStateTransitionImpl()recompilesart::JNI::ExceptionClearand emits an
invokeCallbacksubroutine whoseputCallAddressWithArguments()loadscallbackvia a PC-relative literal(±1 MiB reach). The literal pool was only emitted at
writer.dispose(),after the relocated
ExceptionClearbody. On Android 17ExceptionClearand the following function sit ~2 MiB apart, so the relocated body pushes
the pool out of the load's range, and it is left as
ldr xN, #0, whichreads its own instruction bytes (
0x...58000001) and branches to them,giving a PC-alignment SIGBUS at the first
withRunnableArtThread().Fix: emit the
invokeCallbacksubroutine first and flush the literal poolimmediately after it (it sits after a
ret, so it is never executed),then use the relocated transition body as the entrypoint.
Verification
Pixel 10 Pro XL, Android 17 (SDK 37):
Java.use, static field reads,method invocation, and method replacement (
.implementation) all work.