-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[msan] Block signals during MsanThread::TSDDtor #98405
Conversation
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: ed8565c changed *BlockSignals to only block asynchronous signals, despite the name.
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Thurston Dang (thurstond) ChangesFull diff: https://github.com/llvm/llvm-project/pull/98405.diff 1 Files Affected:
diff --git a/compiler-rt/lib/msan/msan_thread.cpp b/compiler-rt/lib/msan/msan_thread.cpp
index ff9b90bb81f0c..cc4dfe601ead6 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,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
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MsanThread is LINUX only any way
I suggest to move blocker just before msan_current_thread = nullptr in MsanTSDDtor |
per Vitaly's feedback
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::TSDDtor. This is based on an idea suggested by Paul Pluzhnikov (block async signals in MsanThread::Destroy()) and refined by Vitaly Buka. Note: ed8565c changed *BlockSignals to only block asynchronous signals, despite the name.
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::TSDDtor. This is based on an idea suggested by Paul Pluzhnikov (block async signals in MsanThread::Destroy()) and refined by Vitaly Buka.
Note: ed8565c changed *BlockSignals to only block asynchronous signals, despite the name.