aboutsummaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-16 19:47:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-16 19:47:19 +0000
commitf9102cdabba485d415359124bece145f4a7d9089 (patch)
tree8eb48238e74ed80be2c4feea51adc53445040d76 /test/asan
parent2109e2e4181555140883e9ec46807746a0eabad2 (diff)
downloadsrc-f9102cdabba485d415359124bece145f4a7d9089.tar.gz
src-f9102cdabba485d415359124bece145f4a7d9089.zip
Vendor import of compiler-rt trunk r303197:vendor/compiler-rt/compiler-rt-trunk-r303197
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=318372 svn path=/vendor/compiler-rt/compiler-rt-trunk-r303197/; revision=318373; tag=vendor/compiler-rt/compiler-rt-trunk-r303197
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/CMakeLists.txt17
-rw-r--r--test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc30
-rw-r--r--test/asan/TestCases/Posix/strndup_oob_test.cc27
-rw-r--r--test/asan/lit.cfg9
4 files changed, 77 insertions, 6 deletions
diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt
index b8e365227780..87fa9d138748 100644
--- a/test/asan/CMakeLists.txt
+++ b/test/asan/CMakeLists.txt
@@ -3,9 +3,17 @@ set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ASAN_TESTSUITES)
set(ASAN_DYNAMIC_TESTSUITES)
-# FIXME: Shadow memory for 64-bit asan easily exhausts swap on most machines.
-# Find a way to make these tests pass reliably, and re-enable them.
-if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
+# Before Windows 8 (CMAKE_SYSTEM_VERSION 6.2), reserving large regions of shadow
+# memory allocated physical memory for page tables, which made it very
+# unreliable. Remove the asan tests from check-all in this configuration.
+set(SHADOW_MAPPING_UNRELIABLE FALSE)
+if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
+ ${CMAKE_SYSTEM_VERSION} LESS 6.2)
+ set(SHADOW_MAPPING_UNRELIABLE TRUE)
+ message(WARNING "Disabling ASan tests because they are unreliable on Windows 7 and earlier")
+endif()
+
+if (SHADOW_MAPPING_UNRELIABLE)
set(EXCLUDE_FROM_ALL TRUE)
endif()
@@ -165,7 +173,6 @@ if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
endif()
# Reset EXCLUDE_FROM_ALL to its initial value.
-# FIXME: Remove when we run Win64 asan tests.
-if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
+if (SHADOW_MAPPING_UNRELIABLE)
set(EXCLUDE_FROM_ALL FALSE)
endif()
diff --git a/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc b/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc
new file mode 100644
index 000000000000..a845721d5982
--- /dev/null
+++ b/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc
@@ -0,0 +1,30 @@
+// REQUIRES: x86_64-target-arch
+// RUN: %clangxx_asan %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+#include <sanitizer/common_interface_defs.h>
+#include <sched.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ __sanitizer_sandbox_arguments args = {0};
+ // should cache /proc/self/maps
+ __sanitizer_sandbox_on_notify(&args);
+
+ if (unshare(CLONE_NEWUSER)) {
+ printf("unshare failed\n");
+ abort();
+ }
+
+ // remove access to /proc/self/maps
+ if (chroot("/tmp")) {
+ printf("chroot failed\n");
+ abort();
+ }
+
+ *(volatile int*)0x42 = 0;
+// CHECK: AddressSanitizer: SEGV on unknown address 0x000000000042
+// CHECK-NOT: AddressSanitizer CHECK failed
+// CHECK: SUMMARY: AddressSanitizer: SEGV
+}
diff --git a/test/asan/TestCases/Posix/strndup_oob_test.cc b/test/asan/TestCases/Posix/strndup_oob_test.cc
new file mode 100644
index 000000000000..7ea0b7a33400
--- /dev/null
+++ b/test/asan/TestCases/Posix/strndup_oob_test.cc
@@ -0,0 +1,27 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// When built as C on Linux, strndup is transformed to __strndup.
+// RUN: %clangxx_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// Unwind problem on arm: "main" is missing from the allocation stack trace.
+// UNSUPPORTED: win32,s390,armv7l-unknown-linux-gnueabihf
+
+#include <string.h>
+
+char kString[] = "foo";
+
+int main(int argc, char **argv) {
+ char *copy = strndup(kString, 2);
+ int x = copy[2 + argc]; // BOOM
+ // CHECK: AddressSanitizer: heap-buffer-overflow
+ // CHECK: #0 {{.*}}main {{.*}}strndup_oob_test.cc:[[@LINE-2]]
+ // CHECK-LABEL: allocated by thread T{{.*}} here:
+ // CHECK: #{{[01]}} {{.*}}strndup
+ // CHECK: #{{.*}}main {{.*}}strndup_oob_test.cc:[[@LINE-6]]
+ // CHECK-LABEL: SUMMARY
+ // CHECK: strndup_oob_test.cc:[[@LINE-7]]
+ return x;
+}
diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg
index b433a91e830e..063c33b02697 100644
--- a/test/asan/lit.cfg
+++ b/test/asan/lit.cfg
@@ -38,6 +38,11 @@ if config.host_os == 'Darwin':
# Also, make sure we do not overwhelm the syslog while testing.
default_asan_opts = 'abort_on_error=0'
default_asan_opts += ':log_to_syslog=0'
+
+ # On Darwin, leak checking is not enabled by default. Enable for x86_64
+ # tests to prevent regressions
+ if config.target_arch == 'x86_64':
+ default_asan_opts += ':detect_leaks=1'
elif config.android:
# The same as on Darwin, we default to "abort_on_error=1" which slows down
# testing. Also, all existing tests are using "not" instead of "not --crash"
@@ -215,7 +220,9 @@ if re.search('mthumb', config.target_cflags) is not None:
config.available_features.add('fast-unwinder-works')
# Turn on leak detection on 64-bit Linux.
-if config.host_os == 'Linux' and (config.target_arch == 'x86_64' or config.target_arch == 'i386'):
+leak_detection_linux = (config.host_os == 'Linux') and (config.target_arch == 'x86_64' or config.target_arch == 'i386')
+leak_detection_mac = (config.host_os == 'Darwin') and (config.target_arch == 'x86_64')
+if leak_detection_linux or leak_detection_mac:
config.available_features.add('leak-detection')
# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.