diff options
| author | Paul Kirth <paulkirth@google.com> | 2026-01-30 16:01:44 -0800 |
|---|---|---|
| committer | Paul Kirth <paulkirth@google.com> | 2026-02-02 17:10:47 -0800 |
| commit | 7ba94c2e1fa0dad47d503b6b726cf6ace4dd2ca1 (patch) | |
| tree | 1aee20292135005b3aa4f1e24dcf2142ea0944cd | |
| parent | 2f97c47cc22d40b824f36395e2db766959d76e49 (diff) | |
| download | llvm-users/ilovepi/signalstack.zip llvm-users/ilovepi/signalstack.tar.gz llvm-users/ilovepi/signalstack.tar.bz2 | |
[compiler-rt][common] Don't unmap stacks not mapped by the runtimeusers/ilovepi/signalstack
When the sanitizer hasn't mapped the alternate signal stack, but the
host program has (like LLVM), the runtime still tries to unilaterally
unmap the alternate stack. Instead, the runtime should just check if
it's actually mmaped the alternate stack, and only unmap it if it has.
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp index 8e5e879..8cb040b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp @@ -49,6 +49,8 @@ namespace __sanitizer { [[maybe_unused]] static atomic_uint8_t signal_handler_is_from_sanitizer[64]; +static THREADLOCAL void* allocated_alt_stack_base = nullptr; + u32 GetUid() { return getuid(); } @@ -201,6 +203,7 @@ void SetAlternateSignalStack() { altstack.ss_sp = (char *)MmapOrDie(altstack.ss_size, __func__); altstack.ss_flags = 0; CHECK_EQ(0, sigaltstack(&altstack, nullptr)); + allocated_alt_stack_base = altstack.ss_sp; } void UnsetAlternateSignalStack() { @@ -209,7 +212,11 @@ void UnsetAlternateSignalStack() { altstack.ss_flags = SS_DISABLE; altstack.ss_size = GetAltStackSize(); // Some sane value required on Darwin. CHECK_EQ(0, sigaltstack(&altstack, &oldstack)); - UnmapOrDie(oldstack.ss_sp, oldstack.ss_size); + if (allocated_alt_stack_base != 0 && + allocated_alt_stack_base == oldstack.ss_sp) { + UnmapOrDie(oldstack.ss_sp, oldstack.ss_size); + allocated_alt_stack_base = nullptr; + } } bool IsSignalHandlerFromSanitizer(int signum) { |
