[compiler-rt] Msan signals (PR #98405)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 16:00:01 PDT 2024


https://github.com/thurstond created https://github.com/llvm/llvm-project/pull/98405

None

>From 65df606f23710a6dcb8187c48bbaaa87baff9e9c Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Wed, 10 Jul 2024 22:53:23 +0000
Subject: [PATCH 1/2] [msan] Block signals during MsanThread::Destroy

MSan may segfault inside a signal handler, if MSan instrumentation is trying to access thread-local storage that has already
been destroyed. This fixes the issue by blocking asychronous signals
inside MsanThread::Destroy, as suggested by Paul Pluzhnikov.

Note: ed8565cf0b64ea5e88cc94f321b1870bb105d09d changed *BlockSignals to
only block asynchronous signals, despite the name.
---
 compiler-rt/lib/msan/msan_thread.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler-rt/lib/msan/msan_thread.cpp b/compiler-rt/lib/msan/msan_thread.cpp
index ff9b90bb81f0c..75cdc42917bb4 100644
--- a/compiler-rt/lib/msan/msan_thread.cpp
+++ b/compiler-rt/lib/msan/msan_thread.cpp
@@ -3,6 +3,7 @@
 #include "msan_thread.h"
 #include "msan_interface_internal.h"
 
+#include "sanitizer_common/sanitizer_linux.h"
 #include "sanitizer_common/sanitizer_tls_get_addr.h"
 
 namespace __msan {
@@ -56,6 +57,7 @@ void MsanThread::TSDDtor(void *tsd) {
 }
 
 void MsanThread::Destroy() {
+  ScopedBlockSignals block(nullptr);
   malloc_storage().CommitBack();
   // We also clear the shadow on thread destruction because
   // some code may still be executing in later TSD destructors

>From b68c6d52a470391c8ad6f4f22f88dc1c5aecd1ec Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Wed, 10 Jul 2024 22:59:28 +0000
Subject: [PATCH 2/2] Scope change to Linux only

---
 compiler-rt/lib/msan/msan_thread.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler-rt/lib/msan/msan_thread.cpp b/compiler-rt/lib/msan/msan_thread.cpp
index 75cdc42917bb4..cc4dfe601ead6 100644
--- a/compiler-rt/lib/msan/msan_thread.cpp
+++ b/compiler-rt/lib/msan/msan_thread.cpp
@@ -57,7 +57,9 @@ void MsanThread::TSDDtor(void *tsd) {
 }
 
 void MsanThread::Destroy() {
+#if SANITIZER_LINUX
   ScopedBlockSignals block(nullptr);
+#endif
   malloc_storage().CommitBack();
   // We also clear the shadow on thread destruction because
   // some code may still be executing in later TSD destructors



More information about the llvm-commits mailing list