This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Fix signal chaining
ClosedPublic

Authored by vitalybuka on Nov 10 2017, 7:20 PM.

Details

Summary

Return saved values only if installed sigaction is our wrapper.

Diff Detail

Repository
rL LLVM

Event Timeline

vitalybuka created this revision.Nov 10 2017, 7:20 PM
dvyukov accepted this revision.Nov 13 2017, 12:03 AM

LGTM with a nit

compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
2309 ↗(On Diff #122569)

I think we should at least zero old. Otherwise there is no way to distinguish when it's filled and when it's uninit garbage.

This revision is now accepted and ready to land.Nov 13 2017, 12:03 AM
vitalybuka added inline comments.Nov 13 2017, 12:48 PM
compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
2309 ↗(On Diff #122569)

if (res != 0) it's OK to expect garbage there
if (res == 0) old contains whatever was installed without interceptor, and this is the point of the patch, to get Deadly Signal handler.
We install "Deadly Signal" handler using real sigaction to avoid "allow_user_segv_handler" flag check in interceptor.

This revision was automatically updated to reflect the committed changes.
dvyukov added inline comments.Nov 14 2017, 12:06 AM
compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
2309 ↗(On Diff #122569)

if (res == 0) old contains whatever was installed without interceptor

This is not the case when cb != rtl_sigaction. We return 0 and leave garbage in old. Does libc ever return res=0 and garbage in old? If not, we should not too.

vitalybuka added inline comments.Nov 15 2017, 5:04 PM
compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
2309 ↗(On Diff #122569)

if (res == 0 && cb != rtl_sigaction && cb != rtl_sighandler) "old" contains something that was set by REAL(sigaction)(sig, &newact, old) call above, which is not garbage.

dvyukov added inline comments.Nov 15 2017, 11:39 PM
compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
2309 ↗(On Diff #122569)

That's what I missed! We now pass old to sigaction.