crash_dump: clear the default crash handlers.

crash_dump is a dynamic executable that gets the default crash dumping
handlers set by the linker. Turn them off to prevent crash_dump from
dumping itself.

Bug: http://b/34472671
Test: inserted an abort into crash_dump
Change-Id: Ic9d708805ad47afbb2a9ff37e2ca059f23f421de
This commit is contained in:
Josh Gao 2017-01-22 17:41:15 -08:00
parent d20d687de5
commit 575941115e
3 changed files with 25 additions and 12 deletions

View File

@ -160,6 +160,12 @@ static bool tombstoned_notify_completion(int tombstoned_socket) {
return true;
}
static void signal_handler(int) {
// We can't log easily, because the heap might be corrupt.
// Just die and let the surrounding log context explain things.
_exit(1);
}
static void abort_handler(pid_t target, const bool& tombstoned_connected,
unique_fd& tombstoned_socket, unique_fd& output_fd,
const char* abort_msg) {
@ -175,7 +181,6 @@ static void abort_handler(pid_t target, const bool& tombstoned_connected,
dprintf(output_fd.get(), "crash_dump failed to dump process %d: %s\n", target, abort_msg);
// Don't dump ourselves.
_exit(1);
}
@ -201,6 +206,11 @@ int main(int argc, char** argv) {
abort_handler(target, tombstoned_connected, tombstoned_socket, output_fd, abort_msg);
});
// Don't try to dump ourselves.
struct sigaction action = {};
action.sa_handler = signal_handler;
debuggerd_register_handlers(&action);
if (argc != 2) {
return 1;
}

View File

@ -367,15 +367,5 @@ void debuggerd_init(debuggerd_callbacks_t* callbacks) {
// Use the alternate signal stack if available so we can catch stack overflows.
action.sa_flags |= SA_ONSTACK;
sigaction(SIGABRT, &action, nullptr);
sigaction(SIGBUS, &action, nullptr);
sigaction(SIGFPE, &action, nullptr);
sigaction(SIGILL, &action, nullptr);
sigaction(SIGSEGV, &action, nullptr);
#if defined(SIGSTKFLT)
sigaction(SIGSTKFLT, &action, nullptr);
#endif
sigaction(SIGTRAP, &action, nullptr);
sigaction(DEBUGGER_SIGNAL, &action, nullptr);
debuggerd_register_handlers(&action);
}

View File

@ -39,4 +39,17 @@ void debuggerd_init(debuggerd_callbacks_t* callbacks);
// to the log.
#define DEBUGGER_SIGNAL (__SIGRTMIN + 3)
static void __attribute__((__unused__)) debuggerd_register_handlers(struct sigaction* action) {
sigaction(SIGABRT, action, nullptr);
sigaction(SIGBUS, action, nullptr);
sigaction(SIGFPE, action, nullptr);
sigaction(SIGILL, action, nullptr);
sigaction(SIGSEGV, action, nullptr);
#if defined(SIGSTKFLT)
sigaction(SIGSTKFLT, action, nullptr);
#endif
sigaction(SIGTRAP, action, nullptr);
sigaction(DEBUGGER_SIGNAL, action, nullptr);
}
__END_DECLS