This is an archive of the discontinued LLVM Phabricator instance.

[asan][fuchsia] set current thread before reading thread state
ClosedPublic

Authored by zarvox on Oct 16 2020, 5:12 PM.

Details

Summary

When enabling stack use-after-free detection, we discovered that we read
the thread ID on the main thread while it is still set to 2^24-1.

This patch moves our call to AsanThread::Init() out of CreateAsanThread,
so that we can call SetCurrentThread first on the main thread.

Diff Detail

Event Timeline

zarvox created this revision.Oct 16 2020, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 16 2020, 5:12 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
zarvox requested review of this revision.Oct 16 2020, 5:12 PM
charco added a subscriber: charco.Oct 16 2020, 5:27 PM
mcgrathr accepted this revision.Oct 23 2020, 10:58 AM

Thanks for the fix!

compiler-rt/lib/asan/asan_fuchsia.cpp
135

Since that's the invariant and elsewhere there's the invariant that the main thread has tid 0, how about DCHECK_EQ(t->tid(), 0); here? There could also be a DCHECK_NE(tid(), ThreadRegistry::kUnknownTid); in ASanThread::Init, which would have caught this bug.

This revision is now accepted and ready to land.Oct 23 2020, 10:58 AM
zarvox updated this revision to Diff 300361.Oct 23 2020, 11:39 AM

Added DCHECKs per mcgrathr's feedback.

zarvox added inline comments.Oct 23 2020, 11:40 AM
compiler-rt/lib/asan/asan_fuchsia.cpp
135

Yeah, both sound reasonable.

This revision was automatically updated to reflect the committed changes.