[all-commits] [llvm/llvm-project] 35acc3: tsan: fix a race when assigning ThreadSignalContext
Peter Ammon via All-commits
all-commits at lists.llvm.org
Tue Jan 10 10:33:52 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 35acc32b3e6535213d3ec651c9b7870cf74fe0ec
https://github.com/llvm/llvm-project/commit/35acc32b3e6535213d3ec651c9b7870cf74fe0ec
Author: Peter Ammon <corydoras at ridiculousfish.com>
Date: 2023-01-10 (Tue, 10 Jan 2023)
Changed paths:
M compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
M compiler-rt/lib/tsan/rtl/tsan_rtl.h
A compiler-rt/test/tsan/signal_thread_sigctx_race.cpp
Log Message:
-----------
tsan: fix a race when assigning ThreadSignalContext
The SigCtx function lazily allocates a ThreadSignalContext, and stores it
in the ThreadState. This function may be called by various interceptors and
the signal handler itself.
If SigCtx itself is interrupted by a signal, then (prior to this fix) there
was a possibility of allocating two ThreadSignalContexts. This not only
leaks, it fails to deliver the signal to the program's signal handler, as
the recorded signal is overwritten by the new ThreadSignalContext.
Fix this by using a CAS to swap in the ThreadSignalContext, preventing the
race. Add a test for this case.
Reviewed By: dvyukov, melver
Differential Revision: https://reviews.llvm.org/D140582
More information about the All-commits
mailing list