[compiler-rt] 2eda2e0 - [HWASAN] Prevent crashes on thread exit
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu May 11 16:15:21 PDT 2023
Author: Vitaly Buka
Date: 2023-05-11T16:15:06-07:00
New Revision: 2eda2e013830537800b68c9217fc14ea7704e618
URL: https://github.com/llvm/llvm-project/commit/2eda2e013830537800b68c9217fc14ea7704e618
DIFF: https://github.com/llvm/llvm-project/commit/2eda2e013830537800b68c9217fc14ea7704e618.diff
LOG: [HWASAN] Prevent crashes on thread exit
I can't figure out how to reproduce this for test, but I see the case on
random binaries.
The known issue is with GLIBC, others may have a workaround, e.g. Bionic,
https://cs.android.com/android/platform/superproject/+/master:bionic/libc/bionic/pthread_exit.cpp;l=149
see signals blocked above.
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D150401
Added:
Modified:
compiler-rt/lib/hwasan/hwasan_linux.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index abf92d290c84..6f5e9432974e 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -302,8 +302,15 @@ extern "C" void __hwasan_thread_exit() {
Thread *t = GetCurrentThread();
// Make sure that signal handler can not see a stale current thread pointer.
atomic_signal_fence(memory_order_seq_cst);
- if (t)
+ if (t) {
+ // Block async signals on the thread as the handler can be instrumented.
+ // After this point instrumented code can't access essential data from TLS
+ // and will crash.
+ // Bionic already calls __hwasan_thread_exit with blocked signals.
+ if (SANITIZER_GLIBC)
+ BlockSignals();
hwasanThreadList().ReleaseThread(t);
+ }
}
# if HWASAN_WITH_INTERCEPTORS
More information about the llvm-commits
mailing list