summaryrefslogtreecommitdiffstats
path: root/debuggerd/crash_dump.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-03-15 23:23:22 -0700
committerJosh Gao <jmgao@google.com>2017-03-15 23:30:14 -0700
commit57f58f8e4a143f1208593c8b397b9a17d055dad0 (patch)
tree6760dea6ea2582cf8edfc527a0addf525142fca6 /debuggerd/crash_dump.cpp
parente7b335b4712bc650c93b5b5777a6f8b1d85ad83f (diff)
downloadcore-57f58f8e4a143f1208593c8b397b9a17d055dad0.tar.gz
core-57f58f8e4a143f1208593c8b397b9a17d055dad0.tar.bz2
core-57f58f8e4a143f1208593c8b397b9a17d055dad0.zip
crash_dump: fetch process/thread names before dropping privileges.
Processes that don't have dumpable set to 1 cannot have their process/thread names read by processes that don't have all of their capabilities. Fetch these names in crash_dump before dropping privileges. Bug: http://b/36237221 Test: debuggerd_test Test: debuggerd -b `pidof android.hardware.bluetooth@1.0-service` Change-Id: I174769e7b3c1ea9f11f9c8cbdff83028a4225783
Diffstat (limited to 'debuggerd/crash_dump.cpp')
-rw-r--r--debuggerd/crash_dump.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp
index 38b711ff4..88f390b0e 100644
--- a/debuggerd/crash_dump.cpp
+++ b/debuggerd/crash_dump.cpp
@@ -27,6 +27,7 @@
#include <unistd.h>
#include <limits>
+#include <map>
#include <memory>
#include <set>
#include <vector>
@@ -36,6 +37,7 @@
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <cutils/sockets.h>
#include <log/log.h>
@@ -52,7 +54,21 @@
#include "debuggerd/util.h"
using android::base::unique_fd;
+using android::base::ReadFileToString;
using android::base::StringPrintf;
+using android::base::Trim;
+
+static std::string get_process_name(pid_t pid) {
+ std::string result = "<unknown>";
+ ReadFileToString(StringPrintf("/proc/%d/cmdline", pid), &result);
+ return result;
+}
+
+static std::string get_thread_name(pid_t tid) {
+ std::string result = "<unknown>";
+ ReadFileToString(StringPrintf("/proc/%d/comm", tid), &result);
+ return Trim(result);
+}
static bool pid_contains_tid(int pid_proc_fd, pid_t tid) {
struct stat st;
@@ -253,7 +269,7 @@ int main(int argc, char** argv) {
}
// Seize the siblings.
- std::set<pid_t> attached_siblings;
+ std::map<pid_t, std::string> threads;
{
std::set<pid_t> siblings;
if (!android::procinfo::GetProcessTids(target, &siblings)) {
@@ -269,12 +285,12 @@ int main(int argc, char** argv) {
if (!ptrace_seize_thread(target_proc_fd, sibling_tid, &attach_error)) {
LOG(WARNING) << attach_error;
} else {
- attached_siblings.insert(sibling_tid);
+ threads.emplace(sibling_tid, get_thread_name(sibling_tid));
}
}
}
- // Collect the backtrace map and open files, while the process still has PR_GET_DUMPABLE=1
+ // Collect the backtrace map, open files, and process/thread names, while we still have caps.
std::unique_ptr<BacktraceMap> backtrace_map(BacktraceMap::Create(main_tid));
if (!backtrace_map) {
LOG(FATAL) << "failed to create backtrace map";
@@ -284,6 +300,9 @@ int main(int argc, char** argv) {
OpenFilesList open_files;
populate_open_files_list(target, &open_files);
+ std::string process_name = get_process_name(main_tid);
+ threads.emplace(main_tid, get_thread_name(main_tid));
+
// Drop our capabilities now that we've attached to the threads we care about.
drop_capabilities();
@@ -341,10 +360,10 @@ int main(int argc, char** argv) {
std::string amfd_data;
if (backtrace) {
- dump_backtrace(output_fd.get(), backtrace_map.get(), target, main_tid, attached_siblings, 0);
+ dump_backtrace(output_fd.get(), backtrace_map.get(), target, main_tid, process_name, threads, 0);
} else {
engrave_tombstone(output_fd.get(), backtrace_map.get(), &open_files, target, main_tid,
- &attached_siblings, abort_address, fatal_signal ? &amfd_data : nullptr);
+ process_name, threads, abort_address, fatal_signal ? &amfd_data : nullptr);
}
// We don't actually need to PTRACE_DETACH, as long as our tracees aren't in