diff options
author | Josh Gao <jmgao@google.com> | 2016-07-14 16:43:12 -0700 |
---|---|---|
committer | gitbuildkicker <android-build@google.com> | 2016-07-21 17:35:58 -0700 |
commit | c764dcd6977a04e272e44b0381c13ac4aed8a280 (patch) | |
tree | 08ebba7ece5aa22e9d8d6f6aea23325e67aedb45 /debuggerd/backtrace.cpp | |
parent | f483354e592c9edd836acbc0fffcedfb6958c889 (diff) | |
download | system_core-c764dcd6977a04e272e44b0381c13ac4aed8a280.tar.gz system_core-c764dcd6977a04e272e44b0381c13ac4aed8a280.tar.bz2 system_core-c764dcd6977a04e272e44b0381c13ac4aed8a280.zip |
DO NOT MERGE: debuggerd: verify that traced threads belong to the right process.
Fix two races in debuggerd's PTRACE_ATTACH logic:
1. The target thread in a crash dump request could exit between the
/proc/<pid>/task/<tid> check and the PTRACE_ATTACH.
2. Sibling threads could exit between listing /proc/<pid>/task and the
PTRACE_ATTACH.
Backport of NYC change I4dfe1ea30e2c211d2389321bd66e3684dd757591
Bug: http://b/29555636
Change-Id: I6c6efcf82a49bca140d761b2d1de04215ba4d252
Diffstat (limited to 'debuggerd/backtrace.cpp')
-rw-r--r-- | debuggerd/backtrace.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/debuggerd/backtrace.cpp b/debuggerd/backtrace.cpp index b8084c517..ad6a6ee61 100644 --- a/debuggerd/backtrace.cpp +++ b/debuggerd/backtrace.cpp @@ -67,8 +67,8 @@ static void dump_process_footer(log_t* log, pid_t pid) { _LOG(log, logtype::BACKTRACE, "\n----- end %d -----\n", pid); } -static void dump_thread( - log_t* log, pid_t tid, bool attached, bool* detach_failed, int* total_sleep_time_usec) { +static void dump_thread(log_t* log, pid_t pid, pid_t tid, bool attached, + bool* detach_failed, int* total_sleep_time_usec) { char path[PATH_MAX]; char threadnamebuf[1024]; char* threadname = NULL; @@ -88,7 +88,7 @@ static void dump_thread( _LOG(log, logtype::BACKTRACE, "\n\"%s\" sysTid=%d\n", threadname ? threadname : "<unknown>", tid); - if (!attached && ptrace(PTRACE_ATTACH, tid, 0, 0) < 0) { + if (!attached && !ptrace_attach_thread(pid, tid)) { _LOG(log, logtype::BACKTRACE, "Could not attach to thread: %s\n", strerror(errno)); return; } @@ -117,7 +117,7 @@ void dump_backtrace(int fd, int amfd, pid_t pid, pid_t tid, bool* detach_failed, log.amfd = amfd; dump_process_header(&log, pid); - dump_thread(&log, tid, true, detach_failed, total_sleep_time_usec); + dump_thread(&log, pid, tid, true, detach_failed, total_sleep_time_usec); char task_path[64]; snprintf(task_path, sizeof(task_path), "/proc/%d/task", pid); @@ -135,7 +135,7 @@ void dump_backtrace(int fd, int amfd, pid_t pid, pid_t tid, bool* detach_failed, continue; } - dump_thread(&log, new_tid, false, detach_failed, total_sleep_time_usec); + dump_thread(&log, pid, new_tid, false, detach_failed, total_sleep_time_usec); } closedir(d); } |