diff options
author | Vitaly Buka <vitalybuka@google.com> | 2023-05-11 10:30:20 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2023-05-11 16:15:06 -0700 |
commit | 2eda2e013830537800b68c9217fc14ea7704e618 (patch) | |
tree | c6657392bd1a677f6c0262cc7e8eb7a36f91e5a2 /compiler-rt | |
parent | 20a3c6e84e0955ac20762c35e8c2435017ae967d (diff) | |
download | llvm-2eda2e013830537800b68c9217fc14ea7704e618.tar.gz |
[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
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/hwasan/hwasan_linux.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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 |