[llvm-commits] [compiler-rt] r150101 - in /compiler-rt/trunk/lib/asan: asan_interceptors.cc asan_interface.h asan_rtl.cc tests/clone_test.cc tests/clone_test.tmpl
Kostya Serebryany
kcc at google.com
Wed Feb 8 13:33:27 PST 2012
Author: kcc
Date: Wed Feb 8 15:33:27 2012
New Revision: 150101
URL: http://llvm.org/viewvc/llvm-project?rev=150101&view=rev
Log:
[asan] unpoison the stack before every noreturn call. Fixes asan issue 37. rt part
Added:
compiler-rt/trunk/lib/asan/tests/clone_test.cc
compiler-rt/trunk/lib/asan/tests/clone_test.tmpl
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
compiler-rt/trunk/lib/asan/asan_interface.h
compiler-rt/trunk/lib/asan/asan_rtl.cc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=150101&r1=150100&r2=150101&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Wed Feb 8 15:33:27 2012
@@ -231,28 +231,18 @@
}
#endif // _WIN32
-
-static void UnpoisonStackFromHereToTop() {
- int local_stack;
- AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
- CHECK(curr_thread);
- uintptr_t top = curr_thread->stack_top();
- uintptr_t bottom = ((uintptr_t)&local_stack - kPageSize) & ~(kPageSize-1);
- PoisonShadow(bottom, top - bottom, 0);
-}
-
INTERCEPTOR(void, longjmp, void *env, int val) {
- UnpoisonStackFromHereToTop();
+ __asan_handle_no_return();
REAL(longjmp)(env, val);
}
INTERCEPTOR(void, _longjmp, void *env, int val) {
- UnpoisonStackFromHereToTop();
+ __asan_handle_no_return();
REAL(_longjmp)(env, val);
}
INTERCEPTOR(void, siglongjmp, void *env, int val) {
- UnpoisonStackFromHereToTop();
+ __asan_handle_no_return();
REAL(siglongjmp)(env, val);
}
@@ -263,7 +253,7 @@
INTERCEPTOR(void, __cxa_throw, void *a, void *b, void *c) {
CHECK(REAL(__cxa_throw));
- UnpoisonStackFromHereToTop();
+ __asan_handle_no_return();
REAL(__cxa_throw)(a, b, c);
}
#endif
Modified: compiler-rt/trunk/lib/asan/asan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interface.h?rev=150101&r1=150100&r2=150101&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interface.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interface.h Wed Feb 8 15:33:27 2012
@@ -79,6 +79,10 @@
// (un)poison memory in the same memory region simultaneously.
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
+ // Performs cleanup before a NoReturn function. Must be called before things
+ // like _exit and execl to avoid false positives on stack.
+ void __asan_handle_no_return();
+
// User code should use macro instead of functions.
#if defined(__has_feature) && __has_feature(address_sanitizer)
#define ASAN_POISON_MEMORY_REGION(addr, size) \
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=150101&r1=150100&r2=150101&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed Feb 8 15:33:27 2012
@@ -283,6 +283,15 @@
return old;
}
+void __asan_handle_no_return() {
+ int local_stack;
+ AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
+ CHECK(curr_thread);
+ uintptr_t top = curr_thread->stack_top();
+ uintptr_t bottom = ((uintptr_t)&local_stack - kPageSize) & ~(kPageSize-1);
+ PoisonShadow(bottom, top - bottom, 0);
+}
+
void __asan_report_error(uintptr_t pc, uintptr_t bp, uintptr_t sp,
uintptr_t addr, bool is_write, size_t access_size) {
// Do not print more than one report, otherwise they will mix up.
Added: compiler-rt/trunk/lib/asan/tests/clone_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/clone_test.cc?rev=150101&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/clone_test.cc (added)
+++ compiler-rt/trunk/lib/asan/tests/clone_test.cc Wed Feb 8 15:33:27 2012
@@ -0,0 +1,33 @@
+#ifdef __linux__
+#include <stdio.h>
+#include <sched.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int Child(void *arg) {
+ char x[32] = {0}; // Stack gets poisoned.
+ printf("Child: %p\n", x);
+ _exit(1); // NoReturn, stack will remain unpoisoned unless we do something.
+}
+
+int main(int argc, char **argv) {
+ const int kStackSize = 1 << 20;
+ char child_stack[kStackSize + 1];
+ char *sp = child_stack + kStackSize; // Stack grows down.
+ printf("Parent: %p\n", sp);
+ pid_t clone_pid = clone(Child, sp, CLONE_FILES | CLONE_VM, NULL, 0, 0, 0);
+ waitpid(clone_pid, NULL, 0);
+ for (int i = 0; i < kStackSize; i++)
+ child_stack[i] = i;
+ int ret = child_stack[argc - 1];
+ printf("PASSED\n");
+ return ret;
+}
+#else // not __linux__
+#include <stdio.h>
+int main() {
+ printf("PASSED\n");
+}
+#endif
Added: compiler-rt/trunk/lib/asan/tests/clone_test.tmpl
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/clone_test.tmpl?rev=150101&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/clone_test.tmpl (added)
+++ compiler-rt/trunk/lib/asan/tests/clone_test.tmpl Wed Feb 8 15:33:27 2012
@@ -0,0 +1 @@
+PASSED
More information about the llvm-commits
mailing list