[compiler-rt] e00e0b6 - [asan] Block signals when starting threads

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 13:03:45 PDT 2023


Author: Vitaly Buka
Date: 2023-07-26T13:03:40-07:00
New Revision: e00e0b6fb004080214645b14cfe68c3c4eccd437

URL: https://github.com/llvm/llvm-project/commit/e00e0b6fb004080214645b14cfe68c3c4eccd437
DIFF: https://github.com/llvm/llvm-project/commit/e00e0b6fb004080214645b14cfe68c3c4eccd437.diff

LOG: [asan] Block signals when starting threads

Async signals may crash the process if AsanThread is not fully
initialized. We do the same for other sanitizers already.

Can't have good reproducer for test. We see this in internal test with prob 1e-6.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D156299

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_interceptors.cpp
    compiler-rt/lib/asan/asan_posix.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 26e9b7090cf62f..7c0225103e41de 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -223,6 +223,11 @@ static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
   auto self = GetThreadSelf();
   auto args = asanThreadArgRetval().GetArgs(self);
   t->ThreadStart(GetTid());
+
+  __sanitizer_sigset_t sigset;
+  t->GetStartData(sigset);
+  SetSigProcMask(&sigset, nullptr);
+
   thread_return_t retval = (*args.routine)(args.arg_retval);
   asanThreadArgRetval().Finish(self, retval);
   return retval;
@@ -242,7 +247,11 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
   }();
 
   u32 current_tid = GetCurrentTidOrInvalid();
-  AsanThread *t = AsanThread::Create(current_tid, &stack, detached);
+
+  __sanitizer_sigset_t sigset;
+  ScopedBlockSignals block(&sigset);
+
+  AsanThread *t = AsanThread::Create(sigset, current_tid, &stack, detached);
 
   int result;
   {

diff  --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp
index 765f4a26cd7ab8..50b1a8448bd480 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -138,6 +138,11 @@ void PlatformTSDDtor(void *tsd) {
     CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
     return;
   }
+#    if SANITIZER_LINUX
+  // After this point it's unsafe to execute signal handlers which may be
+  // instrumented. It's probably not just a Linux issue.
+  BlockSignals();
+#    endif
   AsanThread::TSDDtor(tsd);
 }
 #endif


        


More information about the llvm-commits mailing list