[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 17:46:26 PDT 2024


https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/108122

Reverts llvm/llvm-project#108112

>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] =?UTF-8?q?Revert=20"Revert=20"[sanitizer]=20Add=20CHECKs?=
 =?UTF-8?q?=20to=20validate=20calculated=20TLS=20range"=20(#10=E2=80=A6"?=
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;



More information about the llvm-commits mailing list