This is an archive of the discontinued LLVM Phabricator instance.

[HWASAN] Fix TLS + signal handling related crash
ClosedPublic

Authored by kstoimenov on Apr 24 2023, 12:27 PM.

Details

Summary

When a signal is raised before HWASAN has a chance to initialize it's TLS entry the program crashes. This only happens when hwasan-with-tls is true, which is default value. This patch fixes the problem by disabling signals during thread initialization time.

Diff Detail

Event Timeline

kstoimenov created this revision.Apr 24 2023, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 12:27 PM
Herald added a subscriber: Enna1. · View Herald Transcript
kstoimenov requested review of this revision.Apr 24 2023, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 12:27 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.Apr 24 2023, 1:57 PM

It would be awesome to have a test, but here D113328 I failed to make reproducer for the similar patch.

compiler-rt/lib/hwasan/hwasan_interceptors.cpp
48–49

Up to you, but I guess you still can keep *A = {callback, param};
it should zero initialize the tail

48–49

for consistency, as it makes no difference with the current state of code
I'd either remove { }, or move block under {}

This revision is now accepted and ready to land.Apr 24 2023, 1:57 PM

the description formatting as is will not look good in "git log"

vitalybuka added inline comments.Apr 24 2023, 2:06 PM
compiler-rt/lib/hwasan/hwasan_interceptors.cpp
47–48

unrelated to the patch, but this could be a source of subtle leaks

Imagine:

  1. caller allocate param on head
  2. pass it into pthread_create
  3. forget the pointer
  4. Lsan checks for leaks
  5. HwasanThreadStartFunc executed

so if lsan checks in the step 4, heap allocated param pointer is only in the mapped region, which lsan can't see, and
before __hwasan_thread_enter the new thread is not visible to lsan as well

Addressed comments.

vitalybuka accepted this revision.Apr 24 2023, 4:40 PM
kstoimenov retitled this revision from [HWASAN] Fix a crash when a singal is raised before HWASAN TLS is initialized by disabling singals at thread start time. to [HWASAN] Fix signal handling related HWASAN crash.Apr 24 2023, 4:40 PM
kstoimenov edited the summary of this revision. (Show Details)
kstoimenov retitled this revision from [HWASAN] Fix signal handling related HWASAN crash to [HWASAN] Fix TLS + signal handling related crash.
This revision was automatically updated to reflect the committed changes.
kstoimenov marked an inline comment as done.