-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[sanitizer] Add cloak_sanitizer_signal_handlers runtime option #162746
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d7e930
[sanitizer] Add cloak_sanitizer_signal_handlers runtime option
thurstond 8c5e14c
Undo API addition
thurstond d6e0f89
Undo NFC change
thurstond 9048f7a
Remove runtime uncloaking test
thurstond 294f76e
Undo stray newline
thurstond dd6ffff
Add TODO for BSD
thurstond f14b39f
Expand tests to cover handle_segv=0 and handle_segv=2
thurstond 714bd58
Update commentary
thurstond 6546834
Add SetSignalHandlerFromSanitizer/IsSignalHandlerFromSanitizer
thurstond 4f4b75e
Use ARRAY_SIZE() instead of MaxSignals
thurstond 253d5b6
Updated to use atomics
thurstond fef7f3e
Use lambdas
thurstond 8a7f494
Remove redundant line`
thurstond e531a92
Lambda approach works with msan and tsan
thurstond ed76424
Undo formatting change
thurstond 5571508
Early exit
thurstond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
51 changes: 51 additions & 0 deletions
51
compiler-rt/test/sanitizer_common/TestCases/Linux/cloak_sigaction.cpp
This file contains hidden or 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,51 @@ | ||
// UNSUPPORTED: android | ||
// UNSUPPORTED: hwasan | ||
|
||
// RUN: %clangxx -O0 %s -o %t | ||
|
||
// Sanitizer signal handler not installed; custom signal handler installed | ||
// RUN: %env_tool_opts=handle_segv=0:cloak_sanitizer_signal_handlers=false not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,CUSTOM | ||
// RUN: %env_tool_opts=handle_segv=0:cloak_sanitizer_signal_handlers=true not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,CUSTOM | ||
|
||
// Sanitizer signal handler installed but overriden by custom signal handler | ||
// RUN: %env_tool_opts=handle_segv=1:cloak_sanitizer_signal_handlers=false not %run %t 2>&1 | FileCheck %s --check-prefixes=NONDEFAULT,CUSTOM | ||
// RUN: %env_tool_opts=handle_segv=1:cloak_sanitizer_signal_handlers=true not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,CUSTOM | ||
|
||
// Sanitizer signal handler installed immutably | ||
// N.B. for handle_segv=2 with cloaking off, there is a pre-existing difference | ||
// in signal vs. sigaction: signal effectively cloaks the handler. | ||
// RUN: %env_tool_opts=handle_segv=2:cloak_sanitizer_signal_handlers=false not %run %t 2>&1 | FileCheck %s --check-prefixes=NONDEFAULT,SANITIZER | ||
// RUN: %env_tool_opts=handle_segv=2:cloak_sanitizer_signal_handlers=true not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,SANITIZER | ||
|
||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void handler(int signum, siginfo_t *info, void *context) { | ||
printf("Custom signal handler\n"); | ||
exit(1); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
struct sigaction sa = {0}; | ||
struct sigaction old = {0}; | ||
sa.sa_flags = SA_SIGINFO; | ||
sa.sa_sigaction = &handler; | ||
sigaction(SIGSEGV, &sa, &old); | ||
|
||
if (reinterpret_cast<void *>(old.sa_sigaction) == SIG_DFL) | ||
printf("Old handler: default\n"); | ||
// DEFAULT: Old handler: default | ||
else | ||
printf("Old handler: non-default\n"); | ||
// NONDEFAULT: Old handler: non-default | ||
|
||
fflush(stdout); | ||
|
||
char *c = (char *)0x123; | ||
printf("%d\n", *c); | ||
// CUSTOM: Custom signal handler | ||
// SANITIZER: Sanitizer:DEADLYSIGNAL | ||
|
||
return 0; | ||
} |
46 changes: 46 additions & 0 deletions
46
compiler-rt/test/sanitizer_common/TestCases/Linux/cloak_signal.cpp
This file contains hidden or 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,46 @@ | ||
// UNSUPPORTED: android | ||
// UNSUPPORTED: hwasan | ||
|
||
// RUN: %clangxx -O0 %s -o %t | ||
|
||
// Sanitizer signal handler not installed; custom signal handler installed | ||
// RUN: %env_tool_opts=handle_segv=0:cloak_sanitizer_signal_handlers=false not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,CUSTOM | ||
// RUN: %env_tool_opts=handle_segv=0:cloak_sanitizer_signal_handlers=true not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,CUSTOM | ||
|
||
// Sanitizer signal handler installed but overriden by custom signal handler | ||
// RUN: %env_tool_opts=handle_segv=1:cloak_sanitizer_signal_handlers=false not %run %t 2>&1 | FileCheck %s --check-prefixes=NONDEFAULT,CUSTOM | ||
// RUN: %env_tool_opts=handle_segv=1:cloak_sanitizer_signal_handlers=true not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,CUSTOM | ||
|
||
// Sanitizer signal handler installed immutably | ||
// N.B. for handle_segv=2 with cloaking off, there is a pre-existing difference | ||
// in signal vs. sigaction: signal effectively cloaks the handler. | ||
// RUN: %env_tool_opts=handle_segv=2:cloak_sanitizer_signal_handlers=false not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,SANITIZER | ||
// RUN: %env_tool_opts=handle_segv=2:cloak_sanitizer_signal_handlers=true not %run %t 2>&1 | FileCheck %s --check-prefixes=DEFAULT,SANITIZER | ||
|
||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void my_signal_sighandler(int signum) { | ||
printf("Custom signal handler\n"); | ||
exit(1); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
__sighandler_t old = signal(SIGSEGV, &my_signal_sighandler); | ||
if (old == SIG_DFL) | ||
printf("Old handler: default\n"); | ||
// DEFAULT: Old handler: default | ||
else | ||
printf("Old handler: non-default\n"); | ||
// NONDEFAULT: Old handler: non-default | ||
|
||
fflush(stdout); | ||
|
||
char *c = (char *)0x123; | ||
printf("%d\n", *c); | ||
// CUSTOM: Custom signal handler | ||
// SANITIZER: Sanitizer:DEADLYSIGNAL | ||
|
||
return 0; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://llvm.org/docs/CodingStandards.html#id40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 5571508