This is an archive of the discontinued LLVM Phabricator instance.

[Support] Use SA_ONSTACK in CrashRecoveryContext
Needs ReviewPublic

Authored by thejh on Oct 14 2020, 7:32 PM.

Details

Summary

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.

Diff Detail

Event Timeline

thejh created this revision.Oct 14 2020, 7:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2020, 7:32 PM
thejh requested review of this revision.Oct 14 2020, 7:32 PM

It seems that we ran into a similar issue recently, but I'm not experienced in this part to determine if that patch fixes the issue. Could someone take a quick look?

Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2023, 7:52 AM