Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hwasan] Detect use after scope within function.
Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D105201
- Loading branch information
Showing
16 changed files
with
489 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Tests use-after-scope detection and reporting. | ||
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope -g %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM | ||
|
||
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope=false -g %s -o %t && %run %t 2>&1 | ||
// Use after scope is turned off by default. | ||
// RUN: %clang_hwasan -g %s -o %t && %run %t 2>&1 | ||
|
||
// RUN: %clang_hwasan -fexperimental-new-pass-manager -mllvm -hwasan-use-after-scope -g %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clang_hwasan -fno-experimental-new-pass-manager -mllvm -hwasan-use-after-scope -g %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
|
||
// REQUIRES: stable-runtime | ||
|
||
// Stack histories currently are not recorded on x86. | ||
// XFAIL: x86_64 | ||
|
||
void USE(void *x) { // pretend_to_do_something(void *x) | ||
__asm__ __volatile__("" | ||
: | ||
: "r"(x) | ||
: "memory"); | ||
} | ||
|
||
__attribute__((noinline)) void Unrelated1() { | ||
int A[2]; | ||
USE(&A[0]); | ||
} | ||
__attribute__((noinline)) void Unrelated2() { | ||
int BB[3]; | ||
USE(&BB[0]); | ||
} | ||
__attribute__((noinline)) void Unrelated3() { | ||
int CCC[4]; | ||
USE(&CCC[0]); | ||
} | ||
|
||
__attribute__((noinline)) char buggy() { | ||
char *volatile p; | ||
{ | ||
char zzz[0x1000]; | ||
p = zzz; | ||
} | ||
return *p; | ||
} | ||
|
||
int main() { | ||
Unrelated1(); | ||
Unrelated2(); | ||
Unrelated3(); | ||
char p = buggy(); | ||
return p; | ||
// CHECK: READ of size 1 at | ||
// CHECK: #0 {{.*}} in buggy{{.*}}stack-uas.c:[[@LINE-10]] | ||
// CHECK: Cause: stack tag-mismatch | ||
// CHECK: is located in stack of thread | ||
// CHECK: Potentially referenced stack objects: | ||
// CHECK-NEXT: zzz in buggy {{.*}}stack-uas.c:[[@LINE-17]] | ||
// CHECK-NEXT: Memory tags around the buggy address | ||
|
||
// NOSYM: Previously allocated frames: | ||
// NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uas.c.tmp+0x{{.*}}){{$}} | ||
// NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uas.c.tmp+0x{{.*}}){{$}} | ||
// NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uas.c.tmp+0x{{.*}}){{$}} | ||
// NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uas.c.tmp+0x{{.*}}){{$}} | ||
// NOSYM-NEXT: Memory tags around the buggy address | ||
|
||
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in buggy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
compiler-rt/test/hwasan/TestCases/use-after-scope-dtor-order.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
compiler-rt/test/hwasan/TestCases/use-after-scope-nobug.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.