-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[sanitizer] Print diagnostic if ptrace syscall fails #151406
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
924c8ae
[sanitizer] Print diagnostic if ptrace syscall fails
thurstond bb743a5
clang-format
thurstond 8a77e9c
Begun, the clone wars have
thurstond 8ef6bdf
Add comment on absence of CLONE_SETTLS
thurstond 2fb71df
Also mention shared TLS in TestPTrace()
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,7 +403,48 @@ struct ScopedSetTracerPID { | |
| } | ||
| }; | ||
|
|
||
| // This detects whether ptrace is blocked (e.g., by seccomp), by forking and | ||
| // then attempting ptrace. | ||
| // This separate check is necessary because StopTheWorld() creates a *thread*, | ||
| // and therefore cannot use waitpid() due to the shared errno. | ||
| static void TestPTrace() { | ||
| // Only check the first time this is called. | ||
| static bool checked = false; | ||
| if (checked) | ||
| return; | ||
| checked = true; | ||
|
|
||
| // fork() should be cheap because of copy-on-write. Besides, this is only | ||
|
||
| // called the first time. | ||
| int pid = internal_fork(); | ||
|
|
||
| if (pid < 0) { | ||
| int rverrno; | ||
| if (internal_iserror(pid, &rverrno)) { | ||
| Report("WARNING: TestPTrace() failed to fork (errno %d)\n", rverrno); | ||
| } | ||
| _exit(-1); | ||
| } | ||
|
|
||
| if (pid == 0) { | ||
| // Child subprocess | ||
| internal_ptrace(PTRACE_ATTACH, 0, nullptr, nullptr); | ||
| _exit (0); | ||
| } else { | ||
| int wstatus; | ||
| internal_waitpid(pid, &wstatus, 0); | ||
|
|
||
| if (WIFSIGNALED(wstatus)) { | ||
| VReport(0, "Warning: ptrace appears to be blocked (is seccomp enabled?). LeakSanitizer may hang.\n"); | ||
| VReport(0, "Child exited with signal %d.\n", WTERMSIG(wstatus)); | ||
| // We don't abort the sanitizer - it's still worth letting the sanitizer try. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void StopTheWorld(StopTheWorldCallback callback, void *argument) { | ||
| TestPTrace(); | ||
|
|
||
| StopTheWorldScope in_stoptheworld; | ||
| // Prepare the arguments for TracerThread. | ||
| struct TracerThreadArgument tracer_thread_argument; | ||
|
|
||
Oops, something went wrong.
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.
errnoshould be thread local on any reasonable platform?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.
The existing comment on line 504 states that errno is shared. I think sanitizers run on all manner of unreasonable platforms?
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.
This whole code is under
SANITIZER_LINUXthoughThere 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.
maybe the real reason is the
clonesyscall?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.
Thanks, updated.
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.
*maybe the real treasure was the clones we made along the way