diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2019-02-21 21:32:24 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2019-02-21 21:32:24 +0000 |
commit | 806f4749b8116d9ad554e723779e3fcfa8761b74 (patch) | |
tree | dd2240d84e219209f04da6a3292145635eb689fb /lib/hwasan | |
parent | 2871f638091021c1aa8eba233ff107a23d5a5b43 (diff) | |
download | compiler-rt-806f4749b8116d9ad554e723779e3fcfa8761b74.tar.gz |
[hwasan,asan] Intercept vfork.
Summary: AArch64 only for now.
Reviewers: vitalybuka, pcc
Subscribers: srhines, kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, jdoerfert, #sanitizers, llvm-commits, kcc
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D58313
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354625 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan')
-rw-r--r-- | lib/hwasan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/hwasan/hwasan.cc | 24 | ||||
-rw-r--r-- | lib/hwasan/hwasan_interceptors.cc | 5 | ||||
-rw-r--r-- | lib/hwasan/hwasan_interceptors_vfork.S | 7 | ||||
-rw-r--r-- | lib/hwasan/hwasan_interface_internal.h | 6 | ||||
-rw-r--r-- | lib/hwasan/hwasan_thread.h | 3 |
6 files changed, 46 insertions, 0 deletions
diff --git a/lib/hwasan/CMakeLists.txt b/lib/hwasan/CMakeLists.txt index 7460abc54..d64564412 100644 --- a/lib/hwasan/CMakeLists.txt +++ b/lib/hwasan/CMakeLists.txt @@ -6,6 +6,7 @@ set(HWASAN_RTL_SOURCES hwasan_allocator.cc hwasan_dynamic_shadow.cc hwasan_interceptors.cc + hwasan_interceptors_vfork.S hwasan_linux.cc hwasan_memintrinsics.cc hwasan_poisoning.cc diff --git a/lib/hwasan/hwasan.cc b/lib/hwasan/hwasan.cc index 9c83f73bd..3a87dea26 100644 --- a/lib/hwasan/hwasan.cc +++ b/lib/hwasan/hwasan.cc @@ -477,6 +477,30 @@ void __hwasan_handle_longjmp(const void *sp_dst) { TagMemory(sp, dst - sp, 0); } +void __hwasan_handle_vfork(const void *sp_dst) { + uptr sp = (uptr)sp_dst; + Thread *t = GetCurrentThread(); + CHECK(t); + uptr top = t->stack_top(); + uptr bottom = t->stack_bottom(); + static const uptr kMaxExpectedCleanupSize = 64 << 20; // 64M + if (top == 0 || bottom == 0 || sp < bottom || sp >= top || + sp - bottom > kMaxExpectedCleanupSize) { + Report( + "WARNING: HWASan is ignoring requested __hwasan_handle_vfork: " + "stack top: %zx; current %zx; bottom: %zx \n" + "False positive error reports may follow\n", + top, sp, bottom); + return; + } + TagMemory(bottom, sp - bottom, 0); +} + +void *__hwasan_extra_spill_area() { + Thread *t = GetCurrentThread(); + return &t->vfork_spill(); +} + void __hwasan_print_memory_usage() { InternalScopedString s(kMemoryUsageBufferSize); HwasanFormatMemoryUsage(s); diff --git a/lib/hwasan/hwasan_interceptors.cc b/lib/hwasan/hwasan_interceptors.cc index baecb1e03..1884b3da3 100644 --- a/lib/hwasan/hwasan_interceptors.cc +++ b/lib/hwasan/hwasan_interceptors.cc @@ -227,6 +227,10 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr, } #endif +#if HWASAN_WITH_INTERCEPTORS +DEFINE_REAL(void, vfork); +#endif + static void BeforeFork() { StackDepotLockAll(); } @@ -266,6 +270,7 @@ void InitializeInterceptors() { INTERCEPT_FUNCTION(fork); #if HWASAN_WITH_INTERCEPTORS + __interception::GetRealFunctionAddress("vfork", (uptr *)&REAL(vfork), 0, 0); #if !defined(__aarch64__) INTERCEPT_FUNCTION(pthread_create); #endif diff --git a/lib/hwasan/hwasan_interceptors_vfork.S b/lib/hwasan/hwasan_interceptors_vfork.S new file mode 100644 index 000000000..54b4a78db --- /dev/null +++ b/lib/hwasan/hwasan_interceptors_vfork.S @@ -0,0 +1,7 @@ +#define COMMON_INTERCEPTOR_SPILL_AREA __hwasan_extra_spill_area +#define COMMON_INTERCEPTOR_HANDLE_VFORK __hwasan_handle_vfork +#include "sanitizer_common/sanitizer_common_interceptors_vfork_aarch64.inc.S" + +#if defined(__linux__) +.section .note.GNU-stack,"",@progbits +#endif diff --git a/lib/hwasan/hwasan_interface_internal.h b/lib/hwasan/hwasan_interface_internal.h index c2ae66653..1b025c923 100644 --- a/lib/hwasan/hwasan_interface_internal.h +++ b/lib/hwasan/hwasan_interface_internal.h @@ -117,6 +117,9 @@ SANITIZER_INTERFACE_ATTRIBUTE void __hwasan_handle_longjmp(const void *sp_dst); SANITIZER_INTERFACE_ATTRIBUTE +void __hwasan_handle_vfork(const void *sp_dst); + +SANITIZER_INTERFACE_ATTRIBUTE u16 __sanitizer_unaligned_load16(const uu16 *p); SANITIZER_INTERFACE_ATTRIBUTE @@ -200,6 +203,9 @@ SANITIZER_INTERFACE_ATTRIBUTE void *__hwasan_memset(void *s, int c, uptr n); SANITIZER_INTERFACE_ATTRIBUTE void *__hwasan_memmove(void *dest, const void *src, uptr n); + +SANITIZER_INTERFACE_ATTRIBUTE +void *__hwasan_extra_spill_area(); } // extern "C" #endif // HWASAN_INTERFACE_INTERNAL_H diff --git a/lib/hwasan/hwasan_thread.h b/lib/hwasan/hwasan_thread.h index 9c45adec1..6fa592bfa 100644 --- a/lib/hwasan/hwasan_thread.h +++ b/lib/hwasan/hwasan_thread.h @@ -67,11 +67,14 @@ class Thread { Print("Thread: "); } + uptr &vfork_spill() { return vfork_spill_; } + private: // NOTE: There is no Thread constructor. It is allocated // via mmap() and *must* be valid in zero-initialized state. void ClearShadowForThreadStackAndTLS(); void Print(const char *prefix); + uptr vfork_spill_; uptr stack_top_; uptr stack_bottom_; uptr tls_begin_; |