Repository navigation
ndk: address thread-locals by value under a thread-pointer swap - #412
Merged
Merged
Conversation
a4l built at -O2 with GCC crashed in any WebView app: SIGSEGV in libwebviewchromium's JNI_OnLoad, on the first use of the JNIEnv that GetEnv returned. w_GetEnv took &t_wrap_env inside the ToGlibc scope. The compiler takes the thread pointer for constant across a function, so at -O2 GCC computed the address after ~ToGlibc had put bionic's thread pointer back, and the env it returned lay under bionic's TCB. w_AttachCurrentThread had the same pattern, and w_DetachCurrentThread wrote t_bionic_fs and t_wrap_env.real between two swaps. The default debug build does not show it. wrap_env_at() and bionic_fs_at() reach the two thread-locals from the glibc thread pointer as a value, through the displacements already recorded for the trampolines. ToGlibc keeps that pointer, and the three wrappers use it. Tested: - x86, GCC 16, -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-strong, plain build type, one WebView app: main crashes in JNI_OnLoad; with this it loads (3 x "JNI_OnLoad ok") and draws 647 frames in 25 s. - arm64 (clang release build) on an i.MX 8M Plus: the same app loads and draws. - x86 suite on the -O2 build: 129 pass, 5 skip (they look for the build under build/), idle-gate failed once in the full run and passes twice alone. - clang-format clean. Signed-off-by: Joel Winarske <joel.winarske@linux.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.
Summary
a4l built at
-O2with GCC crashed in any WebView app: SIGSEGV inlibwebviewchromium'sJNI_OnLoad, on the first use of theJNIEnvthatGetEnvreturned.w_GetEnvtook&t_wrap_envinside theToGlibcscope. The compiler takes the thread pointer for constant across a function, so at-O2GCC computed the address after bionic's thread pointer was back, and the env lay under bionic's TCB.w_AttachCurrentThreadhad the same pattern;w_DetachCurrentThreadwrote two thread-locals between two swaps.wrap_env_at()andbionic_fs_at()now reach those thread-locals from the glibc thread pointer as a value, through the displacements already recorded for the trampolines.The default debug build does not show the fault, and CI builds only that type, so nothing in CI would catch a regression here.
Test status
-O2, plain build type, one WebView app, mainJNI_OnLoad, no framesJNI_OnLoad ok, 647 frames in 25 s-O2buildThe five skips look for the build under
build/. The failure isidle-gate, once in the full run; it passes twice alone.