[PATCH] D63877: Avoid infinite loop with asan interception
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 01:09:22 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366413: Fix asan infinite loop on undefined symbol (authored by serge_sans_paille, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D63877?vs=210050&id=210499#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63877/new/
https://reviews.llvm.org/D63877
Files:
compiler-rt/trunk/lib/interception/interception_linux.cc
compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
Index: compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
===================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
+++ compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
@@ -0,0 +1,42 @@
+// RUN: %clangxx_asan -xc++ -shared -fPIC -o %t.so - < %s
+// RUN: %clang_asan %s -o %t.out -ldl
+// RUN: ASAN_OPTIONS=verbosity=1 not %t.out %t.so 2>&1 | FileCheck %s
+//
+// CHECK: AddressSanitizer: failed to intercept '__cxa_throw'
+//
+// dlopen() can not be intercepted on Android
+// UNSUPPORTED: android
+#ifdef __cplusplus
+
+static void foo(void) {
+ int i = 0;
+ throw(i);
+}
+
+extern "C" {
+int bar(void);
+};
+int bar(void) {
+ try {
+ foo();
+ } catch (int i) {
+ return i;
+ }
+ return -1;
+}
+
+#else
+
+#include <assert.h>
+#include <dlfcn.h>
+
+int main(int argc, char **argv) {
+ int (*bar)(void);
+ void *handle = dlopen(argv[1], RTLD_LAZY);
+ assert(handle);
+ bar = dlsym(handle, "bar");
+ assert(bar);
+ return bar();
+}
+
+#endif
Index: compiler-rt/trunk/lib/interception/interception_linux.cc
===================================================================
--- compiler-rt/trunk/lib/interception/interception_linux.cc
+++ compiler-rt/trunk/lib/interception/interception_linux.cc
@@ -33,7 +33,7 @@
}
#endif
-static void *GetFuncAddr(const char *name) {
+static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
#if SANITIZER_NETBSD
// FIXME: Find a better way to handle renames
if (StrCmp(name, "sigaction"))
@@ -47,13 +47,18 @@
// want the address of the real definition, though, so look it up using
// RTLD_DEFAULT.
addr = dlsym(RTLD_DEFAULT, name);
+
+ // In case `name' is not loaded, dlsym ends up finding the actual wrapper.
+ // We don't want to intercept the wrapper and have it point to itself.
+ if ((uptr)addr == wrapper_addr)
+ addr = nullptr;
}
return addr;
}
bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
uptr wrapper) {
- void *addr = GetFuncAddr(name);
+ void *addr = GetFuncAddr(name, wrapper);
*ptr_to_real = (uptr)addr;
return addr && (func == wrapper);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63877.210499.patch
Type: text/x-patch
Size: 2232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190718/5526cbef/attachment-0001.bin>
More information about the llvm-commits
mailing list