[compiler-rt] Reland "[sanitizer] Add CHECKs to validate calculated TLS range" (PR #108122)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 00:46:19 PDT 2024
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/108122
>From d71338da225d3ec3a5bb88f0c9cd905ad457c4d6 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/9] =?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 c971a0b9fd3fcf7ff6e87d17c36c58bf090da863 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/9] 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 3db659050311888f99e849e40ee49cf1b68c5b6c 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/9] 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 60b3aa1f1254e13d6249c78eb7da2b083eb2d1ab 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/9] 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
>From e12b03a0682ee28e3a642a0331826a96fd5b20e3 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Sep 2024 23:30:00 -0700
Subject: [PATCH 5/9] try
---
.../lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 8 ++++----
compiler-rt/test/asan/TestCases/Linux/stress_dtls.c | 2 +-
2 files changed, 5 insertions(+), 5 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 bf84a2ff60c91c..1113d515dcb06d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -151,10 +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) - kDtvOffset);
- CHECK_LT(reinterpret_cast<uptr>(res) - kDtvOffset, tls_beg + tls_size);
- }
+ // if (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;
return dtv;
diff --git a/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c b/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
index be0baabde49c17..6514456db56f6c 100644
--- a/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
+++ b/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
@@ -11,7 +11,7 @@
// 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: %env_asan_opts=verbosity=2 %run %t 0 3
+// RUN: %env_asan_opts=verbosity=2 %run not %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
>From e7e3b7b36606c6d583197fb05dbc87745d95f3d7 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 11 Sep 2024 08:33:07 -0700
Subject: [PATCH 6/9] touch
---
compiler-rt/test/asan/TestCases/Linux/stress_dtls.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c b/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
index 6514456db56f6c..857bec984c0cb2 100644
--- a/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
+++ b/compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
@@ -29,6 +29,7 @@
// CHECK-NOT: num_live_dtls 5
//
// CHECK0-NOT: __tls_get_addr
+
/*
cc=your-compiler
>From 8cd22f351c2284cf06a6c53f26c95bce04f3bac8 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 11 Sep 2024 10:54:04 -0700
Subject: [PATCH 7/9] again
---
.../lib/sanitizer_common/sanitizer_tls_get_addr.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 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 1113d515dcb06d..bf84a2ff60c91c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -151,10 +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) - kDtvOffset);
- // CHECK_LT(reinterpret_cast<uptr>(res) - kDtvOffset, tls_beg + tls_size);
- // }
+ if (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;
return dtv;
>From 22b522a32d76c6c471707ceb6b9b4dcb9407db27 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 11 Sep 2024 17:29:21 -0700
Subject: [PATCH 8/9] Update sanitizer_tls_get_addr.cpp
---
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 bf84a2ff60c91c..a1107ff7d24737 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));
+ CHECK_LT(reinterpret_cast<uptr>(res), tls_beg + tls_size);
}
dtv->beg = tls_beg;
dtv->size = tls_size;
>From 4e3871cbac740407692152993578cce870951199 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 12 Sep 2024 00:45:50 -0700
Subject: [PATCH 9/9] logs
---
.../test/sanitizer_common/TestCases/Linux/getgrouplist.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
index 7e1b8f1963f27c..dfe5fd05fa6627 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx -O0 -g %s -o %t && %run %t
+// RUN: %clangxx -O0 -g %s -o %t && %run %env_tool_opts=verbosity=2 %t
#include <stdlib.h>
#include <unistd.h>
More information about the llvm-commits
mailing list