[asan] increase max stack size to 256 (+test)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163308 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index af5fbfe..b93964f 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -62,7 +62,7 @@
namespace __asan {
// -------------------------- Flags ------------------------- {{{1
-static const int kMallocContextSize = 64;
+static const int kDeafultMallocContextSize = 30;
static Flags asan_flags;
@@ -82,7 +82,7 @@
ParseFlag(str, &f->report_globals, "report_globals");
ParseFlag(str, &f->check_initialization_order, "initialization_order");
ParseFlag(str, &f->malloc_context_size, "malloc_context_size");
- CHECK(f->malloc_context_size <= kMallocContextSize);
+ CHECK(f->malloc_context_size <= kStackTraceMax);
ParseFlag(str, &f->replace_str, "replace_str");
ParseFlag(str, &f->replace_intrin, "replace_intrin");
@@ -121,7 +121,7 @@
f->debug = false;
f->report_globals = 1;
f->check_initialization_order = true;
- f->malloc_context_size = kMallocContextSize;
+ f->malloc_context_size = kDeafultMallocContextSize;
f->replace_str = true;
f->replace_intrin = true;
f->replace_cfallocator = true;
diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc
index e800e40..bdb5022 100644
--- a/lib/asan/asan_thread.cc
+++ b/lib/asan/asan_thread.cc
@@ -26,9 +26,6 @@
malloc_storage_(x),
stats_(x) { }
-static AsanLock mu_for_thread_summary(LINKER_INITIALIZED);
-static LowLevelAllocator allocator_for_thread_summary;
-
AsanThread *AsanThread::Create(u32 parent_tid, thread_callback_t start_routine,
void *arg, StackTrace *stack) {
uptr size = RoundUpTo(sizeof(AsanThread), kPageSize);
@@ -36,14 +33,10 @@
thread->start_routine_ = start_routine;
thread->arg_ = arg;
- const uptr kSummaryAllocSize = 1024;
+ const uptr kSummaryAllocSize = kPageSize;
CHECK_LE(sizeof(AsanThreadSummary), kSummaryAllocSize);
- AsanThreadSummary *summary;
- {
- ScopedLock lock(&mu_for_thread_summary);
- summary = (AsanThreadSummary*)
- allocator_for_thread_summary.Allocate(kSummaryAllocSize);
- }
+ AsanThreadSummary *summary =
+ (AsanThreadSummary*)MmapOrDie(kPageSize, "AsanThreadSummary");
summary->Init(parent_tid, stack);
summary->set_thread(thread);
thread->set_summary(summary);
diff --git a/lib/asan/lit_tests/deep_stack_uaf.cc b/lib/asan/lit_tests/deep_stack_uaf.cc
new file mode 100644
index 0000000..17d0a33
--- /dev/null
+++ b/lib/asan/lit_tests/deep_stack_uaf.cc
@@ -0,0 +1,36 @@
+// Check that we can store lots of stack frames if asked to.
+
+// RUN: %clangxx_asan -m64 -O0 %s -o %t 2>&1
+// RUN: ASAN_OPTIONS=malloc_context_size=120:redzone=512 %t 2>&1 | \
+// RUN: %symbolize | FileCheck %s
+
+// RUN: %clangxx_asan -m32 -O0 %s -o %t 2>&1
+// RUN: ASAN_OPTIONS=malloc_context_size=120:redzone=512 %t 2>&1 | \
+// RUN: %symbolize | FileCheck %s
+#include <stdlib.h>
+#include <stdio.h>
+
+template <int depth>
+struct DeepFree {
+ static void free(char *x) {
+ DeepFree<depth - 1>::free(x);
+ }
+};
+
+template<>
+struct DeepFree<0> {
+ static void free(char *x) {
+ ::free(x);
+ }
+};
+
+int main() {
+ char *x = new char[10];
+ // deep_free(x);
+ DeepFree<200>::free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer heap-use-after-free on address}}
+ // CHECK: DeepFree<36>
+ // CHECK: DeepFree<98>
+ // CHECK: DeepFree<115>
+}
diff --git a/lib/sanitizer_common/sanitizer_stacktrace.h b/lib/sanitizer_common/sanitizer_stacktrace.h
index 28e3f57..5d15a61 100644
--- a/lib/sanitizer_common/sanitizer_stacktrace.h
+++ b/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -17,7 +17,7 @@
namespace __sanitizer {
-static const uptr kStackTraceMax = 64;
+static const uptr kStackTraceMax = 256;
struct StackTrace {
typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,