[sanitizer] Intercept __aeabi_mem(set|cpy|move).

llvm-svn: 204800
This commit is contained in:
Evgeniy Stepanov 2014-03-26 12:14:34 +00:00
parent 9068dfa6a7
commit 16d89fc356
3 changed files with 123 additions and 1 deletions

View File

@ -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;
/**/

View File

@ -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

View File

@ -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;
}