Skip to content

Commit 600c599

Browse files
Samuel GroßV8 LUCI CQ
authored andcommitted
Use SA_ONSTACK when installing signal handlers
This will cause the signal handlers to run on an alternate stack iff one has been registered (e.g. by Asan). This way, the handlers can run successfully even in case of stack pointer corruption or a stack overflow. If no alternative stack has been registered, the behavior doesn't change and the handlers will continue to run on the default stack. Bug: chromium:1472227 Change-Id: I447538c1a226324666461130baa2d2a71aadf661 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4773135 Commit-Queue: Samuel Groß <[email protected]> Reviewed-by: Clemens Backes <[email protected]> Reviewed-by: Mark Mentovai <[email protected]> Cr-Commit-Position: refs/heads/main@{#89521}
1 parent 9b5b6ee commit 600c599

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎src/base/debug/stack_trace_posix.cc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ bool EnableInProcessStackDumping() {
341341

342342
struct sigaction action;
343343
memset(&action, 0, sizeof(action));
344-
action.sa_flags = SA_RESETHAND | SA_SIGINFO;
344+
// Use SA_ONSTACK so that iff an alternate stack has been registered, the
345+
// handler will run on that stack instead of the default stack. This can be
346+
// useful for example if the stack pointer gets corrupted or in case of stack
347+
// overflows, since that might prevent the handler from running properly.
348+
action.sa_flags = SA_RESETHAND | SA_SIGINFO | SA_ONSTACK;
345349
action.sa_sigaction = &StackDumpSignalHandler;
346350
sigemptyset(&action.sa_mask);
347351

‎src/trap-handler/handler-outside-posix.cc‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ bool RegisterDefaultTrapHandler() {
4545

4646
struct sigaction action;
4747
action.sa_sigaction = HandleSignal;
48-
action.sa_flags = SA_SIGINFO;
48+
// Use SA_ONSTACK so that iff an alternate signal stack was registered via
49+
// sigaltstack, that one is used for handling the signal instead of the
50+
// default stack. This can be useful if for example the stack pointer is
51+
// corrupted or a stack overflow is triggered as that may cause the trap
52+
// handler to crash if it runs on the default stack. We assume that other
53+
// parts, e.g. Asan or the v8 sandbox testing infrastructure, will register
54+
// the alternate stack if necessary.
55+
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
4956
sigemptyset(&action.sa_mask);
5057
// {sigaction} installs a new custom segfault handler. On success, it returns
5158
// 0. If we get a nonzero value, we report an error to the caller by returning

0 commit comments

Comments
 (0)