diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp --- a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp +++ b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp @@ -223,6 +223,13 @@ #undef SIG_BLOCK #undef SIG_SETMASK +# if SANITIZER_LINUX && !SANITIZER_ANDROID +INTERCEPTOR(void *, dlopen, const char *filename, int flag) { + CheckNoDeepBind(filename, flag); + return REAL(dlopen)(filename, flag); +} +# endif + # endif // HWASAN_WITH_INTERCEPTORS namespace __hwasan { @@ -245,12 +252,15 @@ CHECK_EQ(inited, 0); #if HWASAN_WITH_INTERCEPTORS -#if defined(__linux__) +# if SANITIZER_LINUX INTERCEPT_FUNCTION(__libc_longjmp); INTERCEPT_FUNCTION(longjmp); INTERCEPT_FUNCTION(siglongjmp); INTERCEPT_FUNCTION(vfork); -#endif // __linux__ +# if !SANITIZER_ANDROID + INTERCEPT_FUNCTION(dlopen); +# endif +# endif INTERCEPT_FUNCTION(pthread_create); INTERCEPT_FUNCTION(pthread_join); # endif diff --git a/compiler-rt/test/hwasan/TestCases/Linux/deepbind.cpp b/compiler-rt/test/hwasan/TestCases/Linux/deepbind.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/hwasan/TestCases/Linux/deepbind.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_hwasan %s -o %t && %run not %t 2>&1 | FileCheck %s +// UNSUPPORTED: android + +#include + +int main(int argc, char *argv[]) { + // CHECK: You are trying to dlopen a shared library with RTLD_DEEPBIND flag + void *lib = dlopen("", RTLD_NOW | RTLD_DEEPBIND); + return 0; +}