diff options
author | Josh Gao <jmgao@google.com> | 2017-05-04 17:12:57 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2017-05-05 14:58:12 -0700 |
commit | 2e7b8e2d1aff139895127a93c020bddb98a0f26e (patch) | |
tree | 048c949d533b6c7e3d796b224eab2e1519a402d4 /debuggerd/debuggerd_test.cpp | |
parent | 8fad110bfa18b962b8c6e3a25297970a0febe1f2 (diff) |
debuggerd_handler: use syscall(__NR_get[pt]id) instead of get[pt]id.
bionic's cached values for getpid/gettid can be invalid if the crashing
process manually invoked clone to create a thread or process, which
will lead the crash_dump refusing to do anything, because it sees the
actual values.
Use the getpid/gettid syscalls directly to ensure correct values on
this end.
Bug: http://b/37769298
Test: debuggerd_test
Change-Id: I0b1e652beb1a66e564a48b88ed7fa971d61c6ff9
Diffstat (limited to 'debuggerd/debuggerd_test.cpp')
-rw-r--r-- | debuggerd/debuggerd_test.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index 568879ed5..0b4bbfb60 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -29,6 +29,7 @@ #include <android-base/file.h> #include <android-base/logging.h> +#include <android-base/macros.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/strings.h> @@ -149,7 +150,7 @@ class CrasherTest : public ::testing::Test { // Returns -1 if we fail to read a response from tombstoned, otherwise the received return code. void FinishIntercept(int* result); - void StartProcess(std::function<void()> function); + void StartProcess(std::function<void()> function, std::function<pid_t()> forker = fork); void StartCrasher(const std::string& crash_type); void FinishCrasher(); void AssertDeath(int signo); @@ -195,14 +196,14 @@ void CrasherTest::FinishIntercept(int* result) { } } -void CrasherTest::StartProcess(std::function<void()> function) { +void CrasherTest::StartProcess(std::function<void()> function, std::function<pid_t()> forker) { unique_fd read_pipe; unique_fd crasher_read_pipe; if (!Pipe(&crasher_read_pipe, &crasher_pipe)) { FAIL() << "failed to create pipe: " << strerror(errno); } - crasher_pid = fork(); + crasher_pid = forker(); if (crasher_pid == -1) { FAIL() << "fork failed: " << strerror(errno); } else if (crasher_pid == 0) { @@ -527,6 +528,37 @@ TEST_F(CrasherTest, capabilities) { ASSERT_MATCH(result, R"(#00 pc [0-9a-f]+\s+ /system/lib)" ARCH_SUFFIX R"(/libc.so \(tgkill)"); } +TEST_F(CrasherTest, fake_pid) { + int intercept_result; + unique_fd output_fd; + + // Prime the getpid/gettid caches. + UNUSED(getpid()); + UNUSED(gettid()); + + std::function<pid_t()> clone_fn = []() { + return syscall(__NR_clone, SIGCHLD, nullptr, nullptr, nullptr, nullptr); + }; + StartProcess( + []() { + ASSERT_NE(getpid(), syscall(__NR_getpid)); + ASSERT_NE(gettid(), syscall(__NR_gettid)); + raise(SIGSEGV); + }, + clone_fn); + + StartIntercept(&output_fd); + FinishCrasher(); + AssertDeath(SIGSEGV); + FinishIntercept(&intercept_result); + + ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; + + std::string result; + ConsumeFd(std::move(output_fd), &result); + ASSERT_MATCH(result, R"(#00 pc [0-9a-f]+\s+ /system/lib)" ARCH_SUFFIX R"(/libc.so \(tgkill)"); +} + TEST(crash_dump, zombie) { pid_t forkpid = fork(); |