[PATCH] [compiler-rt] Abort after failed exec() and get rid of the allow_reexec ASan flag

Kuba Brecka kuba.brecka at gmail.com
Sun Dec 21 15:39:08 PST 2014


As mentioned in https://code.google.com/p/address-sanitizer/issues/detail?id=365, when the re-exec that adds the required DYLD_INSERT_LIBRARIES variable fails, ASan currently continues to run, but things are broken (some memory can be overwritten, interceptors don't work, ...). This patch aborts if the execv() fails and prints an error message that DYLD_INSERT_LIBRARIES is required. It also removes the "alllow_reexec" flag, since using it causes the same issues.

http://reviews.llvm.org/D6752

Files:
  lib/asan/asan_flags.cc
  lib/asan/asan_flags.h
  lib/asan/asan_mac.cc
  lib/asan/tests/asan_noinst_test.cc

Index: lib/asan/asan_flags.cc
===================================================================
--- lib/asan/asan_flags.cc
+++ lib/asan/asan_flags.cc
@@ -113,10 +113,6 @@
       "If set, prints ASan exit stats even after program terminates "
       "successfully.");
 
-  ParseFlag(str, &f->allow_reexec, "allow_reexec",
-      "Allow the tool to re-exec the program. This may interfere badly with "
-      "the debugger.");
-
   ParseFlag(str, &f->print_full_thread_history,
       "print_full_thread_history",
       "If set, prints thread creation stacks for the threads involved in the "
@@ -209,7 +205,6 @@
   f->print_stats = false;
   f->print_legend = true;
   f->atexit = false;
-  f->allow_reexec = true;
   f->print_full_thread_history = true;
   f->poison_heap = true;
   f->poison_array_cookie = true;
Index: lib/asan/asan_flags.h
===================================================================
--- lib/asan/asan_flags.h
+++ lib/asan/asan_flags.h
@@ -52,7 +52,6 @@
   bool print_stats;
   bool print_legend;
   bool atexit;
-  bool allow_reexec;
   bool print_full_thread_history;
   bool poison_heap;
   bool poison_partial;
Index: lib/asan/asan_mac.cc
===================================================================
--- lib/asan/asan_mac.cc
+++ lib/asan/asan_mac.cc
@@ -102,7 +102,6 @@
 }
 
 void MaybeReexec() {
-  if (!flags()->allow_reexec) return;
   // Make sure the dynamic ASan runtime library is preloaded so that the
   // wrappers work. If it is not, set DYLD_INSERT_LIBRARIES and re-exec
   // ourselves.
@@ -140,8 +139,15 @@
     VReport(1, "exec()-ing the program with\n");
     VReport(1, "%s=%s\n", kDyldInsertLibraries, new_env);
     VReport(1, "to enable ASan wrappers.\n");
-    VReport(1, "Set ASAN_OPTIONS=allow_reexec=0 to disable this.\n");
     execv(program_name, *_NSGetArgv());
+
+    // We get here only if execv() failed.
+    Report("ERROR: The process is launched without DYLD_INSERT_LIBRARIES, "
+           "which is required for ASan to work. ASan tried to set the "
+           "environment variable and re-execute itself, but execv() failed, "
+           "possibly because of sandbox restrictions. Make sure to launch the "
+           "executable with:\n%s=%s\n", kDyldInsertLibraries, new_env);
+    CHECK("execv failed" && 0);
   } else {
     // DYLD_INSERT_LIBRARIES is set and contains the runtime library.
     if (old_env_len == fname_len) {
Index: lib/asan/tests/asan_noinst_test.cc
===================================================================
--- lib/asan/tests/asan_noinst_test.cc
+++ lib/asan/tests/asan_noinst_test.cc
@@ -31,15 +31,6 @@
 // in this test. The static runtime library is linked explicitly (without
 // -fsanitize=address), thus the interceptors do not work correctly on OS X.
 
-#if !defined(_WIN32)
-extern "C" {
-// Set specific ASan options for uninstrumented unittest.
-const char* __asan_default_options() {
-  return "allow_reexec=0";
-}
-}  // extern "C"
-#endif
-
 // Make sure __asan_init is called before any test case is run.
 struct AsanInitCaller {
   AsanInitCaller() { __asan_init(); }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6752.17542.patch
Type: text/x-patch
Size: 3097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141221/fdfb16b4/attachment.bin>


More information about the llvm-commits mailing list