forked from OSchip/llvm-project
AddressSanitizer: Abort after failed exec() and get rid of the allow_reexec ASan flag
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. Reviewed at http://reviews.llvm.org/D6752 llvm-svn: 224712
This commit is contained in:
parent
090d33e393
commit
742c471142
|
@ -113,10 +113,6 @@ void ParseFlagsFromString(Flags *f, const char *str) {
|
|||
"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 @@ void InitializeFlags(Flags *f) {
|
|||
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;
|
||||
|
|
|
@ -52,7 +52,6 @@ struct Flags {
|
|||
bool print_stats;
|
||||
bool print_legend;
|
||||
bool atexit;
|
||||
bool allow_reexec;
|
||||
bool print_full_thread_history;
|
||||
bool poison_heap;
|
||||
bool poison_partial;
|
||||
|
|
|
@ -102,7 +102,6 @@ void LeakyResetEnv(const char *name, const char *name_value) {
|
|||
}
|
||||
|
||||
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 @@ void MaybeReexec() {
|
|||
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) {
|
||||
|
|
|
@ -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(); }
|
||||
|
|
Loading…
Reference in New Issue