Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f13b7d0

Browse filesBrowse files
authored
Reland "[sanitizer] Fix partially initialized static TLS range" (#108883)
Reland #108685 Arguments order was wrong on Windows and Darwin.
1 parent 3acb1ea commit f13b7d0
Copy full SHA for f13b7d0

File tree

Expand file treeCollapse file tree

16 files changed

+86
-120
lines changed
Filter options
Expand file treeCollapse file tree

16 files changed

+86
-120
lines changed

‎compiler-rt/lib/asan/asan_posix.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/asan/asan_posix.cpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ bool PlatformUnpoisonStacks() {
5959

6060
// Since we're on the signal alternate stack, we cannot find the DEFAULT
6161
// stack bottom using a local variable.
62-
uptr default_bottom, tls_addr, tls_size, stack_size;
63-
GetThreadStackAndTls(/*main=*/false, &default_bottom, &stack_size, &tls_addr,
64-
&tls_size);
65-
UnpoisonStack(default_bottom, default_bottom + stack_size, "default");
62+
uptr stack_begin, stack_end, tls_begin, tls_end;
63+
GetThreadStackAndTls(/*main=*/false, &stack_begin, &stack_end, &tls_begin,
64+
&tls_end);
65+
UnpoisonStack(stack_begin, stack_end, "default");
6666
return true;
6767
}
6868

‎compiler-rt/lib/asan/asan_rtl.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/asan/asan_rtl.cpp
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,8 @@ static void UnpoisonDefaultStack() {
580580
} else {
581581
CHECK(!SANITIZER_FUCHSIA);
582582
// If we haven't seen this thread, try asking the OS for stack bounds.
583-
uptr tls_addr, tls_size, stack_size;
584-
GetThreadStackAndTls(/*main=*/false, &bottom, &stack_size, &tls_addr,
585-
&tls_size);
586-
top = bottom + stack_size;
583+
uptr tls_begin, tls_end;
584+
GetThreadStackAndTls(/*main=*/false, &bottom, &top, &tls_begin, &tls_end);
587585
}
588586

589587
UnpoisonStack(bottom, top, "default");

‎compiler-rt/lib/asan/asan_thread.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/asan/asan_thread.cpp
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,10 @@ AsanThread *CreateMainThread() {
306306
// OS-specific implementations that need more information passed through.
307307
void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
308308
DCHECK_EQ(options, nullptr);
309-
uptr tls_size = 0;
310-
uptr stack_size = 0;
311-
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
312-
&tls_begin_, &tls_size);
313-
stack_top_ = RoundDownTo(stack_bottom_ + stack_size, ASAN_SHADOW_GRANULARITY);
309+
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_top_,
310+
&tls_begin_, &tls_end_);
311+
stack_top_ = RoundDownTo(stack_top_, ASAN_SHADOW_GRANULARITY);
314312
stack_bottom_ = RoundDownTo(stack_bottom_, ASAN_SHADOW_GRANULARITY);
315-
tls_end_ = tls_begin_ + tls_size;
316313
dtls_ = DTLS_Get();
317314

318315
if (stack_top_ != stack_bottom_) {

‎compiler-rt/lib/dfsan/dfsan_thread.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/dfsan/dfsan_thread.cpp
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@ DFsanThread *DFsanThread::Create(thread_callback_t start_routine, void *arg,
2121
}
2222

2323
void DFsanThread::SetThreadStackAndTls() {
24-
uptr tls_size = 0;
25-
uptr stack_size = 0;
26-
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, &tls_begin_,
27-
&tls_size);
28-
stack_.top = stack_.bottom + stack_size;
29-
tls_end_ = tls_begin_ + tls_size;
30-
24+
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, &tls_begin_,
25+
&tls_end_);
3126
int local;
3227
CHECK(AddrIsInStack((uptr)&local));
3328
}

‎compiler-rt/lib/hwasan/hwasan_linux.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/hwasan/hwasan_linux.cpp
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,8 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context) {
499499
}
500500

501501
void Thread::InitStackAndTls(const InitState *) {
502-
uptr tls_size;
503-
uptr stack_size;
504-
GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
505-
&tls_size);
506-
stack_top_ = stack_bottom_ + stack_size;
507-
tls_end_ = tls_begin_ + tls_size;
502+
GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_top_, &tls_begin_,
503+
&tls_end_);
508504
}
509505

510506
uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {

‎compiler-rt/lib/lsan/lsan_posix.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/lsan/lsan_posix.cpp
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ void ThreadContext::OnStarted(void *arg) {
5050

5151
void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type) {
5252
OnStartedArgs args;
53-
uptr stack_size = 0;
54-
uptr tls_size = 0;
55-
GetThreadStackAndTls(tid == kMainTid, &args.stack_begin, &stack_size,
56-
&args.tls_begin, &tls_size);
57-
args.stack_end = args.stack_begin + stack_size;
58-
args.tls_end = args.tls_begin + tls_size;
53+
GetThreadStackAndTls(tid == kMainTid, &args.stack_begin, &args.stack_end,
54+
&args.tls_begin, &args.tls_end);
5955
GetAllocatorCacheRange(&args.cache_begin, &args.cache_end);
6056
args.dtls = DTLS_Get();
6157
ThreadContextLsanBase::ThreadStart(tid, os_id, thread_type, &args);

‎compiler-rt/lib/memprof/memprof_thread.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/memprof/memprof_thread.cpp
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,8 @@ MemprofThread *CreateMainThread() {
168168
// OS-specific implementations that need more information passed through.
169169
void MemprofThread::SetThreadStackAndTls(const InitOptions *options) {
170170
DCHECK_EQ(options, nullptr);
171-
uptr tls_size = 0;
172-
uptr stack_size = 0;
173-
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
174-
&tls_begin_, &tls_size);
175-
stack_top_ = stack_bottom_ + stack_size;
176-
tls_end_ = tls_begin_ + tls_size;
171+
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_top_,
172+
&tls_begin_, &tls_end_);
177173
dtls_ = DTLS_Get();
178174

179175
if (stack_top_ != stack_bottom_) {

‎compiler-rt/lib/msan/msan_thread.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/msan/msan_thread.cpp
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ MsanThread *MsanThread::Create(thread_callback_t start_routine,
2020
}
2121

2222
void MsanThread::SetThreadStackAndTls() {
23-
uptr tls_size = 0;
24-
uptr stack_size = 0;
25-
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, &tls_begin_,
26-
&tls_size);
27-
stack_.top = stack_.bottom + stack_size;
28-
tls_end_ = tls_begin_ + tls_size;
29-
23+
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, &tls_begin_,
24+
&tls_end_);
3025
int local;
3126
CHECK(AddrIsInStack((uptr)&local));
3227
}

‎compiler-rt/lib/nsan/nsan_thread.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/nsan/nsan_thread.cpp
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ NsanThread *NsanThread::Create(thread_callback_t start_routine, void *arg) {
2929
}
3030

3131
void NsanThread::SetThreadStackAndTls() {
32-
uptr tls_size = 0;
33-
uptr stack_size = 0;
34-
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, &tls_begin_,
35-
&tls_size);
36-
stack_.top = stack_.bottom + stack_size;
37-
tls_end_ = tls_begin_ + tls_size;
38-
32+
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, &tls_begin_,
33+
&tls_end_);
3934
int local;
4035
CHECK(AddrIsInStack((uptr)&local));
4136
}

‎compiler-rt/lib/sanitizer_common/sanitizer_common.h

Copy file name to clipboardExpand all lines: compiler-rt/lib/sanitizer_common/sanitizer_common.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ int TgKill(pid_t pid, tid_t tid, int sig);
8383
uptr GetThreadSelf();
8484
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
8585
uptr *stack_bottom);
86-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
87-
uptr *tls_addr, uptr *tls_size);
86+
void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
87+
uptr *tls_begin, uptr *tls_end);
8888

8989
// Memory management
9090
void *MmapOrDie(uptr size, const char *mem_type, bool raw_report = false);

‎compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+17-10Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -626,25 +626,32 @@ uptr GetTlsSize() {
626626
}
627627
# endif
628628

629-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
630-
uptr *tls_addr, uptr *tls_size) {
629+
void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
630+
uptr *tls_begin, uptr *tls_end) {
631631
# if SANITIZER_GO
632632
// Stub implementation for Go.
633-
*stk_addr = *stk_size = *tls_addr = *tls_size = 0;
633+
*stk_begin = 0;
634+
*stk_end = 0;
635+
*tls_begin = 0;
636+
*tls_end = 0;
634637
# else
635-
GetTls(tls_addr, tls_size);
638+
uptr tls_addr = 0;
639+
uptr tls_size = 0;
640+
GetTls(&tls_addr, &tls_size);
641+
*tls_begin = tls_addr;
642+
*tls_end = tls_addr + tls_size;
636643

637644
uptr stack_top, stack_bottom;
638645
GetThreadStackTopAndBottom(main, &stack_top, &stack_bottom);
639-
*stk_addr = stack_bottom;
640-
*stk_size = stack_top - stack_bottom;
646+
*stk_begin = stack_bottom;
647+
*stk_end = stack_top;
641648

642649
if (!main) {
643650
// If stack and tls intersect, make them non-intersecting.
644-
if (*tls_addr > *stk_addr && *tls_addr < *stk_addr + *stk_size) {
645-
if (*stk_addr + *stk_size < *tls_addr + *tls_size)
646-
*tls_size = *stk_addr + *stk_size - *tls_addr;
647-
*stk_size = *tls_addr - *stk_addr;
651+
if (*tls_begin > *stk_begin && *tls_begin < *stk_end) {
652+
if (*stk_end < *tls_end)
653+
*tls_end = *stk_end;
654+
*stk_end = *tls_begin;
648655
}
649656
}
650657
# endif

‎compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -572,21 +572,18 @@ uptr TlsSize() {
572572
#endif
573573
}
574574

575-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
576-
uptr *tls_addr, uptr *tls_size) {
577-
#if !SANITIZER_GO
578-
uptr stack_top, stack_bottom;
579-
GetThreadStackTopAndBottom(main, &stack_top, &stack_bottom);
580-
*stk_addr = stack_bottom;
581-
*stk_size = stack_top - stack_bottom;
582-
*tls_addr = TlsBaseAddr();
583-
*tls_size = TlsSize();
584-
#else
585-
*stk_addr = 0;
586-
*stk_size = 0;
587-
*tls_addr = 0;
588-
*tls_size = 0;
589-
#endif
575+
void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
576+
uptr *tls_begin, uptr *tls_end) {
577+
# if !SANITIZER_GO
578+
GetThreadStackTopAndBottom(main, stk_end, stk_begin);
579+
*tls_begin = TlsBaseAddr();
580+
*tls_end = *tls_begin + TlsSize();
581+
# else
582+
*stk_begin = 0;
583+
*stk_end = 0;
584+
*tls_begin = 0;
585+
*tls_end = 0;
586+
# endif
590587
}
591588

592589
void ListOfModules::init() {

‎compiler-rt/lib/sanitizer_common/sanitizer_win.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -876,21 +876,18 @@ uptr GetTlsSize() {
876876
void InitTlsSize() {
877877
}
878878

879-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
880-
uptr *tls_addr, uptr *tls_size) {
881-
#if SANITIZER_GO
882-
*stk_addr = 0;
883-
*stk_size = 0;
884-
*tls_addr = 0;
885-
*tls_size = 0;
886-
#else
887-
uptr stack_top, stack_bottom;
888-
GetThreadStackTopAndBottom(main, &stack_top, &stack_bottom);
889-
*stk_addr = stack_bottom;
890-
*stk_size = stack_top - stack_bottom;
891-
*tls_addr = 0;
892-
*tls_size = 0;
893-
#endif
879+
void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
880+
uptr *tls_begin, uptr *tls_end) {
881+
# if SANITIZER_GO
882+
*stk_begin = 0;
883+
*stk_end = 0;
884+
*tls_begin = 0;
885+
*tls_end = 0;
886+
# else
887+
GetThreadStackTopAndBottom(main, stk_end, stk_begin);
888+
*tls_begin = 0;
889+
*tls_end = 0;
890+
# endif
894891
}
895892

896893
void ReportFile::Write(const char *buffer, uptr length) {

‎compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
+16-17Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,30 +204,29 @@ TEST(SanitizerCommon, InternalMmapVectorSwap) {
204204
}
205205

206206
void TestThreadInfo(bool main) {
207-
uptr stk_addr = 0;
208-
uptr stk_size = 0;
209-
uptr tls_addr = 0;
210-
uptr tls_size = 0;
211-
GetThreadStackAndTls(main, &stk_addr, &stk_size, &tls_addr, &tls_size);
207+
uptr stk_begin = 0;
208+
uptr stk_end = 0;
209+
uptr tls_begin = 0;
210+
uptr tls_end = 0;
211+
GetThreadStackAndTls(main, &stk_begin, &stk_end, &tls_begin, &tls_end);
212212

213213
int stack_var;
214-
EXPECT_NE(stk_addr, (uptr)0);
215-
EXPECT_NE(stk_size, (uptr)0);
216-
EXPECT_GT((uptr)&stack_var, stk_addr);
217-
EXPECT_LT((uptr)&stack_var, stk_addr + stk_size);
214+
EXPECT_NE(stk_begin, (uptr)0);
215+
EXPECT_GT(stk_end, stk_begin);
216+
EXPECT_GT((uptr)&stack_var, stk_begin);
217+
EXPECT_LT((uptr)&stack_var, stk_end);
218218

219219
#if SANITIZER_LINUX && defined(__x86_64__)
220220
static __thread int thread_var;
221-
EXPECT_NE(tls_addr, (uptr)0);
222-
EXPECT_NE(tls_size, (uptr)0);
223-
EXPECT_GT((uptr)&thread_var, tls_addr);
224-
EXPECT_LT((uptr)&thread_var, tls_addr + tls_size);
221+
EXPECT_NE(tls_begin, (uptr)0);
222+
EXPECT_GT(tls_end, tls_begin);
223+
EXPECT_GT((uptr)&thread_var, tls_begin);
224+
EXPECT_LT((uptr)&thread_var, tls_end);
225225

226226
// Ensure that tls and stack do not intersect.
227-
uptr tls_end = tls_addr + tls_size;
228-
EXPECT_TRUE(tls_addr < stk_addr || tls_addr >= stk_addr + stk_size);
229-
EXPECT_TRUE(tls_end < stk_addr || tls_end >= stk_addr + stk_size);
230-
EXPECT_TRUE((tls_addr < stk_addr) == (tls_end < stk_addr));
227+
EXPECT_TRUE(tls_begin < stk_begin || tls_begin >= stk_end);
228+
EXPECT_TRUE(tls_end < stk_begin || tls_end >= stk_end);
229+
EXPECT_TRUE((tls_begin < stk_begin) == (tls_end < stk_begin));
231230
#endif
232231
}
233232

‎compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp

Copy file name to clipboardExpand all lines: compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ void ThreadStart(ThreadState *thr, Tid tid, tid_t os_id,
165165
#endif
166166

167167
uptr stk_addr = 0;
168-
uptr stk_size = 0;
168+
uptr stk_end = 0;
169169
uptr tls_addr = 0;
170-
uptr tls_size = 0;
170+
uptr tls_end = 0;
171171
#if !SANITIZER_GO
172172
if (thread_type != ThreadType::Fiber)
173-
GetThreadStackAndTls(tid == kMainTid, &stk_addr, &stk_size, &tls_addr,
174-
&tls_size);
173+
GetThreadStackAndTls(tid == kMainTid, &stk_addr, &stk_end, &tls_addr,
174+
&tls_end);
175175
#endif
176+
uptr stk_size = stk_end - stk_addr;
177+
uptr tls_size = tls_end - tls_addr;
176178
thr->stk_addr = stk_addr;
177179
thr->stk_size = stk_size;
178180
thr->tls_addr = tls_addr;

‎compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c

Copy file name to clipboardExpand all lines: compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
// No allocator and hooks.
1010
// XFAIL: ubsan
1111

12-
// FIXME: Crashes on CHECK.
13-
// XFAIL: asan && !i386-linux
14-
// XFAIL: msan && !i386-linux
15-
1612
#ifndef BUILD_SO
1713
# include <assert.h>
1814
# include <dlfcn.h>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.