[compiler-rt] r321121 - [hwasan] Fix handling of store errors.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 19 14:57:02 PST 2017


Author: eugenis
Date: Tue Dec 19 14:57:02 2017
New Revision: 321121

URL: http://llvm.org/viewvc/llvm-project?rev=321121&view=rev
Log:
[hwasan] Fix handling of store errors.

Modified:
    compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
    compiler-rt/trunk/test/hwasan/TestCases/use-after-free.cc

Modified: compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_linux.cc?rev=321121&r1=321120&r2=321121&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_linux.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_linux.cc Tue Dec 19 14:57:02 2017
@@ -189,7 +189,7 @@ static AccessInfo GetAccessInfo(siginfo_
   if ((code & 0xff00) != 0x100)
     return AccessInfo{0, 0, false, false}; // Not ours.
   bool is_store = code & 0x10;
-  unsigned size_log = code & 0xff;
+  unsigned size_log = code & 0xf;
   if (size_log > 4 && size_log != 0xf)
     return AccessInfo{0, 0, false, false}; // Not ours.
 

Modified: compiler-rt/trunk/test/hwasan/TestCases/use-after-free.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/hwasan/TestCases/use-after-free.cc?rev=321121&r1=321120&r2=321121&view=diff
==============================================================================
--- compiler-rt/trunk/test/hwasan/TestCases/use-after-free.cc (original)
+++ compiler-rt/trunk/test/hwasan/TestCases/use-after-free.cc Tue Dec 19 14:57:02 2017
@@ -1,7 +1,10 @@
-// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
-// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
-// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
-// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: %clangxx_hwasan -O0 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
+// RUN: %clangxx_hwasan -O1 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
+// RUN: %clangxx_hwasan -O2 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
+// RUN: %clangxx_hwasan -O3 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
+
+// RUN: %clangxx_hwasan -O0 -DSTORE %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,STORE
+
 // REQUIRES: stable-runtime
 
 #include <stdlib.h>
@@ -9,20 +12,28 @@
 
 int main() {
   __hwasan_enable_allocator_tagging();
-  char *x = (char*)malloc(10);
+  char * volatile x = (char*)malloc(10);
   free(x);
   __hwasan_disable_allocator_tagging();
+#ifdef STORE
+  x[5] = 42;
+#endif
+#ifdef LOAD
   return x[5];
-  // CHECK: READ of size 1 at
-  // CHECK: #0 {{.*}} in main {{.*}}use-after-free.cc:15
+#endif
+  // LOAD: READ of size 1 at
+  // LOAD: #0 {{.*}} in main {{.*}}use-after-free.cc:22
+
+  // STORE: WRITE of size 1 at
+  // STORE: #0 {{.*}} in main {{.*}}use-after-free.cc:19
 
   // CHECK: freed here:
   // CHECK: #0 {{.*}} in free {{.*}}hwasan_interceptors.cc
-  // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:13
+  // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:16
 
   // CHECK: previously allocated here:
   // CHECK: #0 {{.*}} in __interceptor_malloc {{.*}}hwasan_interceptors.cc
-  // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:12
+  // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:15
 
   // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
 }




More information about the llvm-commits mailing list