Skip to content

Commit cb19abf

Browse files
committed
Revert "[sanitizer] Move signal blocking code into posix"
Breaks https://lab.llvm.org/buildbot/#/builders/77/builds/30880 This reverts commit 58f7543.
1 parent df330d7 commit cb19abf

File tree

6 files changed

+56
-49
lines changed

6 files changed

+56
-49
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,12 @@ static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
224224
auto args = asanThreadArgRetval().GetArgs(self);
225225
t->ThreadStart(GetTid());
226226

227+
# if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
228+
SANITIZER_SOLARIS
227229
__sanitizer_sigset_t sigset;
228230
t->GetStartData(sigset);
229231
SetSigProcMask(&sigset, nullptr);
232+
# endif
230233

231234
thread_return_t retval = (*args.routine)(args.arg_retval);
232235
asanThreadArgRetval().Finish(self, retval);
@@ -249,7 +252,10 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
249252
u32 current_tid = GetCurrentTidOrInvalid();
250253

251254
__sanitizer_sigset_t sigset;
255+
# if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
256+
SANITIZER_SOLARIS
252257
ScopedBlockSignals block(&sigset);
258+
# endif
253259

254260
AsanThread *t = AsanThread::Create(sigset, current_tid, &stack, detached);
255261

compiler-rt/lib/asan/asan_posix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ void PlatformTSDDtor(void *tsd) {
110110
key.key = nullptr;
111111
// Make sure that signal handler can not see a stale current thread pointer.
112112
atomic_signal_fence(memory_order_seq_cst);
113-
// After this point it's unsafe to execute signal handlers which may be
114-
// instrumented.
115-
BlockSignals();
116113
AsanThread::TSDDtor(tsd);
117114
}
118115
#else
@@ -141,9 +138,12 @@ void PlatformTSDDtor(void *tsd) {
141138
CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
142139
return;
143140
}
141+
# if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
142+
SANITIZER_SOLARIS
144143
// After this point it's unsafe to execute signal handlers which may be
145-
// instrumented.
144+
// instrumented. It's probably not just a Linux issue.
146145
BlockSignals();
146+
# endif
147147
AsanThread::TSDDtor(tsd);
148148
}
149149
#endif

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,36 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
156156

157157
namespace __sanitizer {
158158

159+
void SetSigProcMask(__sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) {
160+
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, set, oldset));
161+
}
162+
163+
void BlockSignals(__sanitizer_sigset_t *oldset) {
164+
__sanitizer_sigset_t set;
165+
internal_sigfillset(&set);
166+
# if SANITIZER_LINUX && !SANITIZER_ANDROID
167+
// Glibc uses SIGSETXID signal during setuid call. If this signal is blocked
168+
// on any thread, setuid call hangs.
169+
// See test/sanitizer_common/TestCases/Linux/setuid.c.
170+
internal_sigdelset(&set, 33);
171+
# endif
172+
# if SANITIZER_LINUX
173+
// Seccomp-BPF-sandboxed processes rely on SIGSYS to handle trapped syscalls.
174+
// If this signal is blocked, such calls cannot be handled and the process may
175+
// hang.
176+
internal_sigdelset(&set, 31);
177+
# endif
178+
SetSigProcMask(&set, oldset);
179+
}
180+
181+
ScopedBlockSignals::ScopedBlockSignals(__sanitizer_sigset_t *copy) {
182+
BlockSignals(&saved_);
183+
if (copy)
184+
internal_memcpy(copy, &saved_, sizeof(saved_));
185+
}
186+
187+
ScopedBlockSignals::~ScopedBlockSignals() { SetSigProcMask(&saved_, nullptr); }
188+
159189
# if SANITIZER_LINUX && defined(__x86_64__)
160190
# include "sanitizer_syscall_linux_x86_64.inc"
161191
# elif SANITIZER_LINUX && SANITIZER_RISCV64

compiler-rt/lib/sanitizer_common/sanitizer_linux.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,22 @@ void ReadProcMaps(ProcSelfMapsBuff *proc_maps);
4646

4747
// Syscall wrappers.
4848
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
49-
uptr internal_sigaltstack(const void *ss, void *oss);
49+
uptr internal_sigaltstack(const void* ss, void* oss);
50+
uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
51+
__sanitizer_sigset_t *oldset);
52+
53+
void SetSigProcMask(__sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset);
54+
void BlockSignals(__sanitizer_sigset_t *oldset = nullptr);
55+
struct ScopedBlockSignals {
56+
explicit ScopedBlockSignals(__sanitizer_sigset_t *copy);
57+
~ScopedBlockSignals();
58+
59+
ScopedBlockSignals &operator=(const ScopedBlockSignals &) = delete;
60+
ScopedBlockSignals(const ScopedBlockSignals &) = delete;
61+
62+
private:
63+
__sanitizer_sigset_t saved_;
64+
};
5065

5166
# if SANITIZER_GLIBC
5267
uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp);

compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -406,35 +406,6 @@ uptr MmapNamed(void *addr, uptr length, int prot, int flags, const char *name) {
406406
return res;
407407
}
408408

409-
void SetSigProcMask(__sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) {
410-
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, set, oldset));
411-
}
412-
413-
void BlockSignals(__sanitizer_sigset_t *oldset) {
414-
__sanitizer_sigset_t set;
415-
internal_sigfillset(&set);
416-
# if SANITIZER_LINUX && !SANITIZER_ANDROID
417-
// Glibc uses SIGSETXID signal during setuid call. If this signal is blocked
418-
// on any thread, setuid call hangs.
419-
// See test/sanitizer_common/TestCases/Linux/setuid.c.
420-
internal_sigdelset(&set, 33);
421-
# endif
422-
# if SANITIZER_LINUX
423-
// Seccomp-BPF-sandboxed processes rely on SIGSYS to handle trapped syscalls.
424-
// If this signal is blocked, such calls cannot be handled and the process may
425-
// hang.
426-
internal_sigdelset(&set, 31);
427-
# endif
428-
SetSigProcMask(&set, oldset);
429-
}
430-
431-
ScopedBlockSignals::ScopedBlockSignals(__sanitizer_sigset_t *copy) {
432-
BlockSignals(&saved_);
433-
if (copy)
434-
internal_memcpy(copy, &saved_, sizeof(saved_));
435-
}
436-
437-
ScopedBlockSignals::~ScopedBlockSignals() { SetSigProcMask(&saved_, nullptr); }
438409

439410
} // namespace __sanitizer
440411

compiler-rt/lib/sanitizer_common/sanitizer_posix.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ int internal_sigaction(int signum, const void *act, void *oldact);
9898
void internal_sigfillset(__sanitizer_sigset_t *set);
9999
void internal_sigemptyset(__sanitizer_sigset_t *set);
100100
bool internal_sigismember(__sanitizer_sigset_t *set, int signum);
101-
uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
102-
__sanitizer_sigset_t *oldset);
103101

104102
uptr internal_execve(const char *filename, char *const argv[],
105103
char *const envp[]);
@@ -126,19 +124,6 @@ void DecorateMapping(uptr addr, uptr size, const char *name);
126124
# define __sanitizer_dirsiz(dp) ((dp)->d_reclen)
127125
# endif
128126

129-
void SetSigProcMask(__sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset);
130-
void BlockSignals(__sanitizer_sigset_t *oldset = nullptr);
131-
struct ScopedBlockSignals {
132-
explicit ScopedBlockSignals(__sanitizer_sigset_t *copy);
133-
~ScopedBlockSignals();
134-
135-
ScopedBlockSignals &operator=(const ScopedBlockSignals &) = delete;
136-
ScopedBlockSignals(const ScopedBlockSignals &) = delete;
137-
138-
private:
139-
__sanitizer_sigset_t saved_;
140-
};
141-
142127
} // namespace __sanitizer
143128

144129
#endif // SANITIZER_POSIX

0 commit comments

Comments
 (0)