Skip to content

Commit 148a42b

Browse files
authored
[sanitizer-common] [Darwin] Provide warnings for common sandbox issues (#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
1 parent 0122187 commit 148a42b

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
@@ -960,7 +960,17 @@ static void DisableMmapExcGuardExceptions() {
960960
RTLD_DEFAULT, "task_set_exc_guard_behavior");
961961
if (set_behavior == nullptr) return;
962962
const task_exc_guard_behavior_t task_exc_guard_none = 0;
963-
set_behavior(mach_task_self(), task_exc_guard_none);
963+
kern_return_t res = set_behavior(mach_task_self(), task_exc_guard_none);
964+
if (res != KERN_SUCCESS) {
965+
Report(
966+
"WARN: task_set_exc_guard_behavior returned %d (%s), "
967+
"mmap may fail unexpectedly.\n",
968+
res, mach_error_string(res));
969+
if (res == KERN_DENIED)
970+
Report(
971+
"HINT: Check that task_set_exc_guard_behavior is allowed by "
972+
"sandbox.\n");
973+
}
964974
}
965975

966976
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)