Skip to content

Commit 0769e3d

Browse files
committed
Revert "Add API to temporalily disable usage of ASAN's fake stack"
This reverts commit 4e72801.
1 parent 4e72801 commit 0769e3d

File tree

10 files changed

+12
-93
lines changed

10 files changed

+12
-93
lines changed

compiler-rt/include/sanitizer/asan_interface.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,6 @@ void SANITIZER_CDECL __asan_handle_no_return(void);
333333
/// trace. Returns 1 if successful, 0 if not.
334334
int SANITIZER_CDECL __asan_update_allocation_context(void *addr);
335335

336-
/// Disables fake stack for the current thread.
337-
/// Temporarily disables use-after-return detection for current thread.
338-
void SANITIZER_CDECL __asan_disable_fake_stack(void);
339-
340-
/// (Re)enables fake stack for the current thread.
341-
void SANITIZER_CDECL __asan_enable_fake_stack(void);
342-
343336
#ifdef __cplusplus
344337
} // extern "C"
345338
#endif

compiler-rt/lib/asan/asan_fake_stack.cpp

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -217,44 +217,26 @@ static THREADLOCAL FakeStack *fake_stack_tls;
217217
FakeStack *GetTLSFakeStack() {
218218
return fake_stack_tls;
219219
}
220-
void SetTLSFakeStack(AsanThread* t, FakeStack* fs) {
221-
if (fs && !t->IsFakeStackEnabled()) {
222-
return;
223-
}
220+
void SetTLSFakeStack(FakeStack *fs) {
224221
fake_stack_tls = fs;
225222
}
226223
#else
227224
FakeStack *GetTLSFakeStack() { return 0; }
228-
void SetTLSFakeStack(AsanThread* t, FakeStack* fs) {}
225+
void SetTLSFakeStack(FakeStack *fs) { }
229226
#endif // (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
230227

231-
static void DisableFakeStack() {
228+
static FakeStack *GetFakeStack() {
232229
AsanThread *t = GetCurrentThread();
233-
if (t) {
234-
t->SetFakeStackEnabled(false);
235-
}
236-
}
237-
238-
static void EnableFakeStack() {
239-
AsanThread* t = GetCurrentThread();
240-
if (t) {
241-
t->SetFakeStackEnabled(true);
242-
}
243-
}
244-
245-
static FakeStack* GetFakeStack(bool for_allocation = true) {
246-
AsanThread* t = GetCurrentThread();
247-
if (!t || (for_allocation && !t->IsFakeStackEnabled()))
248-
return nullptr;
230+
if (!t) return nullptr;
249231
return t->get_or_create_fake_stack();
250232
}
251233

252-
static FakeStack* GetFakeStackFast(bool for_allocation = true) {
234+
static FakeStack *GetFakeStackFast() {
253235
if (FakeStack *fs = GetTLSFakeStack())
254236
return fs;
255237
if (!__asan_option_detect_stack_use_after_return)
256238
return nullptr;
257-
return GetFakeStack(for_allocation);
239+
return GetFakeStack();
258240
}
259241

260242
static FakeStack *GetFakeStackFastAlways() {
@@ -329,9 +311,7 @@ extern "C" {
329311
// -asan-use-after-return=never, after modal UAR flag lands
330312
// (https://github.com/google/sanitizers/issues/1394)
331313
SANITIZER_INTERFACE_ATTRIBUTE
332-
void* __asan_get_current_fake_stack() {
333-
return GetFakeStackFast(/*for_allocation=*/false);
334-
}
314+
void *__asan_get_current_fake_stack() { return GetFakeStackFast(); }
335315

336316
SANITIZER_INTERFACE_ATTRIBUTE
337317
void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
@@ -369,9 +349,4 @@ void __asan_allocas_unpoison(uptr top, uptr bottom) {
369349
(reinterpret_cast<void *>(MemToShadow(top)), 0,
370350
(bottom - top) / ASAN_SHADOW_GRANULARITY);
371351
}
372-
373-
SANITIZER_INTERFACE_ATTRIBUTE
374-
void __asan_disable_fake_stack() { return DisableFakeStack(); }
375-
SANITIZER_INTERFACE_ATTRIBUTE
376-
void __asan_enable_fake_stack() { return EnableFakeStack(); }
377352
} // extern "C"

compiler-rt/lib/asan/asan_fake_stack.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
namespace __asan {
2020

21-
class AsanThread;
22-
2321
// Fake stack frame contains local variables of one function.
2422
struct FakeFrame {
2523
uptr magic; // Modified by the instrumented code.
@@ -198,7 +196,7 @@ class FakeStack {
198196
};
199197

200198
FakeStack *GetTLSFakeStack();
201-
void SetTLSFakeStack(AsanThread* t, FakeStack* fs);
199+
void SetTLSFakeStack(FakeStack *fs);
202200

203201
} // namespace __asan
204202

compiler-rt/lib/asan/asan_interface.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ INTERFACE_FUNCTION(__asan_alloca_poison)
1515
INTERFACE_FUNCTION(__asan_allocas_unpoison)
1616
INTERFACE_FUNCTION(__asan_before_dynamic_init)
1717
INTERFACE_FUNCTION(__asan_describe_address)
18-
INTERFACE_FUNCTION(__asan_disable_fake_stack)
19-
INTERFACE_FUNCTION(__asan_enable_fake_stack)
2018
INTERFACE_FUNCTION(__asan_exp_load1)
2119
INTERFACE_FUNCTION(__asan_exp_load2)
2220
INTERFACE_FUNCTION(__asan_exp_load4)

compiler-rt/lib/asan/asan_thread.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
163163
if (fake_stack_save)
164164
*fake_stack_save = fake_stack_;
165165
fake_stack_ = nullptr;
166-
SetTLSFakeStack(this, nullptr);
166+
SetTLSFakeStack(nullptr);
167167
// if fake_stack_save is null, the fiber will die, delete the fakestack
168168
if (!fake_stack_save && current_fake_stack)
169169
current_fake_stack->Destroy(this->tid());
@@ -177,7 +177,7 @@ void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
177177
}
178178

179179
if (fake_stack_save) {
180-
SetTLSFakeStack(this, fake_stack_save);
180+
SetTLSFakeStack(fake_stack_save);
181181
fake_stack_ = fake_stack_save;
182182
}
183183

@@ -242,7 +242,7 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
242242
Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
243243
fake_stack_ = FakeStack::Create(stack_size_log);
244244
DCHECK_EQ(GetCurrentThread(), this);
245-
SetTLSFakeStack(this, fake_stack_);
245+
SetTLSFakeStack(fake_stack_);
246246
return fake_stack_;
247247
}
248248
return nullptr;
@@ -251,7 +251,6 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
251251
void AsanThread::Init(const InitOptions *options) {
252252
DCHECK_NE(tid(), kInvalidTid);
253253
next_stack_top_ = next_stack_bottom_ = 0;
254-
fake_stack_enabled_ = true;
255254
atomic_store(&stack_switching_, false, memory_order_release);
256255
CHECK_EQ(this->stack_size(), 0U);
257256
SetThreadStackAndTls(options);

compiler-rt/lib/asan/asan_thread.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class AsanThread {
104104
if (!fake_stack_) return;
105105
FakeStack *t = fake_stack_;
106106
fake_stack_ = nullptr;
107-
SetTLSFakeStack(this, nullptr);
107+
SetTLSFakeStack(nullptr);
108108
t->Destroy(tid);
109109
}
110110

@@ -144,14 +144,6 @@ class AsanThread {
144144
GetStartData(&data, sizeof(data));
145145
}
146146

147-
bool IsFakeStackEnabled() const { return fake_stack_enabled_; }
148-
void SetFakeStackEnabled(bool enabled) {
149-
fake_stack_enabled_ = enabled;
150-
if (!enabled) {
151-
SetTLSFakeStack(this, nullptr);
152-
}
153-
}
154-
155147
private:
156148
// NOTE: There is no AsanThread constructor. It is allocated
157149
// via mmap() and *must* be valid in zero-initialized state.
@@ -187,7 +179,6 @@ class AsanThread {
187179
DTLS *dtls_;
188180

189181
FakeStack *fake_stack_;
190-
bool fake_stack_enabled_;
191182
AsanThreadLocalMallocStorage malloc_storage_;
192183
AsanStats stats_;
193184
bool unwinding_;

compiler-rt/lib/asan_abi/asan_abi.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ void *__asan_abi_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
7373
void **end) {
7474
return NULL;
7575
}
76-
void __asan_abi_disable_fake_stack(void) {}
77-
void __asan_abi_enable_fake_stack(void) {}
7876

7977
// Functions concerning poisoning and unpoisoning fake stack alloca
8078
void __asan_abi_alloca_poison(void *addr, size_t size) {}

compiler-rt/lib/asan_abi/asan_abi.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ void *__asan_abi_load_cxx_array_cookie(void **p);
7676
void *__asan_abi_get_current_fake_stack();
7777
void *__asan_abi_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
7878
void **end);
79-
void *__asan_abi_disable_fake_stack();
80-
void *__asan_abi_enable_fake_stack();
81-
8279
// Functions concerning poisoning and unpoisoning fake stack alloca
8380
void __asan_abi_alloca_poison(void *addr, size_t size);
8481
void __asan_abi_allocas_unpoison(void *top, void *bottom);

compiler-rt/lib/asan_abi/asan_abi_shim.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,6 @@ void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
365365
void **end) {
366366
return __asan_abi_addr_is_in_fake_stack(fake_stack, addr, beg, end);
367367
}
368-
void __asan_disable_fake_stack(void) { return __asan_abi_disable_fake_stack(); }
369-
void __asan_enable_fake_stack(void) { return __asan_abi_enable_fake_stack(); }
370368

371369
// Functions concerning poisoning and unpoisoning fake stack alloca
372370
void __asan_alloca_poison(uptr addr, uptr size) {

compiler-rt/test/asan/TestCases/disable_fake_stack.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)