summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>2019-07-18 17:47:42 +0300
committerDongkyun Son <dongkyun.s@samsung.com>2019-07-27 16:45:13 +0000
commit30255a5854a11a5e67c13b640d65a80411a34a39 (patch)
tree8126b63a10bfeac301968bd955723db4e6de85f0
parent89fa22d76eef9205fc845168e4a4ec5812bf2a47 (diff)
downloadlinaro-gcc-30255a5854a11a5e67c13b640d65a80411a34a39.tar.gz
linaro-gcc-30255a5854a11a5e67c13b640d65a80411a34a39.tar.bz2
linaro-gcc-30255a5854a11a5e67c13b640d65a80411a34a39.zip
libsanitizer: Make malloc/realloc/free safe via 'pointer_is_mine'
* libsanitizer/asan/asan_malloc_linux.cc: check pointers before calling forwarding. This change will lead to possible failures inside glibc in cases of free()'ing wild pointers. In usual case ASan should handle this case and provide appropriate backtrace and error report, but this mode is not compatible with interceptor switching functional, so we explicitly disabling it. Change-Id: I8fc40aad4d9e6094301f6b3f3060b99140a191da Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
-rw-r--r--libsanitizer/asan/asan_malloc_linux.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/libsanitizer/asan/asan_malloc_linux.cc b/libsanitizer/asan/asan_malloc_linux.cc
index babec774d0a..914c21a6adf 100644
--- a/libsanitizer/asan/asan_malloc_linux.cc
+++ b/libsanitizer/asan/asan_malloc_linux.cc
@@ -46,8 +46,10 @@ INTERCEPTOR(void, free, void *ptr) {
GET_STACK_TRACE_FREE;
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
return;
- if (UNLIKELY(!asan_pointer_is_mine(ptr)))
- MAYBE_FORWARD_TO_REAL(free, ptr);
+ if (UNLIKELY(!asan_pointer_is_mine(ptr))) {
+ REAL(free)(ptr);
+ return;
+ }
asan_free(ptr, &stack, FROM_MALLOC);
}
@@ -55,8 +57,10 @@ INTERCEPTOR(void, cfree, void *ptr) {
GET_STACK_TRACE_FREE;
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
return;
- if (UNLIKELY(!asan_pointer_is_mine(ptr)))
- MAYBE_FORWARD_TO_REAL(cfree, ptr);
+ if (UNLIKELY(!asan_pointer_is_mine(ptr))) {
+ REAL(cfree)(ptr);
+ return;
+ }
asan_free(ptr, &stack, FROM_MALLOC);
}
@@ -98,8 +102,9 @@ INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
if (UNLIKELY(asan_init_is_running))
return AllocateFromLocalPool(size);
ENSURE_ASAN_INITED();
- if (UNLIKELY(!asan_pointer_is_mine(ptr)))
- MAYBE_FORWARD_TO_REAL(realloc, ptr, size);
+ if (UNLIKELY(!asan_pointer_is_mine(ptr))) {
+ return REAL(realloc)(ptr, size);
+ }
GET_STACK_TRACE_MALLOC;
return asan_realloc(ptr, size, &stack);
}