Skip to content

Commit 7122374

Browse files
committed
[sanitizer-common] [Darwin] Provide warnings for common sandbox issues (llvm#165907)
We currently do not handle errors in task_set_exc_guard_behavior. If this fails, mmap can unexpectedly crash. We also do not currently provide a clear warning if no external symbolizers are found. rdar://163798535 (cherry picked from commit 148a42b)
1 parent bd0335c commit 7122374

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,17 @@ static void DisableMmapExcGuardExceptions() {
954954
RTLD_DEFAULT, "task_set_exc_guard_behavior");
955955
if (set_behavior == nullptr) return;
956956
const task_exc_guard_behavior_t task_exc_guard_none = 0;
957-
set_behavior(mach_task_self(), task_exc_guard_none);
957+
kern_return_t res = set_behavior(mach_task_self(), task_exc_guard_none);
958+
if (res != KERN_SUCCESS) {
959+
Report(
960+
"WARN: task_set_exc_guard_behavior returned %d (%s), "
961+
"mmap may fail unexpectedly.\n",
962+
res, mach_error_string(res));
963+
if (res == KERN_DENIED)
964+
Report(
965+
"HINT: Check that task_set_exc_guard_behavior is allowed by "
966+
"sandbox.\n");
967+
}
958968
}
959969

960970
static void VerifyInterceptorsWorking();

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,13 @@ static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list,
505505
}
506506

507507
# if SANITIZER_APPLE
508+
if (list->empty()) {
509+
Report(
510+
"WARN: No external symbolizers found. Symbols may be missing or "
511+
"unreliable.\n");
512+
Report(
513+
"HINT: Is PATH set? Does sandbox allow file-read of /usr/bin/atos?\n");
514+
}
508515
VReport(2, "Using dladdr symbolizer.\n");
509516
list->push_back(new (*allocator) DlAddrSymbolizer());
510517
# endif // SANITIZER_APPLE

0 commit comments

Comments
 (0)