[compiler-rt] r241876 - [TSan] Fix dl_iterate_phdr callback for the case when info->dlpi_name is overwritten by user.

Alexey Samsonov vonosmas at gmail.com
Thu Jul 9 17:03:55 PDT 2015


Author: samsonov
Date: Thu Jul  9 19:03:54 2015
New Revision: 241876

URL: http://llvm.org/viewvc/llvm-project?rev=241876&view=rev
Log:
[TSan] Fix dl_iterate_phdr callback for the case when info->dlpi_name is overwritten by user.

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/test/tsan/dl_iterate_phdr.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=241876&r1=241875&r2=241876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Jul  9 19:03:54 2015
@@ -2153,6 +2153,10 @@ struct dl_iterate_phdr_data {
   void *data;
 };
 
+static bool IsAppNotRodata(uptr addr) {
+  return IsAppMem(addr) && *(u64*)MemToShadow(addr) != kShadowRodata;
+}
+
 static int dl_iterate_phdr_cb(__sanitizer_dl_phdr_info *info, SIZE_T size,
                               void *data) {
   dl_iterate_phdr_data *cbdata = (dl_iterate_phdr_data *)data;
@@ -2161,13 +2165,13 @@ static int dl_iterate_phdr_cb(__sanitize
   // inside of dynamic linker, so we "unpoison" it here in order to not
   // produce false reports. Ignoring malloc/free in dlopen/dlclose is not enough
   // because some libc functions call __libc_dlopen.
-  bool reset = info && IsAppMem((uptr)info->dlpi_name) &&
-      *(u64*)MemToShadow((uptr)info->dlpi_name) != kShadowRodata;
-  if (reset)
+  if (info && IsAppNotRodata((uptr)info->dlpi_name))
     MemoryResetRange(cbdata->thr, cbdata->pc, (uptr)info->dlpi_name,
                      internal_strlen(info->dlpi_name));
   int res = cbdata->cb(info, size, cbdata->data);
-  if (reset)
+  // Perform the check one more time in case info->dlpi_name was overwritten
+  // by user callback.
+  if (info && IsAppNotRodata((uptr)info->dlpi_name))
     MemoryResetRange(cbdata->thr, cbdata->pc, (uptr)info->dlpi_name,
                      internal_strlen(info->dlpi_name));
   return res;

Modified: compiler-rt/trunk/test/tsan/dl_iterate_phdr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/dl_iterate_phdr.cc?rev=241876&r1=241875&r2=241876&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/dl_iterate_phdr.cc (original)
+++ compiler-rt/trunk/test/tsan/dl_iterate_phdr.cc Thu Jul  9 19:03:54 2015
@@ -18,6 +18,8 @@ int exported_var = 0;
 #include <string>
 
 static int callback(struct dl_phdr_info *info, size_t size, void *data) {
+  if (info->dlpi_name[0] == '\0')
+    info->dlpi_name = "/proc/self/exe";
   return !strcmp(info->dlpi_name, "non existent module");
 }
 





More information about the llvm-commits mailing list