|
|
c047fc |
From ffd0f69c375f12f081a1a5158a02a05000b7a93c Mon Sep 17 00:00:00 2001
|
|
|
c047fc |
From: Vitaly Buka <vitalybuka@google.com>
|
|
|
c047fc |
Date: Fri, 16 Apr 2021 09:50:24 -0700
|
|
|
c047fc |
Subject: [PATCH][compiler-rt] Sanitizer built against glibc 2.34 doesn't work
|
|
|
c047fc |
|
|
|
c047fc |
As mentioned in https://gcc.gnu.org/PR100114 , glibc starting with the
|
|
|
c047fc |
https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53
|
|
|
c047fc |
change doesn't define SIGSTKSZ and MINSIGSTKSZ macros to constants, but to sysconf function call.
|
|
|
c047fc |
sanitizer_posix_libcdep.cpp has
|
|
|
c047fc |
static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
|
|
|
c047fc |
which is generally fine, just means that when SIGSTKSZ is not a compile time constant will be initialized later.
|
|
|
c047fc |
The problem is that kAltStackSize is used in SetAlternateSignalStack which is called very early, from .preinit_array
|
|
|
c047fc |
initialization, i.e. far before file scope variables are constructed, which means it is not initialized and
|
|
|
c047fc |
mmapping 0 will fail:
|
|
|
c047fc |
==145==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
|
|
|
c047fc |
|
|
|
c047fc |
Here is one possible fix, another one could be to make kAltStackSize a preprocessor macro if _SG_SIGSTKSZ is defined
|
|
|
c047fc |
(but perhaps with having an automatic const variable initialized to it so that sysconf isn't at least called twice
|
|
|
c047fc |
during SetAlternateSignalStack.
|
|
|
c047fc |
|
|
|
c047fc |
Reviewed By: vitalybuka
|
|
|
c047fc |
|
|
|
c047fc |
Differential Revision: https://reviews.llvm.org/D100645
|
|
|
c047fc |
|
|
|
c047fc |
(cherry picked from commit 82150606fb11d28813ae6da1101f5bda638165fe)
|
|
|
c047fc |
---
|
|
|
c047fc |
compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp | 12 ++++++++----
|
|
|
c047fc |
1 file changed, 8 insertions(+), 4 deletions(-)
|
|
|
c047fc |
|
|
|
c047fc |
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
|
|
|
c047fc |
index d29438c..2b10bdd 100644
|
|
|
c047fc |
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
|
|
|
c047fc |
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
|
|
|
c047fc |
@@ -165,7 +165,11 @@ bool SupportsColoredOutput(fd_t fd) {
|
|
|
c047fc |
|
|
|
c047fc |
#if !SANITIZER_GO
|
|
|
c047fc |
// TODO(glider): different tools may require different altstack size.
|
|
|
c047fc |
-static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
|
|
|
c047fc |
+static uptr GetAltStackSize() {
|
|
|
c047fc |
+ // SIGSTKSZ is not enough.
|
|
|
c047fc |
+ static const uptr kAltStackSize = SIGSTKSZ * 4;
|
|
|
c047fc |
+ return kAltStackSize;
|
|
|
c047fc |
+}
|
|
|
c047fc |
|
|
|
c047fc |
void SetAlternateSignalStack() {
|
|
|
c047fc |
stack_t altstack, oldstack;
|
|
|
c047fc |
@@ -176,10 +180,10 @@ void SetAlternateSignalStack() {
|
|
|
c047fc |
// TODO(glider): the mapped stack should have the MAP_STACK flag in the
|
|
|
c047fc |
// future. It is not required by man 2 sigaltstack now (they're using
|
|
|
c047fc |
// malloc()).
|
|
|
c047fc |
- void* base = MmapOrDie(kAltStackSize, __func__);
|
|
|
c047fc |
+ void *base = MmapOrDie(GetAltStackSize(), __func__);
|
|
|
c047fc |
altstack.ss_sp = (char*) base;
|
|
|
c047fc |
altstack.ss_flags = 0;
|
|
|
c047fc |
- altstack.ss_size = kAltStackSize;
|
|
|
c047fc |
+ altstack.ss_size = GetAltStackSize();
|
|
|
c047fc |
CHECK_EQ(0, sigaltstack(&altstack, nullptr));
|
|
|
c047fc |
}
|
|
|
c047fc |
|
|
|
c047fc |
@@ -187,7 +191,7 @@ void UnsetAlternateSignalStack() {
|
|
|
c047fc |
stack_t altstack, oldstack;
|
|
|
c047fc |
altstack.ss_sp = nullptr;
|
|
|
c047fc |
altstack.ss_flags = SS_DISABLE;
|
|
|
c047fc |
- altstack.ss_size = kAltStackSize; // Some sane value required on Darwin.
|
|
|
c047fc |
+ altstack.ss_size = GetAltStackSize(); // Some sane value required on Darwin.
|
|
|
c047fc |
CHECK_EQ(0, sigaltstack(&altstack, &oldstack));
|
|
|
c047fc |
UnmapOrDie(oldstack.ss_sp, oldstack.ss_size);
|
|
|
c047fc |
}
|
|
|
c047fc |
--
|
|
|
c047fc |
1.8.3.1
|
|
|
c047fc |
|