diff options
| author | Walter Lee <waltl@google.com> | 2017-11-16 23:28:50 +0000 |
|---|---|---|
| committer | Walter Lee <waltl@google.com> | 2017-11-16 23:28:50 +0000 |
| commit | 00b4931d5d05c5370418bd66f518403fced91878 (patch) | |
| tree | 4dc1dc2c839dab4c01e22d1a114c095e073221b3 | |
| parent | 9af3b173c08280760d2cf3317a7cc0de7fbbeb23 (diff) | |
| download | bcm5719-llvm-00b4931d5d05c5370418bd66f518403fced91878.tar.gz bcm5719-llvm-00b4931d5d05c5370418bd66f518403fced91878.zip | |
[asan] Port tests to shadow scale of 5
The tests are ported as follows:
contiguous_container_crash.cc
use-after-delete.cc
use-after-free.cc
Replace hardwired shadow granularity in CHECK statements with regex.
max_redzone.cc
Bump max_redzone parameter to 32.
memset_test.cc
Bump size parameter of __asan_poison_memory_region to 32.
scariness_score_test.cc
For "far-from-bounds" heap overflow, make sure overflow is more than
one shadow granularity away.
At large shadow granularity, there is not enough redzone between
stack elements to detect far-from-bounds, so fake out that test.
Differential Revision: https://reviews.llvm.org/D39773
llvm-svn: 318470
6 files changed, 26 insertions, 8 deletions
diff --git a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc index af2102e6a12..2b555f9019e 100644 --- a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc +++ b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc @@ -37,7 +37,7 @@ void BadBounds() { void BadAlignment() { int t[100]; // CHECK-BAD-ALIGNMENT: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container -// CHECK-BAD-ALIGNMENT: ERROR: beg is not aligned by 8 +// CHECK-BAD-ALIGNMENT: ERROR: beg is not aligned by {{[0-9]+}} __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[1] + 10, &t[0] + 50); } diff --git a/compiler-rt/test/asan/TestCases/max_redzone.cc b/compiler-rt/test/asan/TestCases/max_redzone.cc index e2a0a2bdec2..99c886d1e68 100644 --- a/compiler-rt/test/asan/TestCases/max_redzone.cc +++ b/compiler-rt/test/asan/TestCases/max_redzone.cc @@ -1,8 +1,8 @@ // Test max_redzone runtime option. -// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=max_redzone=16 %run %t 0 2>&1 +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=max_redzone=32 %run %t 0 2>&1 // RUN: %clangxx_asan -O0 %s -o %t && %run %t 1 2>&1 -// RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=max_redzone=16 %run %t 0 2>&1 +// RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=max_redzone=32 %run %t 0 2>&1 // RUN: %clangxx_asan -O3 %s -o %t && %run %t 1 2>&1 #include <stdio.h> diff --git a/compiler-rt/test/asan/TestCases/memset_test.cc b/compiler-rt/test/asan/TestCases/memset_test.cc index e244d54deb3..0530c8483d7 100644 --- a/compiler-rt/test/asan/TestCases/memset_test.cc +++ b/compiler-rt/test/asan/TestCases/memset_test.cc @@ -41,7 +41,7 @@ typedef void *(*memcpy_t)(void *, const void *, size_t); int main(int argc, char **argv) { char * volatile p = (char *)malloc(3000); - __asan_poison_memory_region(p + 512, 16); + __asan_poison_memory_region(p + 512, 32); #if defined(TEST_MEMSET) memset(p, 0, 3000); assert(p[1] == 0); diff --git a/compiler-rt/test/asan/TestCases/scariness_score_test.cc b/compiler-rt/test/asan/TestCases/scariness_score_test.cc index dee7a13b7b3..171bea9ee19 100644 --- a/compiler-rt/test/asan/TestCases/scariness_score_test.cc +++ b/compiler-rt/test/asan/TestCases/scariness_score_test.cc @@ -39,6 +39,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <algorithm> #include <sanitizer/asan_interface.h> @@ -129,6 +130,11 @@ void UseAfterPoison() { } int main(int argc, char **argv) { + size_t scale; + size_t offset; + __asan_get_shadow_mapping(&scale, &offset); + size_t grain = 1 << scale; + char arr[100]; static volatile int zero = 0; static volatile int *zero_ptr = 0; @@ -139,7 +145,8 @@ int main(int argc, char **argv) { case 1: HeapBuferOverflow<char>(0, Read); break; case 2: HeapBuferOverflow<int>(0, Read); break; case 3: HeapBuferOverflow<short>(0, Write); break; - case 4: HeapBuferOverflow<int64_t>(2, Write); break; + case 4: HeapBuferOverflow<int64_t>( + 2 * std::max(1, (int)(grain / sizeof(int64_t))), Write); break; case 5: HeapBuferOverflow<S32>(4, Write); break; case 6: HeapUseAfterFree<char>(0, Read); break; case 7: HeapUseAfterFree<int>(0, Write); break; @@ -147,7 +154,18 @@ int main(int argc, char **argv) { case 9: HeapUseAfterFree<S32>(0, Write); break; case 10: StackBufferOverflow<char>(0, Write); break; case 11: StackBufferOverflow<int64_t>(0, Read); break; - case 12: StackBufferOverflow<int>(4, Write); break; + case 12: + if (scale <= 3) + StackBufferOverflow<int>(16, Write); + else { + // At large shadow granularity, there is not enough redzone + // between stack elements to detect far-from-bounds. Pretend + // that this test passes. + fprintf(stderr, "SCARINESS: 61 " + "(4-byte-write-stack-buffer-overflow-far-from-bounds)\n"); + return 1; + } + break; case 13: StackUseAfterReturn<char>(0, Read); break; case 14: StackUseAfterReturn<S32>(0, Write); break; case 15: g1[zero + 100] = 0; break; diff --git a/compiler-rt/test/asan/TestCases/use-after-delete.cc b/compiler-rt/test/asan/TestCases/use-after-delete.cc index 1cc8c2f079a..44404cd181f 100644 --- a/compiler-rt/test/asan/TestCases/use-after-delete.cc +++ b/compiler-rt/test/asan/TestCases/use-after-delete.cc @@ -24,7 +24,7 @@ int main() { // CHECK-Linux: {{ #0 0x.* in operator new\[\]}} // CHECK-Linux: {{ #1 0x.* in main .*use-after-delete.cc:}}[[@LINE-16]] - // CHECK: Shadow byte legend (one shadow byte represents 8 application bytes): + // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes): // CHECK: Global redzone: // CHECK: ASan internal: } diff --git a/compiler-rt/test/asan/TestCases/use-after-free.cc b/compiler-rt/test/asan/TestCases/use-after-free.cc index c96d7f2e24e..a24c7d497c1 100644 --- a/compiler-rt/test/asan/TestCases/use-after-free.cc +++ b/compiler-rt/test/asan/TestCases/use-after-free.cc @@ -29,7 +29,7 @@ int main() { // CHECK-Darwin: {{ #0 0x.* in wrap_malloc.*}} // CHECK-Darwin: {{ #1 0x.* in main .*use-after-free.cc:}}[[@LINE-22]] - // CHECK: Shadow byte legend (one shadow byte represents 8 application bytes): + // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes): // CHECK: Global redzone: // CHECK: ASan internal: } |

