-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hwasan] Improve support of forking with threads #75291
Merged
vitalybuka
merged 16 commits into
main
from
users/vitalybuka/spr/hwasan-improve-support-of-forking-with-threads
Dec 13, 2023
Merged
[hwasan] Improve support of forking with threads #75291
vitalybuka
merged 16 commits into
main
from
users/vitalybuka/spr/hwasan-improve-support-of-forking-with-threads
Dec 13, 2023
Conversation
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
Created using spr 1.3.4
Created using spr 1.3.4 [skip ci]
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) ChangesLock Lsan and Thread related date at_fork. Clean shadow before thread starts, forked process may reuse already Full diff: https://github.com/llvm/llvm-project/pull/75291.diff 3 Files Affected:
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index f01fa42764134..e0db24b9519f7 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -523,12 +523,24 @@ uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
void HwasanInstallAtForkHandler() {
auto before = []() {
- HwasanAllocatorLock();
+ if (CAN_SANITIZE_LEAKS) {
+ __lsan::LockGlobal();
+ }
+ // `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and do the
+ // job.
+ __lsan::LockThreads();
+ __lsan::LockAllocator();
StackDepotLockAll();
};
auto after = []() {
StackDepotUnlockAll();
- HwasanAllocatorUnlock();
+ // `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and do the
+ // job.
+ __lsan::UnlockAllocator();
+ __lsan::UnlockThreads();
+ if (CAN_SANITIZE_LEAKS) {
+ __lsan::UnlockGlobal();
+ }
};
pthread_atfork(before, after, after);
}
diff --git a/compiler-rt/lib/hwasan/hwasan_thread.cpp b/compiler-rt/lib/hwasan/hwasan_thread.cpp
index ce36547580e6e..3e14a718513d7 100644
--- a/compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -68,6 +68,7 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
}
Print("Creating : ");
}
+ ClearShadowForThreadStackAndTLS();
}
void Thread::InitStackRingBuffer(uptr stack_buffer_start,
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
index 1a52702c5de8c..f27859f815ff9 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
@@ -1,7 +1,5 @@
// RUN: %clang -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
-// UNSUPPORTED: hwasan
-
// Forking in multithread environment is unsupported. However we already have
// some workarounds, and will add more, so this is the test.
// The test try to check two things:
@@ -58,6 +56,10 @@ NOSAN static void *inchild(void *arg) {
}
int main(void) {
+#if __has_feature(hwaddress_sanitizer)
+ __hwasan_enable_allocator_tagging();
+#endif
+
pid_t pid;
pthread_barrier_init(&bar, NULL, 2);
|
Created using spr 1.3.4
thurstond
approved these changes
Dec 13, 2023
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4 [skip ci]
thurstond
approved these changes
Dec 13, 2023
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4 [skip ci]
vitalybuka
changed the base branch from
users/vitalybuka/spr/main.hwasan-improve-support-of-forking-with-threads
to
main
December 13, 2023 22:39
vitalybuka
deleted the
users/vitalybuka/spr/hwasan-improve-support-of-forking-with-threads
branch
December 13, 2023 22:50
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lock Lsan and Thread related date at_fork.
Clean shadow before thread starts, forked process may reuse already
mapped stack of 'lost' parent thread for new threads.