-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[asan] Add experimental 'poison_history_size' flag #133175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
4cffa15
[asan] Add experimental 'track_poison' flag
thurstond 1c42b53
Use GET_STACK_TRACE (and only use it if track_poison is enabled)
thurstond 32a8dda
Single poison value
thurstond f080021
Add mutex
thurstond 7882b79
clang-format
thurstond 5db5a53
Cleanup
thurstond c17cb52
Simplify
thurstond ae3d17b
Typo
thurstond 4abbd69
Revert added newline
thurstond c0bbb3e
clang-format
thurstond f5ec200
clang-format
thurstond a93e41c
Poison record API
thurstond b03df8e
Change flag from track_poison to poison_history_size
thurstond c94f53c
Lazy initialize poison tracking data structure
thurstond 826d2f2
Fork handler
thurstond 9d07a0c
Use u32
thurstond 140b919
Formatting
thurstond 17e4077
Humorless test case
thurstond 249774b
Fix output and improve test
thurstond 19c3dfe
Add test case of Poisoned access with insufficient history
thurstond 3d2ee1d
Update test case and formatting
thurstond b6be8ed
clang-format
thurstond 1c4f226
Remove unused function declaration
thurstond ec2a866
Move #include
thurstond 411a091
Add 'flags()->poison_history_size <= 0' guards to ensure no-op
thurstond 1dd4385
Poison records depends on stack depot so must be locked before
thurstond b4c624e
Only unlock in child
thurstond 287a7b8
Address Vitaly's feedback
thurstond c2b1947
Hide diagnostic of stack depot did not have a matching stack
thurstond f4c7b3f
Check next shadow byte if partial granule. Add test case.
thurstond 00e9bf1
Update comment for partial granule test case
thurstond 0014b7e
clang-format
thurstond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
compiler-rt/test/asan/TestCases/use-after-poison-history-size-partial-granule.cpp
This file contains hidden or 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,40 @@ | ||
// Check that __asan_poison_memory_region and ASAN_OPTIONS=poison_history_size work for partial granules. | ||
// | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 20 2>&1 | FileCheck %s | ||
// | ||
// Partial granule | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 2>&1 | FileCheck %s | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
extern "C" void __asan_poison_memory_region(void *, size_t); | ||
extern "C" void __asan_unpoison_memory_region(void *, size_t); | ||
|
||
void honey_ive_poisoned_the_memory(char *x) { | ||
__asan_poison_memory_region(x + 10, 20); | ||
} | ||
|
||
void foo(char *x) { honey_ive_poisoned_the_memory(x); } | ||
|
||
int main(int argc, char **argv) { | ||
char *x = new char[64]; | ||
x[10] = 0; | ||
foo(x); | ||
// Bytes [0, 9]: addressable | ||
// Bytes [10, 31]: poisoned by A | ||
// Bytes [32, 63]: addressable | ||
|
||
int res = x[argc * 10]; // BOOOM | ||
// CHECK: ERROR: AddressSanitizer: use-after-poison | ||
// CHECK: main{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-2]] | ||
|
||
// CHECK: Memory was manually poisoned by thread T0: | ||
// CHECK: honey_ive_poisoned_the_memory{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-18]] | ||
// CHECK: foo{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-16]] | ||
// CHECK: main{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-12]] | ||
|
||
delete[] x; | ||
|
||
return 0; | ||
} |
65 changes: 65 additions & 0 deletions
65
compiler-rt/test/asan/TestCases/use-after-poison-history-size.cpp
This file contains hidden or 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,65 @@ | ||
// Check that __asan_poison_memory_region and ASAN_OPTIONS=poison_history_size work. | ||
// | ||
// Poisoned access with history | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-ACDE,CHECK-ABC,CHECK-AC,CHECK-A | ||
// | ||
// Not poisoned access | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 %run %t 20 2>&1 | FileCheck %s --check-prefixes=CHECK-ABC,CHECK-B,CHECK-BDE | ||
// | ||
// Poisoned access with history (different stack trace) | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 30 30 2>&1 | FileCheck %s --check-prefixes=CHECK-ACDE,CHECK-ABC,CHECK-AC,CHECK-C | ||
// | ||
// Poisoned access without history | ||
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-ACDE,CHECK-BDE,CHECK-D | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-ACDE,CHECK-BDE,CHECK-D | ||
|
||
// Poisoned access with insufficient history | ||
// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-ACDE,CHECK-BDE,CHECK-E | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
extern "C" void __asan_poison_memory_region(void *, size_t); | ||
extern "C" void __asan_unpoison_memory_region(void *, size_t); | ||
|
||
void honey_ive_poisoned_the_memory(char *x) { | ||
__asan_poison_memory_region(x, 64); // A | ||
__asan_unpoison_memory_region(x + 16, 8); // B | ||
__asan_poison_memory_region(x + 24, 16); // C | ||
} | ||
|
||
void foo(char *x) { honey_ive_poisoned_the_memory(x); } | ||
|
||
int main(int argc, char **argv) { | ||
char *x = new char[64]; | ||
x[10] = 0; | ||
foo(x); | ||
// Bytes [ 0, 15]: poisoned by A | ||
// Bytes [16, 23]: unpoisoned by B | ||
// Bytes [24, 63]: poisoned by C | ||
|
||
int res = x[argc * 10]; // BOOOM | ||
// CHECK-ACDE: ERROR: AddressSanitizer: use-after-poison | ||
// CHECK-ACDE: main{{.*}}use-after-poison-history-size.cpp:[[@LINE-2]] | ||
// CHECK-B-NOT: ERROR: AddressSanitizer: use-after-poison | ||
// CHECK-ABC-NOT: try the experimental setting ASAN_OPTIONS=poison_history_size= | ||
// CHECK-D: try the experimental setting ASAN_OPTIONS=poison_history_size= | ||
|
||
// CHECK-AC: Memory was manually poisoned by thread T0: | ||
// CHECK-A: honey_ive_poisoned_the_memory{{.*}}use-after-poison-history-size.cpp:[[@LINE-23]] | ||
// CHECK-C: honey_ive_poisoned_the_memory{{.*}}use-after-poison-history-size.cpp:[[@LINE-22]] | ||
// CHECK-AC: foo{{.*}}use-after-poison-history-size.cpp:[[@LINE-20]] | ||
// CHECK-AC: main{{.*}}use-after-poison-history-size.cpp:[[@LINE-16]] | ||
// CHECK-BDE-NOT: Memory was manually poisoned by thread T0: | ||
|
||
// CHECK-ABC-NOT: Try a larger value for ASAN_OPTIONS=poison_history_size= | ||
// CHECK-D-NOT: Try a larger value for ASAN_OPTIONS=poison_history_size= | ||
// CHECK-E: Try a larger value for ASAN_OPTIONS=poison_history_size= | ||
|
||
delete[] x; | ||
|
||
printf("End of program reached\n"); | ||
// CHECK-B: End of program reached | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.