Skip to content

Reland "[sanitizer] Add CHECKs to validate calculated TLS range" #108122

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

Conversation

vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Sep 11, 2024

Reland #107941 taking into account that res
can have non-zero kDtvOffset on some platforms.

Reverts #108112

@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2024

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

Author: Vitaly Buka (vitalybuka)

Changes

Reverts llvm/llvm-project#108112


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp (+4)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
index 666e6f3b351067..a1107ff7d24737 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -151,6 +151,10 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
     // This may happen inside the DTOR of main thread, so just ignore it.
     tls_size = 0;
   }
+  if (tls_size) {
+    CHECK_LE(tls_beg, reinterpret_cast<uptr>(res));
+    CHECK_LT(reinterpret_cast<uptr>(res), tls_beg + tls_size);
+  }
   dtv->beg = tls_beg;
   dtv->size = tls_size;
   return dtv;

@llvmbot llvmbot added the compiler-rt:asan Address sanitizer label Sep 11, 2024
@vitalybuka vitalybuka force-pushed the revert-108112-revert-107941-users/vitalybuka/spr/sanitizer-add-checks-to-validate-calculated-tls-range branch from d924f90 to d92d55f Compare September 11, 2024 14:57
@vitalybuka vitalybuka marked this pull request as draft September 11, 2024 14:58
@vitalybuka vitalybuka force-pushed the revert-108112-revert-107941-users/vitalybuka/spr/sanitizer-add-checks-to-validate-calculated-tls-range branch from d92d55f to 730ca7d Compare September 11, 2024 15:32
Copy link

github-actions bot commented Sep 11, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 695cb55ccb34a3cf659c12e1cbca1b916372a199 98f470287a4671173197fd1cd3c8141d2282144a --extensions c,cpp -- compiler-rt/lib/msan/msan_allocator.cpp compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp compiler-rt/test/asan/TestCases/Linux/stress_dtls.c compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
View the diff from clang-format here.
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
index 884d0f2a5e..73d524ae51 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
@@ -1,9 +1,9 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %env_tool_opts=verbosity=2 %t
 
-#include <stdlib.h>
+#include <grp.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
-#include <grp.h>
 
 int main(void) {
   gid_t *groups;

@vitalybuka vitalybuka force-pushed the revert-108112-revert-107941-users/vitalybuka/spr/sanitizer-add-checks-to-validate-calculated-tls-range branch from 13141eb to 8cd22f3 Compare September 11, 2024 21:52
@vitalybuka vitalybuka closed this Sep 13, 2024
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.

2 participants