Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hwasan] Reset current thread pointer on thread exit.
Summary: This is necessary to handle calls to free() after __hwasan_thread_exit, which is possible in glibc. Also, add a null check to GetCurrentThread, otherwise the logic in GetThreadByBufferAddress turns it into a non-null value. This means that all of the checks for GetCurrentThread() != nullptr do not have any effect at all right now! Reviewers: pcc, hctim Subscribers: #sanitizers, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D79608
- Loading branch information
Showing
4 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=random_tags=1 %run %t | ||
// REQUIRES: stable-runtime | ||
|
||
#include <pthread.h> | ||
#include <sanitizer/hwasan_interface.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void *ThreadFn(void *) { | ||
strerror_l(-1, 0); | ||
__hwasan_enable_allocator_tagging(); | ||
// This will trigger memory deallocation in __strerror_thread_freeres, | ||
// at a point when HwasanThread is already gone. | ||
} | ||
|
||
int main() { | ||
pthread_t t; | ||
pthread_create(&t, NULL, ThreadFn, NULL); | ||
pthread_join(t, NULL); | ||
return 0; | ||
} |