[compiler-rt] Reland "[sanitizer] Add CHECKs to validate calculated TLS range" (PR #108122)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 22:17:30 PDT 2024
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/108122
>From eceac8e53357b8d91f047f7a5fe954d987e05e53 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at gmail.com>
Date: Tue, 10 Sep 2024 17:46:05 -0700
Subject: [PATCH 1/4] =?UTF-8?q?Revert=20"Revert=20"[sanitizer]=20Add=20CHE?=
=?UTF-8?q?CKs=20to=20validate=20calculated=20TLS=20range"=20(#10=E2=80=A6?=
=?UTF-8?q?"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit 5804193e38680683b370cb3ced46c018d4dbd1b2.
---
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 4 ++++
1 file changed, 4 insertions(+)
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;
>From 56aff1c53215bb9cbd1ead977428bb793abf7848 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Sep 2024 17:51:36 -0700
Subject: [PATCH 2/4] Take into account kDtvOffset
---
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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 a1107ff7d24737..6e77676fabf091 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -152,8 +152,8 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
tls_size = 0;
}
if (tls_size) {
- CHECK_LE(tls_beg, reinterpret_cast<uptr>(res));
- CHECK_LT(reinterpret_cast<uptr>(res), tls_beg + tls_size);
+ CHECK_LE(tls_beg, reinterpret_cast<uptr>(res) + kDtvOffset);
+ CHECK_LT(reinterpret_cast<uptr>(res) + kDtvOffset, tls_beg + tls_size);
}
dtv->beg = tls_beg;
dtv->size = tls_size;
>From dd3f250c25b9284c32e414c8ef762386328a914d Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Sep 2024 17:59:59 -0700
Subject: [PATCH 3/4] apply kDtvOffset correctly
---
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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 6e77676fabf091..bf84a2ff60c91c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -152,8 +152,8 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
tls_size = 0;
}
if (tls_size) {
- CHECK_LE(tls_beg, reinterpret_cast<uptr>(res) + kDtvOffset);
- CHECK_LT(reinterpret_cast<uptr>(res) + kDtvOffset, tls_beg + tls_size);
+ CHECK_LE(tls_beg, reinterpret_cast<uptr>(res) - kDtvOffset);
+ CHECK_LT(reinterpret_cast<uptr>(res) - kDtvOffset, tls_beg + tls_size);
}
dtv->beg = tls_beg;
dtv->size = tls_size;
>From 3ba2861d550c286608e03b9e0ba1510e1d5aa9cf Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Sep 2024 22:17:06 -0700
Subject: [PATCH 4/4] verbose test
---
compiler-rt/test/asan/TestCases/Linux/stress_dtls.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c b/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
index fd1ce0cd472f99..be0baabde49c17 100644
--- a/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
+++ b/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
@@ -11,8 +11,8 @@
// RUN: %clangxx_asan -x c -DSO_NAME=f1 %s -shared -o %t-f1.so -fPIC
// RUN: %clangxx_asan -x c -DSO_NAME=f2 %s -shared -o %t-f2.so -fPIC
// RUN: %clangxx_asan %s -ldl -pthread -o %t
-// RUN: %run %t 0 3
-// RUN: %run %t 2 3
+// RUN: %env_asan_opts=verbosity=2 %run %t 0 3
+// RUN: %env_asan_opts=verbosity=2 %run %t 2 3
// RUN: %env_asan_opts=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_asan_opts=verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_asan_opts=verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
More information about the llvm-commits
mailing list