[PATCH] D89442: [Support] Use SA_ONSTACK in CrashRecoveryContext

Jann Horn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 19:32:15 PDT 2020


thejh created this revision.
thejh added reviewers: chandlerc, ddunbar, rsmith.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
thejh requested review of this revision.

The signal handlers LLVM installs in RegisterHandlers() (used for things
like printing a stack trace) use SA_ONSTACK so that on stack overflow,
the signal handler still has a stack from which it can run.

However, CrashRecoveryContext overwrites those signal handlers with ones
without SA_ONSTACK. Therefore, if the stack overflows while a
CrashRecoveryContext is active, the kernel fails to write a signal frame
and terminates the process.

Fix it by registering CrashRecoveryContext's signal handlers such that
they also run off the alternate signal stack.

You can test this by calling an endlessly recursing function directly
below the call to llvm::CrashRecoveryContext::Enable() in
clang/tools/driver/driver.cpp.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89442

Files:
  llvm/lib/Support/CrashRecoveryContext.cpp


Index: llvm/lib/Support/CrashRecoveryContext.cpp
===================================================================
--- llvm/lib/Support/CrashRecoveryContext.cpp
+++ llvm/lib/Support/CrashRecoveryContext.cpp
@@ -392,7 +392,7 @@
   // Setup the signal handler.
   struct sigaction Handler;
   Handler.sa_handler = CrashRecoverySignalHandler;
-  Handler.sa_flags = 0;
+  Handler.sa_flags = SA_ONSTACK;
   sigemptyset(&Handler.sa_mask);
 
   for (unsigned i = 0; i != NumSignals; ++i) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89442.298281.patch
Type: text/x-patch
Size: 485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201015/85d5f15f/attachment.bin>


More information about the llvm-commits mailing list