Skip to content

[tsan] Change personality CHECK to Printf() + Die() #142821

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

Merged
merged 4 commits into from
Jun 4, 2025

Conversation

thurstond
Copy link
Contributor

Currently, if TSan needs to disable ASLR but is unable to do so, it aborts with a cryptic message:

    ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"

and a segfault (google/sanitizers#837 (comment)).

This patch replaces the CHECK with more user-friendly diagnostics and suggestions via printf, followed by Die().

thurstond added 3 commits June 4, 2025 17:37
Currently, if TSan needs to disable ASLR but is unable to do so, it
aborts with a cryptic message:
    ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"
and a segfault (google/sanitizers#837 (comment)).

This patch replaces the CHECK with more user-friendly diagnostics and
suggestions via printf, followed by Die().
@llvmbot
Copy link
Member

llvmbot commented Jun 4, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Thurston Dang (thurstond)

Changes

Currently, if TSan needs to disable ASLR but is unable to do so, it aborts with a cryptic message:

    ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"

and a segfault (google/sanitizers#837 (comment)).

This patch replaces the CHECK with more user-friendly diagnostics and suggestions via printf, followed by Die().


Full diff: https://github.com/llvm/llvm-project/pull/142821.diff

1 Files Affected:

  • (modified) compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp (+21-2)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index 373acd3d95d01..469525ac41cf8 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -259,7 +259,15 @@ static void ReExecIfNeeded(bool ignore_heap) {
             "WARNING: Program is run with randomized virtual address "
             "space, which wouldn't work with ThreadSanitizer on Android.\n"
             "Re-execing with fixed virtual address space.\n");
-    CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
+
+    if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
+      Printf(
+          "FATAL: ThreadSanitizer: unable to disable ASLR (perhaps "
+          "sandboxing is enabled?).\n");
+      Printf("FATAL: Please rerun without sandboxing and/or ASLR.\n");
+      Die();
+    }
+
     reexec = true;
   }
 #      endif
@@ -287,7 +295,18 @@ static void ReExecIfNeeded(bool ignore_heap) {
               "possibly due to high-entropy ASLR.\n"
               "Re-execing with fixed virtual address space.\n"
               "N.B. reducing ASLR entropy is preferable.\n");
-      CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
+
+      if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
+        Printf(
+            "FATAL: ThreadSanitizer: encountered an incompatible memory "
+            "but was unable to disable ASLR (perhaps sandboxing is "
+            "enabled?).\n");
+        Printf(
+            "FATAL: Please rerun with lower ASLR entropy, ASLR disabled, "
+            "and/or sandboxing disabled.\n");
+        Die();
+      }
+
       reexec = true;
     } else {
       Printf(

@thurstond thurstond merged commit 96c1fd4 into llvm:main Jun 4, 2025
10 checks passed
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
Currently, if TSan needs to disable ASLR but is unable to do so, it
aborts with a cryptic message:
```
    ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"
```
and a segfault
(google/sanitizers#837 (comment)).

This patch replaces the CHECK with more user-friendly diagnostics and
suggestions via printf, followed by Die().
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
Currently, if TSan needs to disable ASLR but is unable to do so, it
aborts with a cryptic message:
```
    ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"
```
and a segfault
(google/sanitizers#837 (comment)).

This patch replaces the CHECK with more user-friendly diagnostics and
suggestions via printf, followed by Die().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants