[compiler-rt] 6826f1a - [ASan] Fix UnpoisonDefaultStack stack bottom estimation (#178137)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 27 10:17:15 PST 2026
Author: Andrew Haberlandt
Date: 2026-01-27T10:17:10-08:00
New Revision: 6826f1a6f35b690b604bc81bfe73a5b743905303
URL: https://github.com/llvm/llvm-project/commit/6826f1a6f35b690b604bc81bfe73a5b743905303
DIFF: https://github.com/llvm/llvm-project/commit/6826f1a6f35b690b604bc81bfe73a5b743905303.diff
LOG: [ASan] Fix UnpoisonDefaultStack stack bottom estimation (#178137)
UnpoisonDefaultStack estimates the stack bottom as:
```
bottom = ((uptr)&local_stack - page_size) & ~(page_size - 1);
```
However, this can try to poision memory that doesn't have a shadow (i.e.
AddrIsInMem(x) is false) if the local_stack variable is within two pages
of the actual bottom of the space available for stack. This causes the
unpoison-alternate-stack.cpp test (which allocates a very small stack)
to fail.
This PR changes this computation to check AddrIsInMem before subtracting
the additional page.
rdar://82645815
Added:
Modified:
compiler-rt/lib/asan/asan_rtl.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index b9ba250f5bcd7..c036a13a11029 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -618,7 +618,9 @@ static void UnpoisonDefaultStack() {
int local_stack;
const uptr page_size = GetPageSizeCached();
top = curr_thread->stack_top();
- bottom = ((uptr)&local_stack - page_size) & ~(page_size - 1);
+ bottom = (uptr)&local_stack & ~(page_size - 1);
+ if (AddrIsInMem(bottom - page_size))
+ bottom -= page_size;
} else {
CHECK(!SANITIZER_FUCHSIA);
// If we haven't seen this thread, try asking the OS for stack bounds.
More information about the llvm-commits
mailing list