[compiler-rt] r206753 - [asan] add a run-time flag detect_container_overflow=true/false

Kostya Serebryany kcc at google.com
Mon Apr 21 07:18:45 PDT 2014


Author: kcc
Date: Mon Apr 21 09:18:45 2014
New Revision: 206753

URL: http://llvm.org/viewvc/llvm-project?rev=206753&view=rev
Log:
[asan] add a run-time flag detect_container_overflow=true/false

Modified:
    compiler-rt/trunk/lib/asan/asan_flags.h
    compiler-rt/trunk/lib/asan/asan_poisoning.cc
    compiler-rt/trunk/lib/asan/asan_report.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/test/asan/TestCases/contiguous_container_crash.cc

Modified: compiler-rt/trunk/lib/asan/asan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.h?rev=206753&r1=206752&r2=206753&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.h (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.h Mon Apr 21 09:18:45 2014
@@ -63,6 +63,7 @@ struct Flags {
   bool strict_init_order;
   bool start_deactivated;
   int detect_invalid_pointer_pairs;
+  bool detect_container_overflow;
 };
 
 extern Flags asan_flags_dont_use_directly;

Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=206753&r1=206752&r2=206753&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Mon Apr 21 09:18:45 2014
@@ -266,6 +266,7 @@ void __sanitizer_annotate_contiguous_con
                                                const void *end_p,
                                                const void *old_mid_p,
                                                const void *new_mid_p) {
+  if (!flags()->detect_container_overflow) return;
   VPrintf(2, "contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p,
           new_mid_p);
   uptr beg = reinterpret_cast<uptr>(beg_p);

Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=206753&r1=206752&r2=206753&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Mon Apr 21 09:18:45 2014
@@ -141,7 +141,7 @@ static void PrintLegend(InternalScopedSt
                   kAsanInitializationOrderMagic);
   PrintShadowByte(str, "  Poisoned by user:        ",
                   kAsanUserPoisonedMemoryMagic);
-  PrintShadowByte(str, "  Contiguous container OOB:",
+  PrintShadowByte(str, "  Container overflow:      ",
                   kAsanContiguousContainerOOBMagic);
   PrintShadowByte(str, "  ASan internal:           ", kAsanInternalHeapMagic);
 }

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=206753&r1=206752&r2=206753&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Apr 21 09:18:45 2014
@@ -220,6 +220,11 @@ static void ParseFlagsFromString(Flags *
       "If non-zero, try to detect operations like <, <=, >, >= and - on "
       "invalid pointer pairs (e.g. when pointers belong to different objects). "
       "The bigger the value the harder we try.");
+
+  ParseFlag(str, &f->detect_container_overflow,
+      "detect_container_overflow",
+      "If true, honor the container overflow  annotations. "
+      "See https://code.google.com/p/address-sanitizer/wiki/ContainerOverflow");
 }
 
 void InitializeFlags(Flags *f, const char *env) {
@@ -267,6 +272,7 @@ void InitializeFlags(Flags *f, const cha
   f->strict_init_order = false;
   f->start_deactivated = false;
   f->detect_invalid_pointer_pairs = 0;
+  f->detect_container_overflow = true;
 
   // Override from compile definition.
   ParseFlagsFromString(f, MaybeUseAsanDefaultOptionsCompileDefiniton());

Modified: compiler-rt/trunk/test/asan/TestCases/contiguous_container_crash.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/contiguous_container_crash.cc?rev=206753&r1=206752&r2=206753&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/contiguous_container_crash.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/contiguous_container_crash.cc Mon Apr 21 09:18:45 2014
@@ -1,6 +1,8 @@
 // RUN: %clangxx_asan -O %s -o %t
 // RUN: not %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: not %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD %s
+// RUN: ASAN_OPTIONS=detect_container_overflow=0 %t crash
+//
 // Test crash due to __sanitizer_annotate_contiguous_container.
 
 #include <assert.h>
@@ -16,6 +18,7 @@ static volatile int one = 1;
 
 int TestCrash() {
   long t[100];
+  t[60] = 0;
   __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
                                             &t[0] + 50);
   return (int)t[60 * one];  // Touches the poisoned memory.





More information about the llvm-commits mailing list