diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-03-26 12:14:34 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-03-26 12:14:34 +0000 |
commit | 16d89fc356ef70e836a7863ccbf4e29ff2b7724c (patch) | |
tree | 93df90ff3e7129a1e7b9e5a86e3e7c207a71e5c1 | |
parent | 9068dfa6a73b544f0b43ef49419520e907f8638c (diff) | |
download | bcm5719-llvm-16d89fc356ef70e836a7863ccbf4e29ff2b7724c.tar.gz bcm5719-llvm-16d89fc356ef70e836a7863ccbf4e29ff2b7724c.zip |
[sanitizer] Intercept __aeabi_mem(set|cpy|move).
llvm-svn: 204800
3 files changed, 123 insertions, 1 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index f962291454d..88328620920 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -3411,6 +3411,65 @@ INTERCEPTOR(int, capset, void *hdrp, const void *datap) { #define INIT_CAPGET #endif +#if SANITIZER_INTERCEPT_AEABI_MEM +DECLARE_REAL_AND_INTERCEPTOR(void *, memmove, void *, const void *, uptr); +DECLARE_REAL_AND_INTERCEPTOR(void *, memcpy, void *, const void *, uptr); +DECLARE_REAL_AND_INTERCEPTOR(void *, memset, void *, int, uptr); + +INTERCEPTOR(void *, __aeabi_memmove, void *to, const void *from, uptr size) { + return WRAP(memmove)(to, from, size); +} +INTERCEPTOR(void *, __aeabi_memmove4, void *to, const void *from, uptr size) { + return WRAP(memmove)(to, from, size); +} +INTERCEPTOR(void *, __aeabi_memmove8, void *to, const void *from, uptr size) { + return WRAP(memmove)(to, from, size); +} +INTERCEPTOR(void *, __aeabi_memcpy, void *to, const void *from, uptr size) { + return WRAP(memcpy)(to, from, size); +} +INTERCEPTOR(void *, __aeabi_memcpy4, void *to, const void *from, uptr size) { + return WRAP(memcpy)(to, from, size); +} +INTERCEPTOR(void *, __aeabi_memcpy8, void *to, const void *from, uptr size) { + return WRAP(memcpy)(to, from, size); +} +// Note the argument order. +INTERCEPTOR(void *, __aeabi_memset, void *block, uptr size, int c) { + return WRAP(memset)(block, c, size); +} +INTERCEPTOR(void *, __aeabi_memset4, void *block, uptr size, int c) { + return WRAP(memset)(block, c, size); +} +INTERCEPTOR(void *, __aeabi_memset8, void *block, uptr size, int c) { + return WRAP(memset)(block, c, size); +} +INTERCEPTOR(void *, __aeabi_memclr, void *block, uptr size) { + return WRAP(memset)(block, 0, size); +} +INTERCEPTOR(void *, __aeabi_memclr4, void *block, uptr size) { + return WRAP(memset)(block, 0, size); +} +INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) { + return WRAP(memset)(block, 0, size); +} +#define INIT_AEABI_MEM \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memmove); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memmove4); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memmove8); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memcpy); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memcpy4); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memcpy8); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memset); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memset4); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memset8); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memclr); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memclr4); \ + COMMON_INTERCEPT_FUNCTION(__aeabi_memclr8); +#else +#define INIT_AEABI_MEM +#endif // SANITIZER_INTERCEPT_AEABI_MEM + #define SANITIZER_COMMON_INTERCEPTORS_INIT \ INIT_TEXTDOMAIN; \ INIT_STRCMP; \ @@ -3532,5 +3591,6 @@ INTERCEPTOR(int, capset, void *hdrp, const void *datap) { INIT_GETRESID; \ INIT_GETIFADDRS; \ INIT_IF_INDEXTONAME; \ - INIT_CAPGET; + INIT_CAPGET; \ + INIT_AEABI_MEM; /**/ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 20ec85e18a3..3e9ec10450f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -187,5 +187,6 @@ #define SANITIZER_INTERCEPT_GETIFADDRS SI_LINUX_NOT_ANDROID || SI_MAC #define SANITIZER_INTERCEPT_IF_INDEXTONAME SI_LINUX_NOT_ANDROID || SI_MAC #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID +#define SANITIZER_INTERCEPT_AEABI_MEM SI_LINUX && defined(__arm__) #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H diff --git a/compiler-rt/test/asan/TestCases/memset_test.cc b/compiler-rt/test/asan/TestCases/memset_test.cc new file mode 100644 index 00000000000..37898e14306 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/memset_test.cc @@ -0,0 +1,61 @@ +// Test that large memset/memcpy/memmove check the entire range. + +// RUN: %clangxx_asan -O0 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMSET +// RUN: %clangxx_asan -O1 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMSET +// RUN: %clangxx_asan -O2 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMSET +// RUN: %clangxx_asan -O3 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMSET + +// RUN: %clangxx_asan -O0 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY +// RUN: %clangxx_asan -O1 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY +// RUN: %clangxx_asan -O2 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY +// RUN: %clangxx_asan -O3 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY + +// RUN: %clangxx_asan -O0 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE +// RUN: %clangxx_asan -O1 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE +// RUN: %clangxx_asan -O2 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE +// RUN: %clangxx_asan -O3 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE + +#include <assert.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include <sanitizer/asan_interface.h> + +int main(int argc, char **argv) { + char * volatile p = (char *)malloc(3000); + __asan_poison_memory_region(p + 512, 16); +#if defined(TEST_MEMSET) + memset(p, 0, 3000); + assert(p[1] == 0); + // CHECK-MEMSET: AddressSanitizer: use-after-poison on address + // CHECK-MEMSET: in {{.*}}memset +#else + char * volatile q = (char *)malloc(3000); +#if defined(TEST_MEMCPY) + memcpy(q, p, 3000); + // CHECK-MEMCPY: AddressSanitizer: use-after-poison on address + // CHECK-MEMCPY: in {{.*}}memcpy +#elif defined(TEST_MEMMOVE) + memmove(q, p, 3000); + // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address + // CHECK-MEMMOVE: in {{.*}}memmove +#endif + assert(q[1] == 0); + free(q); +#endif + free(p); + return 0; +} |