diff options
Diffstat (limited to 'compiler-rt/test/asan')
20 files changed, 351 insertions, 61 deletions
diff --git a/compiler-rt/test/asan/TestCases/Darwin/Inputs/check-syslog.sh b/compiler-rt/test/asan/TestCases/Darwin/Inputs/check-syslog.sh new file mode 100755 index 0000000..8939ca7 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Darwin/Inputs/check-syslog.sh @@ -0,0 +1,6 @@ +#!/bin/sh +for I in {1..3}; do \ + log show --debug --last $((SECONDS + 30))s --predicate "processID == $1" --style syslog > $2; \ + if grep -q "use-after-poison" $2; then break; fi; \ + sleep 5; \ +done diff --git a/compiler-rt/test/asan/TestCases/Darwin/asan-verify-module-map.cpp b/compiler-rt/test/asan/TestCases/Darwin/asan-verify-module-map.cpp index 7660841..15be1cd 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/asan-verify-module-map.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/asan-verify-module-map.cpp @@ -3,10 +3,10 @@ // RUN: %clangxx_asan -DSHARED_LIB -g %s -dynamiclib -o %t.dylib // RUN: %clangxx_asan -O0 -g %s %t.dylib -o %t.executable -// RUN: %env_asan_opts="print_module_map=2" not %run %t.executable 2>&1 | FileCheck %s -DDYLIB=%t.dylib +// RUN: %env_asan_opts="print_module_map=2" not %run %t.executable 2>&1 | FileCheck %s -DDYLIB=%{t:stem}.tmp.dylib // CHECK-NOT: WARN: Invalid dyld module map -// CHECK-DAG: 0x{{.*}}-0x{{.*}} [[DYLIB]] +// CHECK-DAG: 0x{{.*}}-0x{{.*}} {{.*}}[[DYLIB]] // CHECK-DAG: 0x{{.*}}-0x{{.*}} {{.*}}libsystem #ifdef SHARED_LIB diff --git a/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cpp b/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cpp index 664471b..4201d49 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cpp @@ -1,6 +1,7 @@ // Check that when having a DYLD_ROOT_PATH set, the symbolizer still works. // RUN: %clangxx_asan -O0 %s -o %t -// RUN: %env_asan_opts=verbosity=2 DYLD_ROOT_PATH="/" ASAN_SYMBOLIZER_PATH=$(which atos) \ +// RUN: which atos | tr -d '\n' > %t.symbolizer_path +// RUN: %env_asan_opts=verbosity=2 DYLD_ROOT_PATH="/" ASAN_SYMBOLIZER_PATH=%{readfile:%t.symbolizer_path} \ // RUN: not %run %t 2>&1 | FileCheck %s // // Due to a bug in atos, this only works on x86_64. diff --git a/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer.cpp b/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer.cpp index bab4e4f..7487bd4 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer.cpp @@ -1,7 +1,8 @@ // Check that the `atos` symbolizer works. // RUN: %clangxx_asan -O0 %s -o %t -// RUN: %env_asan_opts=verbosity=2 ASAN_SYMBOLIZER_PATH=$(which atos) not %run %t 2>&1 | FileCheck %s +// RUN: which atos | tr -d '\n' > %t.symbolizer_path +// RUN: %env_asan_opts=verbosity=2 ASAN_SYMBOLIZER_PATH=%{readfile:%t.symbolizer_path} not %run %t 2>&1 | FileCheck %s // Path returned by `which atos` is invalid on iOS. // UNSUPPORTED: ios, i386-darwin diff --git a/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp b/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp index 5a0353b..40a168b 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp @@ -1,8 +1,8 @@ // UNSUPPORTED: ios // REQUIRES: darwin_log_cmd // RUN: %clangxx_asan -fsanitize-recover=address %s -o %t -// RUN: { %env_asan_opts=halt_on_error=0,log_to_syslog=1 %run %t > %t.process_output.txt 2>&1 & } \ -// RUN: ; export TEST_PID=$! ; wait ${TEST_PID} +// RUN: bash -c '{ %env_asan_opts=halt_on_error=0,log_to_syslog=1 %run %t > %t.process_output.txt 2>&1 & } \ +// RUN: ; export TEST_PID=$! ; wait ${TEST_PID}; echo -n ${TEST_PID} > %t.test_pid' // Check process output. // RUN: FileCheck %s --check-prefixes CHECK,CHECK-PROC -input-file=%t.process_output.txt @@ -10,11 +10,7 @@ // Check syslog output. We filter recent system logs based on PID to avoid // getting the logs of previous test runs. Make some reattempts in case there // is a delay. -// RUN: for I in {1..3}; do \ -// RUN: log show --debug --last $((SECONDS + 30))s --predicate "processID == ${TEST_PID}" --style syslog > %t.process_syslog_output.txt; \ -// RUN: if grep -q "use-after-poison" %t.process_syslog_output.txt; then break; fi; \ -// RUN: sleep 5; \ -// RUN: done +// RUN: %S/Inputs/check-syslog.sh %{readfile:%t.test_pid} %t.process_syslog_output.txt // RUN: FileCheck %s -input-file=%t.process_syslog_output.txt #include <cassert> #include <cstdio> diff --git a/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cpp b/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cpp index 0fec18b..89ee7a1 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cpp @@ -4,7 +4,8 @@ // UNSUPPORTED: ios // RUN: rm -rf %t && mkdir -p %t -// RUN: cp `%clang_asan -print-file-name=lib`/darwin/libclang_rt.asan_osx_dynamic.dylib \ +// RUN: %clang_asan -print-file-name=lib | tr -d '\n' > %t.lib_name +// RUN: cp %{readfile:%t.lib_name}/darwin/libclang_rt.asan_osx_dynamic.dylib \ // RUN: %t/libclang_rt.asan_osx_dynamic.dylib // RUN: %clangxx_asan %s -o %t/a.out @@ -13,23 +14,12 @@ // RUN: %run %t/a.out 2>&1 \ // RUN: | FileCheck %s -// RUN: MACOS_MAJOR=$(sw_vers -productVersion | cut -d'.' -f1) -// RUN: MACOS_MINOR=$(sw_vers -productVersion | cut -d'.' -f2) - -// RUN: IS_MACOS_10_11_OR_HIGHER=$([ $MACOS_MAJOR -eq 10 ] && [ $MACOS_MINOR -lt 11 ]; echo $?) - // On OS X 10.10 and lower, if the dylib is not DYLD-inserted, ASan will re-exec. -// RUN: if [ $IS_MACOS_10_11_OR_HIGHER == 0 ]; then \ -// RUN: %env_asan_opts=verbosity=1 %run %t/a.out 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-NOINSERT %s; \ -// RUN: fi +// RUN: %if mac-os-10-11-or-higher %{ %env_asan_opts=verbosity=1 %run %t/a.out 2>&1 | FileCheck --check-prefix=CHECK-NOINSERT %s %} // On OS X 10.11 and higher, we don't need to DYLD-insert anymore, and the interceptors // still installed correctly. Let's just check that things work and we don't try to re-exec. -// RUN: if [ $IS_MACOS_10_11_OR_HIGHER == 1 ]; then \ -// RUN: %env_asan_opts=verbosity=1 %run %t/a.out 2>&1 \ -// RUN: | FileCheck %s; \ -// RUN: fi +// RUN: %if mac-os-10-10-or-lower %{ %env_asan_opts=verbosity=1 %run %t/a.out 2>&1 | FileCheck %s %} #include <stdio.h> diff --git a/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp b/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp index 0672e06..872848d 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp @@ -5,29 +5,27 @@ // UNSUPPORTED: ios // RUN: rm -rf %t && mkdir -p %t -// RUN: cp `%clang_asan -print-file-name=lib`/darwin/libclang_rt.asan_osx_dynamic.dylib \ +// RUN: %clang_asan -print-file-name=lib | tr -d '\n' > %t.lib_name +// RUN: cp %{readfile:%t.lib_name}/darwin/libclang_rt.asan_osx_dynamic.dylib \ // RUN: %t/libclang_rt.asan_osx_dynamic.dylib // RUN: %clangxx_asan %s -o %t/a.out // RUN: %clangxx -DSHARED_LIB %s \ // RUN: -dynamiclib -o %t/dummy-so.dylib -// RUN: ( cd %t && \ -// RUN: DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ -// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1 +// RUN: cd %t +// RUN: env DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ +// RUN: %run ./a.out 2>&1 | FileCheck %s -// RUN: ( cd %t && \ -// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ -// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1 +// RUN: env DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ +// RUN: %run ./a.out 2>&1 | FileCheck %s -// RUN: ( cd %t && \ -// RUN: %env_asan_opts=strip_env=0 \ -// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ -// RUN: %run ./a.out 2>&1 ) | FileCheck %s --check-prefix=CHECK-KEEP || exit 1 +// RUN: %env_asan_opts=strip_env=0 \ +// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ +// RUN: %run ./a.out 2>&1 | FileCheck %s --check-prefix=CHECK-KEEP -// RUN: ( cd %t && \ -// RUN: DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ -// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1 +// RUN: env DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \ +// RUN: %run ./a.out 2>&1 | FileCheck %s #if !defined(SHARED_LIB) #include <stdio.h> diff --git a/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp b/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp index 3bf8e99..9bb652c 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp @@ -5,7 +5,7 @@ // - By default the lit config sets this but we don't want this // test to implicitly depend on this. // - It avoids requiring `--crash` to be passed to `not`. -// RUN: APPLE_ASAN_INIT_FOR_DLOPEN=0 %env_asan_opts=abort_on_error=0 not \ +// RUN: %env_asan_opts=abort_on_error=0 APPLE_ASAN_INIT_FOR_DLOPEN=0 not \ // RUN: %run %t %shared_libasan 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s // RUN: env -u APPLE_ASAN_INIT_FOR_DLOPEN %env_asan_opts=abort_on_error=0 not \ diff --git a/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.cpp b/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.cpp index 59dca32..ddf9388 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.cpp @@ -9,13 +9,17 @@ // RUN: %clangxx_asan -dead_strip -O2 %s -o %t.exe // // note: we can not use -D on Darwin. -// RUN: nm -g `%clang_asan %s -fsanitize=address -### 2>&1 | grep "libclang_rt.asan_osx_dynamic.dylib" | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \ -// RUN: | grep " [TU] " \ -// RUN: | grep -o "\(__asan_\|__ubsan_\|__sancov_\|__sanitizer_\)[^ ]*" \ -// RUN: | grep -v "__sanitizer_syscall" \ -// RUN: | grep -v "__sanitizer_weak_hook" \ -// RUN: | grep -v "__sanitizer_mz" \ -// RUN: | grep -v "__sancov_lowest_stack" \ +// RUN: %clang_asan %s -fsanitize=address -### 2>&1 \ +// RUN: | grep "libclang_rt.asan_osx_dynamic.dylib" \ +// RUN: | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/' \ +// RUN: | tr -d '\n' > %t.compiler_runtime_path +// RUN: nm -g %{readfile:%t.compiler_runtime_path} \ +// RUN: | grep " [TU] " \ +// RUN: | grep -o "\(__asan_\|__ubsan_\|__sancov_\|__sanitizer_\)[^ ]*" \ +// RUN: | grep -v "__sanitizer_syscall" \ +// RUN: | grep -v "__sanitizer_weak_hook" \ +// RUN: | grep -v "__sanitizer_mz" \ +// RUN: | grep -v "__sancov_lowest_stack" \ // RUN: | sed -e "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \ // RUN: > %t.exports // diff --git a/compiler-rt/test/asan/TestCases/Darwin/lit.local.cfg.py b/compiler-rt/test/asan/TestCases/Darwin/lit.local.cfg.py index af82d30..fc99cd7 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/lit.local.cfg.py +++ b/compiler-rt/test/asan/TestCases/Darwin/lit.local.cfg.py @@ -1,3 +1,6 @@ +import subprocess + + def getRoot(config): if not config.parent: return config @@ -8,3 +11,26 @@ root = getRoot(config) if root.target_os not in ["Darwin"]: config.unsupported = True + + +def get_product_version(): + try: + version_process = subprocess.run( + ["sw_vers", "-productVersion"], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + version_string = version_process.stdout.decode("utf-8").split("\n")[0] + version_split = version_string.split(".") + return (int(version_split[0]), int(version_split[1])) + except: + return (0, 0) + + +macos_version_major, macos_version_minor = get_product_version() +if config.apple_platform == "osx": + if macos_version_major > 10 and macos_version_minor > 11: + config.available_features.add("mac-os-10-11-or-higher") + else: + config.available_features.add("mac-os-10-10-or-lower") diff --git a/compiler-rt/test/asan/TestCases/Darwin/malloc_zone-protected.cpp b/compiler-rt/test/asan/TestCases/Darwin/malloc_zone-protected.cpp index 125b544..ac3c589 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/malloc_zone-protected.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/malloc_zone-protected.cpp @@ -3,8 +3,7 @@ #include <stdio.h> // RUN: %clangxx_asan %s -o %t -// RUN: ASAN_OPTIONS="abort_on_error=1" not --crash %run %t 2>&1 | FileCheck %s - +// RUN: env ASAN_OPTIONS="abort_on_error=1" not --crash %run %t 2>&1 | FileCheck %s void *pwn(malloc_zone_t *unused_zone, size_t unused_size) { printf("PWNED\n"); diff --git a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp index f60a6a4..c51e11f 100644 --- a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp @@ -7,25 +7,37 @@ // Limit this test to Linux since we're relying on allocator internal // limits (shadow memory size, allocation limits etc.) +// TODO(boomanaiden154): Switch back to using env options instead of explicitly +// exporting when the underlying bug causing ulimits to not apply to run lines +// that use env options is fixed. + // RUN: %clangxx_asan -O0 %s -o %t // RUN: ulimit -v 22024290304 // RUN: not %run %t malloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-MALLOC,CHECK-CRASH -// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=0 +// RUN: not %run %t malloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-MALLOC,CHECK-CRASH -// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t malloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=1 +// RUN: %run %t malloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-MALLOC,CHECK-NULL -// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t calloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=0 +// RUN: not %run %t calloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-CALLOC,CHECK-CRASH -// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t calloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=1 +// RUN: %run %t calloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-CALLOC,CHECK-NULL -// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t realloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=0 +// RUN: not %run %t realloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-REALLOC,CHECK-CRASH -// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t realloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=1 +// RUN: %run %t realloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-REALLOC,CHECK-NULL -// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t realloc-after-malloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=0 +// RUN: not %run %t realloc-after-malloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-MALLOC-REALLOC,CHECK-CRASH -// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t realloc-after-malloc 2>&1 \ +// RUN: %export_asan_opts=allocator_may_return_null=1 +// RUN: %run %t realloc-after-malloc 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-MALLOC-REALLOC,CHECK-NULL // ASan shadow memory on s390 is too large for this test. diff --git a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp index 1342eae..c4e519f 100644 --- a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp @@ -1,5 +1,9 @@ // Check that UAR mode can handle very deep recursion. // REQUIRES: shell +// TODO(boomanaiden154): This test currently fails with the internal +// shell because python is not able to set RLIMIT_STACK. We should +// reenable this when the behavior is fixed. +// UNSUPPORTED: system-darwin // RUN: %clangxx_asan -O2 %s -o %t // RUN: ulimit -s 4096 // RUN: %env_asan_opts=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s diff --git a/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.cpp b/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.cpp new file mode 100644 index 0000000..9e1e428 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.cpp @@ -0,0 +1,51 @@ +// Test crash gives guidance on -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ and +// ASAN_OPTIONS=detect_container_overflow=0 +// RUN: %clangxx_asan -O %s -o %t +// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s +// +// Test overflow checks can be disabled at runtime with +// ASAN_OPTIONS=detect_container_overflow=0 +// RUN: %env_asan_opts=detect_container_overflow=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-NOCRASH %s +// +// Illustrate use of -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ flag to suppress +// overflow checks at compile time. +// RUN: %clangxx_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ -O %s -o %t-no-overflow +// RUN: %run %t-no-overflow 2>&1 | FileCheck --check-prefix=CHECK-NOCRASH %s +// +// UNSUPPORTED: true + +#include <assert.h> +#include <stdio.h> +#include <string.h> + +// public definition of __sanitizer_annotate_contiguous_container +#include "sanitizer/common_interface_defs.h" + +static volatile int one = 1; + +int TestCrash() { + long t[100]; + t[60] = 0; +#if __has_feature(address_sanitizer) + __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100, + &t[0] + 50); +#endif + // CHECK-CRASH: AddressSanitizer: container-overflow + // CHECK-CRASH: ASAN_OPTIONS=detect_container_overflow=0 + // CHECK-CRASH: __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ + // CHECK-NOCRASH-NOT: AddressSanitizer: container-overflow + // CHECK-NOCRASH-NOT: ASAN_OPTIONS=detect_container_overflow=0 + // CHECK-NOCRASH-NOT: __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ + return (int)t[60 * one]; // Touches the poisoned memory. +} + +int main(int argc, char **argv) { + + int retval = 0; + + retval = TestCrash(); + + printf("Exiting main\n"); + + return retval; +} diff --git a/compiler-rt/test/asan/TestCases/log-path_test.cpp b/compiler-rt/test/asan/TestCases/log-path_test.cpp index 6875d57..22f077f 100644 --- a/compiler-rt/test/asan/TestCases/log-path_test.cpp +++ b/compiler-rt/test/asan/TestCases/log-path_test.cpp @@ -1,6 +1,5 @@ // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 -// XFAIL: android -// UNSUPPORTED: ios +// UNSUPPORTED: ios, android // // The for loop in the backticks below requires bash. // REQUIRES: shell diff --git a/compiler-rt/test/asan/TestCases/scariness_score_test.cpp b/compiler-rt/test/asan/TestCases/scariness_score_test.cpp index 5d229cf..51ae040 100644 --- a/compiler-rt/test/asan/TestCases/scariness_score_test.cpp +++ b/compiler-rt/test/asan/TestCases/scariness_score_test.cpp @@ -74,6 +74,10 @@ // Parts of the test are too platform-specific: // REQUIRES: x86_64-target-arch // REQUIRES: shell +// TODO(boomanaiden154): This test currently fails with the internal +// shell because python is not able to set RLIMIT_STACK. We should +// reenable this when the behavior is fixed. +// UNSUPPORTED: system-darwin #include <stdlib.h> #include <stdio.h> #include <string.h> diff --git a/compiler-rt/test/asan/TestCases/stack_container_dynamic_lib.cpp b/compiler-rt/test/asan/TestCases/stack_container_dynamic_lib.cpp new file mode 100644 index 0000000..e14d946 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/stack_container_dynamic_lib.cpp @@ -0,0 +1,120 @@ +// Test to demonstrate compile-time disabling of container-overflow checks +// in order to handle uninstrumented libraries +// UNSUPPORTED: target={{.*windows-.*}} + +// Mimic a closed-source library compiled without ASan +// RUN: %clangxx_asan -fno-sanitize=address -DSHARED_LIB %s %fPIC -shared -o %t-so.so + +// Mimic multiple files being linked into a single executable, +// %t-object.o and %t-main compiled seperately and then linked together +// RUN: %clangxx_asan -DMULTI_SOURCE %s -c -o %t-object.o +// RUN: %clangxx_asan %s -c -o %t-main.o +// RUN: %clangxx_asan -o %t %t-main.o %t-object.o %libdl +// RUN: not %run %t 2>&1 | FileCheck %s + +// Disable container overflow checks at runtime using ASAN_OPTIONS=detect_container_overflow=0 +// RUN: %env_asan_opts=detect_container_overflow=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-NO-CONTAINER-OVERFLOW %s + +// RUN: %clangxx_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ -DMULTI_SOURCE %s -c -o %t-object.o +// RUN: %clangxx_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ %s -c -o %t-main.o +// RUN: %clangxx_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ -o %t %t-main.o %t-object.o %libdl +// RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-NO-CONTAINER-OVERFLOW %s +// +// UNSUPPORTED: true + +#include <assert.h> +#include <sanitizer/common_interface_defs.h> +#include <stdio.h> + +template <typename T> class Stack { +private: + T data[5]; + size_t size; + +public: + Stack() : size(0) { +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ + // Mark entire storage as unaddressable initially + __sanitizer_annotate_contiguous_container(data, data + 5, data + 5, data); +#endif + } + + ~Stack() { +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ + __sanitizer_annotate_contiguous_container(data, data + 5, data + size, + data + 5); +#endif + } + + void push(const T &value) { + assert(size < 5 && "Stack overflow"); +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ + __sanitizer_annotate_contiguous_container(data, data + 5, data + size, + data + size + 1); +#endif + data[size++] = value; + } + + T pop() { + assert(size > 0 && "Cannot pop from empty stack"); + T result = data[--size]; +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ + __sanitizer_annotate_contiguous_container(data, data + 5, data + size + 1, + data + size); +#endif + return result; + } +}; + +#ifdef SHARED_LIB +// Mimics a closed-source library compiled without ASan + +extern "C" void push_value_to_stack(Stack<int> &stack) { stack.push(42); } +#else // SHARED_LIB + +# include <dlfcn.h> +# include <string> + +typedef void (*push_func_t)(Stack<int> &); + +# if defined(MULTI_SOURCE) +extern push_func_t push_value; + +extern "C" void do_push_value_to_stack(Stack<int> &stack) { + assert(push_value); + push_value(stack); +} + +# else +push_func_t push_value = nullptr; + +extern "C" void do_push_value_to_stack(Stack<int> &stack); + +int main(int argc, char *argv[]) { + std::string path = std::string(argv[0]) + "-so.so"; + printf("Loading library: %s\n", path.c_str()); + + void *lib = dlopen(path.c_str(), RTLD_NOW); + assert(lib); + + push_value = (push_func_t)dlsym(lib, "push_value_to_stack"); + assert(push_value); + + Stack<int> stack; + do_push_value_to_stack(stack); + + // BOOM! uninstrumented library didn't update container bounds + int value = stack.pop(); + // CHECK: AddressSanitizer: container-overflow + printf("Popped value: %d\n", value); + assert(value == 42 && "Expected value 42"); + + dlclose(lib); + printf("SUCCESS\n"); + // CHECK-NO-CONTAINER-OVERFLOW: SUCCESS + return 0; +} + +# endif // MULTI_SOURCE + +#endif // SHARED_LIB diff --git a/compiler-rt/test/asan/TestCases/suppress_fake_stack.cpp b/compiler-rt/test/asan/TestCases/suppress_fake_stack.cpp new file mode 100644 index 0000000..f072c6a --- /dev/null +++ b/compiler-rt/test/asan/TestCases/suppress_fake_stack.cpp @@ -0,0 +1,39 @@ +// RUN: %clangxx_asan %s -o %t && env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t +// RUN: %clangxx_asan %s -mllvm -asan-use-after-return=runtime -o %t && env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t +// RUN: %clangxx_asan %s -mllvm -asan-use-after-return=always -o %t && %run %t + +#include "defines.h" + +#include <cassert> +#include <sanitizer/asan_interface.h> + +volatile uintptr_t saved; + +ATTRIBUTE_NOINLINE bool IsOnRealStack(uintptr_t parent_frame, + uintptr_t var_addr) { + uintptr_t this_frame = + reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); + return this_frame <= var_addr && var_addr <= parent_frame; +} + +ATTRIBUTE_NOINLINE bool IsOnRealStack(uintptr_t parent_frame) { + volatile char temp = ' '; + saved = reinterpret_cast<uintptr_t>(&temp); + return IsOnRealStack(parent_frame, saved); +} + +ATTRIBUTE_NOINLINE bool IsOnRealStack() { + return IsOnRealStack(reinterpret_cast<uintptr_t>(__builtin_frame_address(0))); +} + +int main(int argc, char *argv[]) { + assert(!IsOnRealStack()); + + __asan_suppress_fake_stack(); + assert(IsOnRealStack()); + + __asan_unsuppress_fake_stack(); + assert(!IsOnRealStack()); + + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/suppress_fake_stack_force_disabled.cpp b/compiler-rt/test/asan/TestCases/suppress_fake_stack_force_disabled.cpp new file mode 100644 index 0000000..c549f08 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/suppress_fake_stack_force_disabled.cpp @@ -0,0 +1,40 @@ +// Check unsuppressing fake stack does not reenable it if disabled via compile or runtime options. +// +// RUN: %clangxx_asan %s -mllvm -asan-use-after-return=never -o %t && %run %t +// RUN: %clangxx_asan %s -mllvm -asan-use-after-return=runtime -o %t && env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t + +#include "defines.h" + +#include <cassert> +#include <sanitizer/asan_interface.h> + +volatile uintptr_t saved; + +ATTRIBUTE_NOINLINE bool IsOnRealStack(uintptr_t parent_frame, + uintptr_t var_addr) { + uintptr_t this_frame = + reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); + return this_frame <= var_addr && var_addr <= parent_frame; +} + +ATTRIBUTE_NOINLINE bool IsOnRealStack(uintptr_t parent_frame) { + volatile char temp = ' '; + saved = reinterpret_cast<uintptr_t>(&temp); + return IsOnRealStack(parent_frame, saved); +} + +ATTRIBUTE_NOINLINE bool IsOnRealStack() { + return IsOnRealStack(reinterpret_cast<uintptr_t>(__builtin_frame_address(0))); +} + +int main(int argc, char *argv[]) { + assert(IsOnRealStack()); + + __asan_suppress_fake_stack(); + assert(IsOnRealStack()); + + __asan_unsuppress_fake_stack(); + assert(IsOnRealStack()); + + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp b/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp index 53166cc..f4781a7 100644 --- a/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp +++ b/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp @@ -9,8 +9,8 @@ // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t-dir/asan.log.verbose-log-path_test-binary.* // FIXME: only FreeBSD, NetBSD and Linux have verbose log paths now. -// XFAIL: target={{.*windows-msvc.*}},android -// UNSUPPORTED: ios +// XFAIL: target={{.*windows-msvc.*}} +// UNSUPPORTED: ios, android #include <stdlib.h> #include <string.h> |
