This is an archive of the discontinued LLVM Phabricator instance.

msan: check that ucontext_t is initialized on signal return
ClosedPublic

Authored by dvyukov on Dec 23 2021, 12:15 AM.

Details

Summary

A signal handler can alter ucontext_t to affect execution after
the signal returns. Check that the contents are initialized.
Restoring unitialized values in registers can't be good.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Dec 23 2021, 12:15 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2021, 12:15 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Do you expect some cleanup for this?

compiler-rt/lib/msan/msan_interceptors.cpp
999

what if signal handler is not instrumented?

compiler-rt/test/msan/Linux/signal_mcontext2.cpp
2

do we need -fsanitize-memory-track-origins=2 ?
if not the rest of the test is not msan specific and can be moved under sanitizer_common?

vitalybuka added inline comments.Dec 23 2021, 12:10 PM
compiler-rt/lib/msan/msan_interceptors.cpp
999

Ah, uc then should stay OK after __msan_unpoison

vitalybuka added inline comments.Dec 23 2021, 12:12 PM
compiler-rt/lib/msan/msan_interceptors.cpp
999

I guess we will have a problem if uninstructed handler use memcpy interceptors

dvyukov added inline comments.Dec 31 2021, 1:01 AM
compiler-rt/lib/msan/msan_interceptors.cpp
999

Are there any known precedents for uninstrumented handlers that call instrumented functions?
Otherwise it does not look different from not instrumenting random parts of the code with msan and getting false positives. Yes, that leads to false positives for any code. If the code will call memcpy+memcmp if will get false positives even w/o this change.

compiler-rt/test/msan/Linux/signal_mcontext2.cpp
2

It will fail only under msan, so the "not %run" part is msan-specific.

vitalybuka accepted this revision.Jan 5 2022, 12:23 AM
This revision is now accepted and ready to land.Jan 5 2022, 12:23 AM
This revision was landed with ongoing or failed builds.Jan 5 2022, 4:20 AM
This revision was automatically updated to reflect the committed changes.