Skip to content

Commit b07f1be

Browse files
authored
[sanitizer] Remove DTLS_on_libc_memalign (#108120)
`DTLS_on_libc_memalign` is called from primary allocator, so `__sanitizer_get_allocated_begin` should also be aware of allocation, and correctly handled by `GetDTLSRange`.
1 parent 0683c4e commit b07f1be

File tree

8 files changed

+8
-43
lines changed

8 files changed

+8
-43
lines changed

compiler-rt/lib/asan/asan_malloc_linux.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
# include "sanitizer_common/sanitizer_allocator_checks.h"
2626
# include "sanitizer_common/sanitizer_allocator_dlsym.h"
2727
# include "sanitizer_common/sanitizer_errno.h"
28-
# include "sanitizer_common/sanitizer_tls_get_addr.h"
2928

3029
// ---------------------- Replacement functions ---------------- {{{1
3130
using namespace __asan;
@@ -99,9 +98,7 @@ INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
9998

10099
INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) {
101100
GET_STACK_TRACE_MALLOC;
102-
void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC);
103-
DTLS_on_libc_memalign(res, size);
104-
return res;
101+
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
105102
}
106103
#endif // SANITIZER_INTERCEPT_MEMALIGN
107104

compiler-rt/lib/dfsan/dfsan_interceptors.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ INTERCEPTOR(void *, reallocarray, void *ptr, SIZE_T nmemb, SIZE_T size) {
3939
}
4040

4141
INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
42-
void *ptr = dfsan_memalign(alignment, size);
43-
if (ptr)
44-
DTLS_on_libc_memalign(ptr, size);
45-
return ptr;
42+
return dfsan_memalign(alignment, size);
4643
}
4744

4845
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {

compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "sanitizer_common/sanitizer_allocator_dlsym.h"
1818
#include "sanitizer_common/sanitizer_allocator_interface.h"
1919
#include "sanitizer_common/sanitizer_mallinfo.h"
20-
#include "sanitizer_common/sanitizer_tls_get_addr.h"
2120

2221
using namespace __hwasan;
2322

@@ -62,10 +61,7 @@ void *__sanitizer_aligned_alloc(uptr alignment, uptr size) {
6261
SANITIZER_INTERFACE_ATTRIBUTE
6362
void *__sanitizer___libc_memalign(uptr alignment, uptr size) {
6463
GET_MALLOC_STACK_TRACE;
65-
void *ptr = hwasan_memalign(alignment, size, &stack);
66-
if (ptr)
67-
DTLS_on_libc_memalign(ptr, size);
68-
return ptr;
64+
return hwasan_memalign(alignment, size, &stack);
6965
}
7066

7167
SANITIZER_INTERFACE_ATTRIBUTE

compiler-rt/lib/lsan/lsan_interceptors.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#if SANITIZER_POSIX
2727
#include "sanitizer_common/sanitizer_posix.h"
2828
#endif
29-
#include "sanitizer_common/sanitizer_tls_get_addr.h"
3029
#include "lsan.h"
3130
#include "lsan_allocator.h"
3231
#include "lsan_common.h"
@@ -135,9 +134,7 @@ INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
135134
INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
136135
ENSURE_LSAN_INITED;
137136
GET_STACK_TRACE_MALLOC;
138-
void *res = lsan_memalign(alignment, size, stack);
139-
DTLS_on_libc_memalign(res, size);
140-
return res;
137+
return lsan_memalign(alignment, size, stack);
141138
}
142139
#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
143140
#else

compiler-rt/lib/memprof/memprof_malloc_linux.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ INTERCEPTOR(void *, memalign, uptr boundary, uptr size) {
9090

9191
INTERCEPTOR(void *, __libc_memalign, uptr boundary, uptr size) {
9292
GET_STACK_TRACE_MALLOC;
93-
void *res = memprof_memalign(boundary, size, &stack, FROM_MALLOC);
94-
DTLS_on_libc_memalign(res, size);
95-
return res;
93+
return memprof_memalign(boundary, size, &stack, FROM_MALLOC);
9694
}
9795
#endif // SANITIZER_INTERCEPT_MEMALIGN
9896

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
3838
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
3939
#include "sanitizer_common/sanitizer_stackdepot.h"
40-
#include "sanitizer_common/sanitizer_tls_get_addr.h"
4140
#include "sanitizer_common/sanitizer_vector.h"
4241

4342
#if SANITIZER_NETBSD
@@ -185,10 +184,7 @@ INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
185184
#if !SANITIZER_NETBSD
186185
INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
187186
GET_MALLOC_STACK_TRACE;
188-
void *ptr = msan_memalign(alignment, size, &stack);
189-
if (ptr)
190-
DTLS_on_libc_memalign(ptr, size);
191-
return ptr;
187+
return msan_memalign(alignment, size, &stack);
192188
}
193189
#define MSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
194190
#else

compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static bool GetDTLSRange(uptr &tls_beg, uptr &tls_size) {
116116
return false;
117117
tls_beg = (uptr)start;
118118
tls_size = __sanitizer_get_allocated_size(start);
119-
VReport(2, "__tls_get_addr: glibc >=2.25 suspected; tls={%p,0x%zx}\n",
119+
VReport(2, "__tls_get_addr: glibc DTLS suspected; tls={%p,0x%zx}\n",
120120
(void *)tls_beg, tls_size);
121121
return true;
122122
}
@@ -137,11 +137,7 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
137137
(void *)arg, arg->dso_id, arg->offset, res, (void *)tls_beg,
138138
(void *)&tls_beg,
139139
atomic_load(&number_of_live_dtls, memory_order_relaxed));
140-
if (dtls.last_memalign_ptr == tls_beg) {
141-
tls_size = dtls.last_memalign_size;
142-
VReport(2, "__tls_get_addr: glibc <=2.24 suspected; tls={%p,0x%zx}\n",
143-
(void *)tls_beg, tls_size);
144-
} else if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
140+
if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
145141
// This is the static TLS block which was initialized / unpoisoned at thread
146142
// creation.
147143
VReport(2, "__tls_get_addr: static tls: %p\n", (void *)tls_beg);
@@ -156,13 +152,6 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
156152
return dtv;
157153
}
158154

159-
void DTLS_on_libc_memalign(void *ptr, uptr size) {
160-
if (!common_flags()->intercept_tls_get_addr) return;
161-
VReport(2, "DTLS_on_libc_memalign: %p 0x%zx\n", ptr, size);
162-
dtls.last_memalign_ptr = reinterpret_cast<uptr>(ptr);
163-
dtls.last_memalign_size = size;
164-
}
165-
166155
DTLS *DTLS_Get() { return &dtls; }
167156

168157
bool DTLSInDestruction(DTLS *dtls) {
@@ -171,7 +160,6 @@ bool DTLSInDestruction(DTLS *dtls) {
171160
}
172161

173162
#else
174-
void DTLS_on_libc_memalign(void *ptr, uptr size) {}
175163
DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res,
176164
unsigned long, unsigned long) { return 0; }
177165
DTLS *DTLS_Get() { return 0; }

compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ struct DTLS {
5555
static_assert(sizeof(DTVBlock) <= 4096UL, "Unexpected block size");
5656

5757
atomic_uintptr_t dtv_block;
58-
59-
// Auxiliary fields, don't access them outside sanitizer_tls_get_addr.cpp
60-
uptr last_memalign_size;
61-
uptr last_memalign_ptr;
6258
};
6359

6460
template <typename Fn>

0 commit comments

Comments
 (0)