Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 0e12fa8

Browse files
committed
[hwasan] Fix handling of store errors.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@321121 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ebd3997 commit 0e12fa8

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lib/hwasan/hwasan_linux.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static AccessInfo GetAccessInfo(siginfo_t *info, ucontext_t *uc) {
189189
if ((code & 0xff00) != 0x100)
190190
return AccessInfo{0, 0, false, false}; // Not ours.
191191
bool is_store = code & 0x10;
192-
unsigned size_log = code & 0xff;
192+
unsigned size_log = code & 0xf;
193193
if (size_log > 4 && size_log != 0xf)
194194
return AccessInfo{0, 0, false, false}; // Not ours.
195195

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1-
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2-
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3-
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4-
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
1+
// RUN: %clangxx_hwasan -O0 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
2+
// RUN: %clangxx_hwasan -O1 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
3+
// RUN: %clangxx_hwasan -O2 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
4+
// RUN: %clangxx_hwasan -O3 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD
5+
6+
// RUN: %clangxx_hwasan -O0 -DSTORE %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,STORE
7+
58
// REQUIRES: stable-runtime
69

710
#include <stdlib.h>
811
#include <sanitizer/hwasan_interface.h>
912

1013
int main() {
1114
__hwasan_enable_allocator_tagging();
12-
char *x = (char*)malloc(10);
15+
char * volatile x = (char*)malloc(10);
1316
free(x);
1417
__hwasan_disable_allocator_tagging();
18+
#ifdef STORE
19+
x[5] = 42;
20+
#endif
21+
#ifdef LOAD
1522
return x[5];
16-
// CHECK: READ of size 1 at
17-
// CHECK: #0 {{.*}} in main {{.*}}use-after-free.cc:15
23+
#endif
24+
// LOAD: READ of size 1 at
25+
// LOAD: #0 {{.*}} in main {{.*}}use-after-free.cc:22
26+
27+
// STORE: WRITE of size 1 at
28+
// STORE: #0 {{.*}} in main {{.*}}use-after-free.cc:19
1829

1930
// CHECK: freed here:
2031
// CHECK: #0 {{.*}} in free {{.*}}hwasan_interceptors.cc
21-
// CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:13
32+
// CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:16
2233

2334
// CHECK: previously allocated here:
2435
// CHECK: #0 {{.*}} in __interceptor_malloc {{.*}}hwasan_interceptors.cc
25-
// CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:12
36+
// CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:15
2637

2738
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
2839
}

0 commit comments

Comments
 (0)