[PATCH] D63877: Avoid infinite loop with asan interception

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 14:28:26 PDT 2019


serge-sans-paille updated this revision to Diff 206938.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63877/new/

https://reviews.llvm.org/D63877

Files:
  compiler-rt/lib/interception/interception_linux.cc


Index: compiler-rt/lib/interception/interception_linux.cc
===================================================================
--- compiler-rt/lib/interception/interception_linux.cc
+++ compiler-rt/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.206938.patch
Type: text/x-patch
Size: 1146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190627/b7d93940/attachment.bin>


More information about the llvm-commits mailing list