Skip to content

Commit f9dd3ea

Browse files
committed
[hwasan] Fix data race between ReleaseThread() and VisitAllLiveThreads()
Data race scenario: ``` Thread 1 | Thread 2 ReportTagMismatch() | Call VisitAllLiveThreads() to scan all | threads' ring buffers to find | if it's a heap-use-after-free. | Lock live_list_mutex_ | | Thread 2 exit | ReleaseThread() calls Thread::Destroy() for Thread 2, | which frees heap alloctions ring buffer | RemoveThreadFromLiveList() tries to take live_list_mutex_ again Iterate the heap alloctions ring buffer | of Thread 2, which is already freed | ``` Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D148909
1 parent 6076667 commit f9dd3ea

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compiler-rt/lib/hwasan/hwasan_thread_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ class SANITIZER_MUTEX HwasanThreadList {
131131

132132
void ReleaseThread(Thread *t) SANITIZER_EXCLUDES(free_list_mutex_) {
133133
RemoveThreadStats(t);
134+
RemoveThreadFromLiveList(t);
134135
t->Destroy();
135136
DontNeedThread(t);
136-
RemoveThreadFromLiveList(t);
137137
SpinMutexLock l(&free_list_mutex_);
138138
free_list_.push_back(t);
139139
}

0 commit comments

Comments
 (0)