Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <err.h> |
| 18 | #include <fcntl.h> |
Josh Gao | cdea750 | 2017-11-01 15:00:40 -0700 | [diff] [blame] | 19 | #include <stdlib.h> |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 20 | #include <sys/capability.h> |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 21 | #include <sys/prctl.h> |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 22 | #include <sys/ptrace.h> |
Josh Gao | 70adac6 | 2018-02-22 11:38:33 -0800 | [diff] [blame] | 23 | #include <sys/resource.h> |
Dan Albert | c38057a | 2017-10-11 11:35:40 -0700 | [diff] [blame] | 24 | #include <sys/syscall.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 25 | #include <sys/types.h> |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 26 | #include <unistd.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 27 | |
| 28 | #include <chrono> |
| 29 | #include <regex> |
| 30 | #include <thread> |
| 31 | |
Josh Gao | bf06a40 | 2018-08-27 16:34:01 -0700 | [diff] [blame] | 32 | #include <android/fdsan.h> |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 33 | #include <android/set_abort_message.h> |
| 34 | |
Josh Gao | 5f87bbd | 2019-01-09 17:01:49 -0800 | [diff] [blame] | 35 | #include <android-base/cmsg.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 36 | #include <android-base/file.h> |
| 37 | #include <android-base/logging.h> |
Josh Gao | 2e7b8e2 | 2017-05-04 17:12:57 -0700 | [diff] [blame] | 38 | #include <android-base/macros.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 39 | #include <android-base/parseint.h> |
| 40 | #include <android-base/properties.h> |
Josh Gao | 2b22ae1 | 2018-09-12 14:51:03 -0700 | [diff] [blame] | 41 | #include <android-base/stringprintf.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 42 | #include <android-base/strings.h> |
Josh Gao | 30171a8 | 2017-04-27 19:48:44 -0700 | [diff] [blame] | 43 | #include <android-base/test_utils.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 44 | #include <android-base/unique_fd.h> |
| 45 | #include <cutils/sockets.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 46 | #include <gtest/gtest.h> |
| 47 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 48 | #include <libminijail.h> |
| 49 | #include <scoped_minijail.h> |
| 50 | |
Narayan Kamath | 2d377cd | 2017-05-10 10:58:59 +0100 | [diff] [blame] | 51 | #include "debuggerd/handler.h" |
| 52 | #include "protocol.h" |
| 53 | #include "tombstoned/tombstoned.h" |
| 54 | #include "util.h" |
| 55 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 56 | using namespace std::chrono_literals; |
Josh Gao | 5f87bbd | 2019-01-09 17:01:49 -0800 | [diff] [blame] | 57 | |
| 58 | using android::base::SendFileDescriptors; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 59 | using android::base::unique_fd; |
| 60 | |
| 61 | #if defined(__LP64__) |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 62 | #define ARCH_SUFFIX "64" |
| 63 | #else |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 64 | #define ARCH_SUFFIX "" |
| 65 | #endif |
| 66 | |
| 67 | constexpr char kWaitForGdbKey[] = "debug.debuggerd.wait_for_gdb"; |
| 68 | |
| 69 | #define TIMEOUT(seconds, expr) \ |
| 70 | [&]() { \ |
| 71 | struct sigaction old_sigaction; \ |
| 72 | struct sigaction new_sigaction = {}; \ |
| 73 | new_sigaction.sa_handler = [](int) {}; \ |
| 74 | if (sigaction(SIGALRM, &new_sigaction, &new_sigaction) != 0) { \ |
| 75 | err(1, "sigaction failed"); \ |
| 76 | } \ |
| 77 | alarm(seconds); \ |
| 78 | auto value = expr; \ |
| 79 | int saved_errno = errno; \ |
| 80 | if (sigaction(SIGALRM, &old_sigaction, nullptr) != 0) { \ |
| 81 | err(1, "sigaction failed"); \ |
| 82 | } \ |
| 83 | alarm(0); \ |
| 84 | errno = saved_errno; \ |
| 85 | return value; \ |
| 86 | }() |
| 87 | |
Chih-Hung Hsieh | 3249b3a | 2018-05-11 16:01:21 -0700 | [diff] [blame] | 88 | // Backtrace frame dump could contain: |
| 89 | // #01 pc 0001cded /data/tmp/debuggerd_test32 (raise_debugger_signal+80) |
| 90 | // or |
| 91 | // #01 pc 00022a09 /data/tmp/debuggerd_test32 (offset 0x12000) (raise_debugger_signal+80) |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 92 | #define ASSERT_BACKTRACE_FRAME(result, frame_name) \ |
Chih-Hung Hsieh | 3249b3a | 2018-05-11 16:01:21 -0700 | [diff] [blame] | 93 | ASSERT_MATCH(result, \ |
| 94 | R"(#\d\d pc [0-9a-f]+\s+ \S+ (\(offset 0x[0-9a-f]+\) )?\()" frame_name R"(\+)"); |
Jaesung Chung | 58778e1 | 2017-06-15 18:20:34 +0900 | [diff] [blame] | 95 | |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 96 | static void tombstoned_intercept(pid_t target_pid, unique_fd* intercept_fd, unique_fd* output_fd, |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 97 | InterceptStatus* status, DebuggerdDumpType intercept_type) { |
Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 98 | intercept_fd->reset(socket_local_client(kTombstonedInterceptSocketName, |
| 99 | ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET)); |
| 100 | if (intercept_fd->get() == -1) { |
| 101 | FAIL() << "failed to contact tombstoned: " << strerror(errno); |
| 102 | } |
| 103 | |
Nick Desaulniers | 67d52aa | 2019-10-07 23:28:15 -0700 | [diff] [blame^] | 104 | InterceptRequest req = { |
| 105 | .dump_type = intercept_type, |
| 106 | .pid = target_pid, |
| 107 | }; |
Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 108 | |
| 109 | unique_fd output_pipe_write; |
| 110 | if (!Pipe(output_fd, &output_pipe_write)) { |
| 111 | FAIL() << "failed to create output pipe: " << strerror(errno); |
| 112 | } |
| 113 | |
| 114 | std::string pipe_size_str; |
| 115 | int pipe_buffer_size; |
| 116 | if (!android::base::ReadFileToString("/proc/sys/fs/pipe-max-size", &pipe_size_str)) { |
| 117 | FAIL() << "failed to read /proc/sys/fs/pipe-max-size: " << strerror(errno); |
| 118 | } |
| 119 | |
| 120 | pipe_size_str = android::base::Trim(pipe_size_str); |
| 121 | |
| 122 | if (!android::base::ParseInt(pipe_size_str.c_str(), &pipe_buffer_size, 0)) { |
| 123 | FAIL() << "failed to parse pipe max size"; |
| 124 | } |
| 125 | |
| 126 | if (fcntl(output_fd->get(), F_SETPIPE_SZ, pipe_buffer_size) != pipe_buffer_size) { |
| 127 | FAIL() << "failed to set pipe size: " << strerror(errno); |
| 128 | } |
| 129 | |
Josh Gao | 5675f3c | 2017-06-01 12:19:53 -0700 | [diff] [blame] | 130 | ASSERT_GE(pipe_buffer_size, 1024 * 1024); |
| 131 | |
Josh Gao | 5f87bbd | 2019-01-09 17:01:49 -0800 | [diff] [blame] | 132 | ssize_t rc = SendFileDescriptors(intercept_fd->get(), &req, sizeof(req), output_pipe_write.get()); |
| 133 | output_pipe_write.reset(); |
| 134 | if (rc != sizeof(req)) { |
Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 135 | FAIL() << "failed to send output fd to tombstoned: " << strerror(errno); |
| 136 | } |
| 137 | |
| 138 | InterceptResponse response; |
Josh Gao | 5f87bbd | 2019-01-09 17:01:49 -0800 | [diff] [blame] | 139 | rc = TEMP_FAILURE_RETRY(read(intercept_fd->get(), &response, sizeof(response))); |
Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 140 | if (rc == -1) { |
| 141 | FAIL() << "failed to read response from tombstoned: " << strerror(errno); |
| 142 | } else if (rc == 0) { |
| 143 | FAIL() << "failed to read response from tombstoned (EOF)"; |
| 144 | } else if (rc != sizeof(response)) { |
| 145 | FAIL() << "received packet of unexpected length from tombstoned: expected " << sizeof(response) |
| 146 | << ", received " << rc; |
| 147 | } |
| 148 | |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 149 | *status = response.status; |
Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 152 | class CrasherTest : public ::testing::Test { |
| 153 | public: |
| 154 | pid_t crasher_pid = -1; |
| 155 | bool previous_wait_for_gdb; |
| 156 | unique_fd crasher_pipe; |
| 157 | unique_fd intercept_fd; |
| 158 | |
| 159 | CrasherTest(); |
| 160 | ~CrasherTest(); |
| 161 | |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 162 | void StartIntercept(unique_fd* output_fd, DebuggerdDumpType intercept_type = kDebuggerdTombstone); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 163 | |
| 164 | // Returns -1 if we fail to read a response from tombstoned, otherwise the received return code. |
| 165 | void FinishIntercept(int* result); |
| 166 | |
Josh Gao | 2e7b8e2 | 2017-05-04 17:12:57 -0700 | [diff] [blame] | 167 | void StartProcess(std::function<void()> function, std::function<pid_t()> forker = fork); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 168 | void StartCrasher(const std::string& crash_type); |
| 169 | void FinishCrasher(); |
| 170 | void AssertDeath(int signo); |
| 171 | }; |
| 172 | |
| 173 | CrasherTest::CrasherTest() { |
| 174 | previous_wait_for_gdb = android::base::GetBoolProperty(kWaitForGdbKey, false); |
| 175 | android::base::SetProperty(kWaitForGdbKey, "0"); |
| 176 | } |
| 177 | |
| 178 | CrasherTest::~CrasherTest() { |
| 179 | if (crasher_pid != -1) { |
| 180 | kill(crasher_pid, SIGKILL); |
| 181 | int status; |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 182 | TEMP_FAILURE_RETRY(waitpid(crasher_pid, &status, WUNTRACED)); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | android::base::SetProperty(kWaitForGdbKey, previous_wait_for_gdb ? "1" : "0"); |
| 186 | } |
| 187 | |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 188 | void CrasherTest::StartIntercept(unique_fd* output_fd, DebuggerdDumpType intercept_type) { |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 189 | if (crasher_pid == -1) { |
| 190 | FAIL() << "crasher hasn't been started"; |
| 191 | } |
| 192 | |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 193 | InterceptStatus status; |
| 194 | tombstoned_intercept(crasher_pid, &this->intercept_fd, output_fd, &status, intercept_type); |
| 195 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void CrasherTest::FinishIntercept(int* result) { |
| 199 | InterceptResponse response; |
| 200 | |
Christopher Ferris | 11555f0 | 2019-09-20 14:18:55 -0700 | [diff] [blame] | 201 | ssize_t rc = TIMEOUT(30, read(intercept_fd.get(), &response, sizeof(response))); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 202 | if (rc == -1) { |
| 203 | FAIL() << "failed to read response from tombstoned: " << strerror(errno); |
| 204 | } else if (rc == 0) { |
| 205 | *result = -1; |
| 206 | } else if (rc != sizeof(response)) { |
| 207 | FAIL() << "received packet of unexpected length from tombstoned: expected " << sizeof(response) |
| 208 | << ", received " << rc; |
| 209 | } else { |
Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 210 | *result = response.status == InterceptStatus::kStarted ? 1 : 0; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Josh Gao | 2e7b8e2 | 2017-05-04 17:12:57 -0700 | [diff] [blame] | 214 | void CrasherTest::StartProcess(std::function<void()> function, std::function<pid_t()> forker) { |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 215 | unique_fd read_pipe; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 216 | unique_fd crasher_read_pipe; |
| 217 | if (!Pipe(&crasher_read_pipe, &crasher_pipe)) { |
| 218 | FAIL() << "failed to create pipe: " << strerror(errno); |
| 219 | } |
| 220 | |
Josh Gao | 2e7b8e2 | 2017-05-04 17:12:57 -0700 | [diff] [blame] | 221 | crasher_pid = forker(); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 222 | if (crasher_pid == -1) { |
| 223 | FAIL() << "fork failed: " << strerror(errno); |
| 224 | } else if (crasher_pid == 0) { |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 225 | char dummy; |
| 226 | crasher_pipe.reset(); |
| 227 | TEMP_FAILURE_RETRY(read(crasher_read_pipe.get(), &dummy, 1)); |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 228 | function(); |
| 229 | _exit(0); |
| 230 | } |
| 231 | } |
| 232 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 233 | void CrasherTest::FinishCrasher() { |
| 234 | if (crasher_pipe == -1) { |
| 235 | FAIL() << "crasher pipe uninitialized"; |
| 236 | } |
| 237 | |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 238 | ssize_t rc = TEMP_FAILURE_RETRY(write(crasher_pipe.get(), "\n", 1)); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 239 | if (rc == -1) { |
| 240 | FAIL() << "failed to write to crasher pipe: " << strerror(errno); |
| 241 | } else if (rc == 0) { |
| 242 | FAIL() << "crasher pipe was closed"; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | void CrasherTest::AssertDeath(int signo) { |
| 247 | int status; |
Christopher Ferris | 11555f0 | 2019-09-20 14:18:55 -0700 | [diff] [blame] | 248 | pid_t pid = TIMEOUT(30, waitpid(crasher_pid, &status, 0)); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 249 | if (pid != crasher_pid) { |
Christopher Ferris | afc0ff7 | 2019-06-26 15:08:51 -0700 | [diff] [blame] | 250 | printf("failed to wait for crasher (expected pid %d, return value %d): %s\n", crasher_pid, pid, |
| 251 | strerror(errno)); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 252 | sleep(100); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 253 | FAIL() << "failed to wait for crasher: " << strerror(errno); |
| 254 | } |
| 255 | |
Josh Gao | e06f2a4 | 2017-04-27 16:50:38 -0700 | [diff] [blame] | 256 | if (signo == 0) { |
| 257 | ASSERT_TRUE(WIFEXITED(status)); |
| 258 | ASSERT_EQ(0, WEXITSTATUS(signo)); |
| 259 | } else { |
| 260 | ASSERT_FALSE(WIFEXITED(status)); |
| 261 | ASSERT_TRUE(WIFSIGNALED(status)) << "crasher didn't terminate via a signal"; |
| 262 | ASSERT_EQ(signo, WTERMSIG(status)); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 263 | } |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 264 | crasher_pid = -1; |
| 265 | } |
| 266 | |
| 267 | static void ConsumeFd(unique_fd fd, std::string* output) { |
| 268 | constexpr size_t read_length = PAGE_SIZE; |
| 269 | std::string result; |
| 270 | |
| 271 | while (true) { |
| 272 | size_t offset = result.size(); |
| 273 | result.resize(result.size() + PAGE_SIZE); |
| 274 | ssize_t rc = TEMP_FAILURE_RETRY(read(fd.get(), &result[offset], read_length)); |
| 275 | if (rc == -1) { |
| 276 | FAIL() << "read failed: " << strerror(errno); |
| 277 | } else if (rc == 0) { |
| 278 | result.resize(result.size() - PAGE_SIZE); |
| 279 | break; |
| 280 | } |
| 281 | |
| 282 | result.resize(result.size() - PAGE_SIZE + rc); |
| 283 | } |
| 284 | |
| 285 | *output = std::move(result); |
| 286 | } |
| 287 | |
| 288 | TEST_F(CrasherTest, smoke) { |
| 289 | int intercept_result; |
| 290 | unique_fd output_fd; |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 291 | StartProcess([]() { |
| 292 | *reinterpret_cast<volatile char*>(0xdead) = '1'; |
| 293 | }); |
| 294 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 295 | StartIntercept(&output_fd); |
| 296 | FinishCrasher(); |
| 297 | AssertDeath(SIGSEGV); |
| 298 | FinishIntercept(&intercept_result); |
| 299 | |
| 300 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 301 | |
| 302 | std::string result; |
| 303 | ConsumeFd(std::move(output_fd), &result); |
| 304 | ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0xdead)"); |
| 305 | } |
| 306 | |
Josh Gao | cdea750 | 2017-11-01 15:00:40 -0700 | [diff] [blame] | 307 | TEST_F(CrasherTest, LD_PRELOAD) { |
| 308 | int intercept_result; |
| 309 | unique_fd output_fd; |
| 310 | StartProcess([]() { |
| 311 | setenv("LD_PRELOAD", "nonexistent.so", 1); |
| 312 | *reinterpret_cast<volatile char*>(0xdead) = '1'; |
| 313 | }); |
| 314 | |
| 315 | StartIntercept(&output_fd); |
| 316 | FinishCrasher(); |
| 317 | AssertDeath(SIGSEGV); |
| 318 | FinishIntercept(&intercept_result); |
| 319 | |
| 320 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 321 | |
| 322 | std::string result; |
| 323 | ConsumeFd(std::move(output_fd), &result); |
| 324 | ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0xdead)"); |
| 325 | } |
| 326 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 327 | TEST_F(CrasherTest, abort) { |
| 328 | int intercept_result; |
| 329 | unique_fd output_fd; |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 330 | StartProcess([]() { |
| 331 | abort(); |
| 332 | }); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 333 | StartIntercept(&output_fd); |
| 334 | FinishCrasher(); |
| 335 | AssertDeath(SIGABRT); |
| 336 | FinishIntercept(&intercept_result); |
| 337 | |
| 338 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 339 | |
| 340 | std::string result; |
| 341 | ConsumeFd(std::move(output_fd), &result); |
Andreas Gampe | 26cbafb | 2017-06-22 20:14:43 -0700 | [diff] [blame] | 342 | ASSERT_BACKTRACE_FRAME(result, "abort"); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | TEST_F(CrasherTest, signal) { |
| 346 | int intercept_result; |
| 347 | unique_fd output_fd; |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 348 | StartProcess([]() { |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 349 | while (true) { |
| 350 | sleep(1); |
| 351 | } |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 352 | }); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 353 | StartIntercept(&output_fd); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 354 | FinishCrasher(); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 355 | ASSERT_EQ(0, kill(crasher_pid, SIGSEGV)); |
| 356 | |
| 357 | AssertDeath(SIGSEGV); |
| 358 | FinishIntercept(&intercept_result); |
| 359 | |
| 360 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 361 | |
| 362 | std::string result; |
| 363 | ConsumeFd(std::move(output_fd), &result); |
Elliott Hughes | 8972270 | 2018-05-02 10:47:00 -0700 | [diff] [blame] | 364 | ASSERT_MATCH( |
| 365 | result, |
| 366 | R"(signal 11 \(SIGSEGV\), code 0 \(SI_USER from pid \d+, uid \d+\), fault addr --------)"); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 367 | ASSERT_MATCH(result, R"(backtrace:)"); |
| 368 | } |
| 369 | |
| 370 | TEST_F(CrasherTest, abort_message) { |
| 371 | int intercept_result; |
| 372 | unique_fd output_fd; |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 373 | StartProcess([]() { |
Josh Gao | 1cc7bd8 | 2018-02-13 13:16:17 -0800 | [diff] [blame] | 374 | // Arrived at experimentally; |
| 375 | // logd truncates at 4062. |
| 376 | // strlen("Abort message: ''") is 17. |
| 377 | // That's 4045, but we also want a NUL. |
| 378 | char buf[4045 + 1]; |
| 379 | memset(buf, 'x', sizeof(buf)); |
| 380 | buf[sizeof(buf) - 1] = '\0'; |
| 381 | android_set_abort_message(buf); |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 382 | abort(); |
| 383 | }); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 384 | StartIntercept(&output_fd); |
| 385 | FinishCrasher(); |
| 386 | AssertDeath(SIGABRT); |
| 387 | FinishIntercept(&intercept_result); |
| 388 | |
| 389 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 390 | |
| 391 | std::string result; |
| 392 | ConsumeFd(std::move(output_fd), &result); |
Josh Gao | 1cc7bd8 | 2018-02-13 13:16:17 -0800 | [diff] [blame] | 393 | ASSERT_MATCH(result, R"(Abort message: 'x{4045}')"); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Josh Gao | e06f2a4 | 2017-04-27 16:50:38 -0700 | [diff] [blame] | 396 | TEST_F(CrasherTest, abort_message_backtrace) { |
| 397 | int intercept_result; |
| 398 | unique_fd output_fd; |
| 399 | StartProcess([]() { |
| 400 | android_set_abort_message("not actually aborting"); |
| 401 | raise(DEBUGGER_SIGNAL); |
| 402 | exit(0); |
| 403 | }); |
| 404 | StartIntercept(&output_fd); |
| 405 | FinishCrasher(); |
| 406 | AssertDeath(0); |
| 407 | FinishIntercept(&intercept_result); |
| 408 | |
| 409 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 410 | |
| 411 | std::string result; |
| 412 | ConsumeFd(std::move(output_fd), &result); |
| 413 | ASSERT_NOT_MATCH(result, R"(Abort message:)"); |
| 414 | } |
| 415 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 416 | TEST_F(CrasherTest, intercept_timeout) { |
| 417 | int intercept_result; |
| 418 | unique_fd output_fd; |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 419 | StartProcess([]() { |
| 420 | abort(); |
| 421 | }); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 422 | StartIntercept(&output_fd); |
| 423 | |
| 424 | // Don't let crasher finish until we timeout. |
| 425 | FinishIntercept(&intercept_result); |
| 426 | |
| 427 | ASSERT_NE(1, intercept_result) << "tombstoned reported success? (intercept_result = " |
| 428 | << intercept_result << ")"; |
| 429 | |
| 430 | FinishCrasher(); |
| 431 | AssertDeath(SIGABRT); |
| 432 | } |
| 433 | |
| 434 | TEST_F(CrasherTest, wait_for_gdb) { |
| 435 | if (!android::base::SetProperty(kWaitForGdbKey, "1")) { |
| 436 | FAIL() << "failed to enable wait_for_gdb"; |
| 437 | } |
| 438 | sleep(1); |
| 439 | |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 440 | StartProcess([]() { |
| 441 | abort(); |
| 442 | }); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 443 | FinishCrasher(); |
| 444 | |
| 445 | int status; |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 446 | ASSERT_EQ(crasher_pid, TEMP_FAILURE_RETRY(waitpid(crasher_pid, &status, WUNTRACED))); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 447 | ASSERT_TRUE(WIFSTOPPED(status)); |
| 448 | ASSERT_EQ(SIGSTOP, WSTOPSIG(status)); |
| 449 | |
| 450 | ASSERT_EQ(0, kill(crasher_pid, SIGCONT)); |
| 451 | |
| 452 | AssertDeath(SIGABRT); |
| 453 | } |
| 454 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 455 | TEST_F(CrasherTest, backtrace) { |
| 456 | std::string result; |
| 457 | int intercept_result; |
| 458 | unique_fd output_fd; |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 459 | |
| 460 | StartProcess([]() { |
| 461 | abort(); |
| 462 | }); |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 463 | StartIntercept(&output_fd, kDebuggerdNativeBacktrace); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 464 | |
| 465 | std::this_thread::sleep_for(500ms); |
| 466 | |
| 467 | sigval val; |
| 468 | val.sival_int = 1; |
| 469 | ASSERT_EQ(0, sigqueue(crasher_pid, DEBUGGER_SIGNAL, val)) << strerror(errno); |
| 470 | FinishIntercept(&intercept_result); |
| 471 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 472 | ConsumeFd(std::move(output_fd), &result); |
Jaesung Chung | 58778e1 | 2017-06-15 18:20:34 +0900 | [diff] [blame] | 473 | ASSERT_BACKTRACE_FRAME(result, "read"); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 474 | |
| 475 | int status; |
| 476 | ASSERT_EQ(0, waitpid(crasher_pid, &status, WNOHANG | WUNTRACED)); |
| 477 | |
| 478 | StartIntercept(&output_fd); |
| 479 | FinishCrasher(); |
| 480 | AssertDeath(SIGABRT); |
| 481 | FinishIntercept(&intercept_result); |
| 482 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 483 | ConsumeFd(std::move(output_fd), &result); |
Andreas Gampe | 26cbafb | 2017-06-22 20:14:43 -0700 | [diff] [blame] | 484 | ASSERT_BACKTRACE_FRAME(result, "abort"); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 485 | } |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 486 | |
| 487 | TEST_F(CrasherTest, PR_SET_DUMPABLE_0_crash) { |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 488 | int intercept_result; |
| 489 | unique_fd output_fd; |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 490 | StartProcess([]() { |
| 491 | prctl(PR_SET_DUMPABLE, 0); |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 492 | abort(); |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 493 | }); |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 494 | |
| 495 | StartIntercept(&output_fd); |
| 496 | FinishCrasher(); |
| 497 | AssertDeath(SIGABRT); |
| 498 | FinishIntercept(&intercept_result); |
| 499 | |
| 500 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 501 | |
| 502 | std::string result; |
| 503 | ConsumeFd(std::move(output_fd), &result); |
Andreas Gampe | 26cbafb | 2017-06-22 20:14:43 -0700 | [diff] [blame] | 504 | ASSERT_BACKTRACE_FRAME(result, "abort"); |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 507 | TEST_F(CrasherTest, capabilities) { |
| 508 | ASSERT_EQ(0U, getuid()) << "capability test requires root"; |
| 509 | |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 510 | StartProcess([]() { |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 511 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) { |
| 512 | err(1, "failed to set PR_SET_KEEPCAPS"); |
| 513 | } |
| 514 | |
| 515 | if (setresuid(1, 1, 1) != 0) { |
| 516 | err(1, "setresuid failed"); |
| 517 | } |
| 518 | |
| 519 | __user_cap_header_struct capheader; |
| 520 | __user_cap_data_struct capdata[2]; |
| 521 | memset(&capheader, 0, sizeof(capheader)); |
| 522 | memset(&capdata, 0, sizeof(capdata)); |
| 523 | |
| 524 | capheader.version = _LINUX_CAPABILITY_VERSION_3; |
| 525 | capheader.pid = 0; |
| 526 | |
| 527 | // Turn on every third capability. |
| 528 | static_assert(CAP_LAST_CAP > 33, "CAP_LAST_CAP <= 32"); |
| 529 | for (int i = 0; i < CAP_LAST_CAP; i += 3) { |
| 530 | capdata[CAP_TO_INDEX(i)].permitted |= CAP_TO_MASK(i); |
| 531 | capdata[CAP_TO_INDEX(i)].effective |= CAP_TO_MASK(i); |
| 532 | } |
| 533 | |
| 534 | // Make sure CAP_SYS_PTRACE is off. |
| 535 | capdata[CAP_TO_INDEX(CAP_SYS_PTRACE)].permitted &= ~(CAP_TO_MASK(CAP_SYS_PTRACE)); |
| 536 | capdata[CAP_TO_INDEX(CAP_SYS_PTRACE)].effective &= ~(CAP_TO_MASK(CAP_SYS_PTRACE)); |
| 537 | |
| 538 | if (capset(&capheader, &capdata[0]) != 0) { |
| 539 | err(1, "capset failed"); |
| 540 | } |
| 541 | |
| 542 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0) != 0) { |
| 543 | err(1, "failed to drop ambient capabilities"); |
| 544 | } |
| 545 | |
Josh Gao | a5199a9 | 2017-04-03 13:18:34 -0700 | [diff] [blame] | 546 | pthread_setname_np(pthread_self(), "thread_name"); |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 547 | raise(SIGSYS); |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 548 | }); |
Josh Gao | 502cfd2 | 2017-02-17 01:39:15 -0800 | [diff] [blame] | 549 | |
| 550 | unique_fd output_fd; |
| 551 | StartIntercept(&output_fd); |
| 552 | FinishCrasher(); |
| 553 | AssertDeath(SIGSYS); |
| 554 | |
| 555 | std::string result; |
| 556 | int intercept_result; |
| 557 | FinishIntercept(&intercept_result); |
| 558 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 559 | ConsumeFd(std::move(output_fd), &result); |
Josh Gao | a5199a9 | 2017-04-03 13:18:34 -0700 | [diff] [blame] | 560 | ASSERT_MATCH(result, R"(name: thread_name\s+>>> .+debuggerd_test(32|64) <<<)"); |
Jaesung Chung | 58778e1 | 2017-06-15 18:20:34 +0900 | [diff] [blame] | 561 | ASSERT_BACKTRACE_FRAME(result, "tgkill"); |
Josh Gao | fca7ca3 | 2017-01-23 12:05:35 -0800 | [diff] [blame] | 562 | } |
Josh Gao | c3c8c02 | 2017-02-13 16:36:18 -0800 | [diff] [blame] | 563 | |
Josh Gao | 2e7b8e2 | 2017-05-04 17:12:57 -0700 | [diff] [blame] | 564 | TEST_F(CrasherTest, fake_pid) { |
| 565 | int intercept_result; |
| 566 | unique_fd output_fd; |
| 567 | |
| 568 | // Prime the getpid/gettid caches. |
| 569 | UNUSED(getpid()); |
| 570 | UNUSED(gettid()); |
| 571 | |
| 572 | std::function<pid_t()> clone_fn = []() { |
| 573 | return syscall(__NR_clone, SIGCHLD, nullptr, nullptr, nullptr, nullptr); |
| 574 | }; |
| 575 | StartProcess( |
| 576 | []() { |
| 577 | ASSERT_NE(getpid(), syscall(__NR_getpid)); |
| 578 | ASSERT_NE(gettid(), syscall(__NR_gettid)); |
| 579 | raise(SIGSEGV); |
| 580 | }, |
| 581 | clone_fn); |
| 582 | |
| 583 | StartIntercept(&output_fd); |
| 584 | FinishCrasher(); |
| 585 | AssertDeath(SIGSEGV); |
| 586 | FinishIntercept(&intercept_result); |
| 587 | |
| 588 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 589 | |
| 590 | std::string result; |
| 591 | ConsumeFd(std::move(output_fd), &result); |
Jaesung Chung | 58778e1 | 2017-06-15 18:20:34 +0900 | [diff] [blame] | 592 | ASSERT_BACKTRACE_FRAME(result, "tgkill"); |
Josh Gao | 2e7b8e2 | 2017-05-04 17:12:57 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 595 | static const char* const kDebuggerdSeccompPolicy = |
| 596 | "/system/etc/seccomp_policy/crash_dump." ABI_STRING ".policy"; |
| 597 | |
Josh Gao | 70adac6 | 2018-02-22 11:38:33 -0800 | [diff] [blame] | 598 | static pid_t seccomp_fork_impl(void (*prejail)()) { |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 599 | std::string policy; |
| 600 | if (!android::base::ReadFileToString(kDebuggerdSeccompPolicy, &policy)) { |
| 601 | PLOG(FATAL) << "failed to read policy file"; |
| 602 | } |
| 603 | |
| 604 | // Allow a bunch of syscalls used by the tests. |
| 605 | policy += "\nclone: 1"; |
| 606 | policy += "\nsigaltstack: 1"; |
| 607 | policy += "\nnanosleep: 1"; |
Christopher Ferris | ab60668 | 2019-09-17 15:31:47 -0700 | [diff] [blame] | 608 | policy += "\ngetrlimit: 1"; |
| 609 | policy += "\nugetrlimit: 1"; |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 610 | |
| 611 | FILE* tmp_file = tmpfile(); |
| 612 | if (!tmp_file) { |
| 613 | PLOG(FATAL) << "tmpfile failed"; |
| 614 | } |
| 615 | |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 616 | unique_fd tmp_fd(TEMP_FAILURE_RETRY(dup(fileno(tmp_file)))); |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 617 | if (!android::base::WriteStringToFd(policy, tmp_fd.get())) { |
| 618 | PLOG(FATAL) << "failed to write policy to tmpfile"; |
| 619 | } |
| 620 | |
| 621 | if (lseek(tmp_fd.get(), 0, SEEK_SET) != 0) { |
| 622 | PLOG(FATAL) << "failed to seek tmp_fd"; |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | ScopedMinijail jail{minijail_new()}; |
| 626 | if (!jail) { |
| 627 | LOG(FATAL) << "failed to create minijail"; |
| 628 | } |
| 629 | |
| 630 | minijail_no_new_privs(jail.get()); |
| 631 | minijail_log_seccomp_filter_failures(jail.get()); |
| 632 | minijail_use_seccomp_filter(jail.get()); |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 633 | minijail_parse_seccomp_filters_from_fd(jail.get(), tmp_fd.release()); |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 634 | |
| 635 | pid_t result = fork(); |
| 636 | if (result == -1) { |
| 637 | return result; |
| 638 | } else if (result != 0) { |
| 639 | return result; |
| 640 | } |
| 641 | |
| 642 | // Spawn and detach a thread that spins forever. |
| 643 | std::atomic<bool> thread_ready(false); |
| 644 | std::thread thread([&jail, &thread_ready]() { |
| 645 | minijail_enter(jail.get()); |
| 646 | thread_ready = true; |
| 647 | for (;;) |
| 648 | ; |
| 649 | }); |
| 650 | thread.detach(); |
| 651 | |
| 652 | while (!thread_ready) { |
| 653 | continue; |
| 654 | } |
| 655 | |
Josh Gao | 70adac6 | 2018-02-22 11:38:33 -0800 | [diff] [blame] | 656 | if (prejail) { |
| 657 | prejail(); |
| 658 | } |
| 659 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 660 | minijail_enter(jail.get()); |
| 661 | return result; |
| 662 | } |
| 663 | |
Josh Gao | 70adac6 | 2018-02-22 11:38:33 -0800 | [diff] [blame] | 664 | static pid_t seccomp_fork() { |
| 665 | return seccomp_fork_impl(nullptr); |
| 666 | } |
| 667 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 668 | TEST_F(CrasherTest, seccomp_crash) { |
| 669 | int intercept_result; |
| 670 | unique_fd output_fd; |
| 671 | |
| 672 | StartProcess([]() { abort(); }, &seccomp_fork); |
| 673 | |
| 674 | StartIntercept(&output_fd); |
| 675 | FinishCrasher(); |
| 676 | AssertDeath(SIGABRT); |
| 677 | FinishIntercept(&intercept_result); |
| 678 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 679 | |
| 680 | std::string result; |
| 681 | ConsumeFd(std::move(output_fd), &result); |
| 682 | ASSERT_BACKTRACE_FRAME(result, "abort"); |
| 683 | } |
| 684 | |
Josh Gao | 70adac6 | 2018-02-22 11:38:33 -0800 | [diff] [blame] | 685 | static pid_t seccomp_fork_rlimit() { |
| 686 | return seccomp_fork_impl([]() { |
| 687 | struct rlimit rlim = { |
| 688 | .rlim_cur = 512 * 1024 * 1024, |
| 689 | .rlim_max = 512 * 1024 * 1024, |
| 690 | }; |
| 691 | |
| 692 | if (setrlimit(RLIMIT_AS, &rlim) != 0) { |
| 693 | raise(SIGINT); |
| 694 | } |
| 695 | }); |
| 696 | } |
| 697 | |
| 698 | TEST_F(CrasherTest, seccomp_crash_oom) { |
| 699 | int intercept_result; |
| 700 | unique_fd output_fd; |
| 701 | |
| 702 | StartProcess( |
| 703 | []() { |
| 704 | std::vector<void*> vec; |
| 705 | for (int i = 0; i < 512; ++i) { |
| 706 | char* buf = static_cast<char*>(malloc(1024 * 1024)); |
| 707 | if (!buf) { |
| 708 | abort(); |
| 709 | } |
| 710 | memset(buf, 0xff, 1024 * 1024); |
| 711 | vec.push_back(buf); |
| 712 | } |
| 713 | }, |
| 714 | &seccomp_fork_rlimit); |
| 715 | |
| 716 | StartIntercept(&output_fd); |
| 717 | FinishCrasher(); |
| 718 | AssertDeath(SIGABRT); |
| 719 | FinishIntercept(&intercept_result); |
| 720 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 721 | |
| 722 | // We can't actually generate a backtrace, just make sure that the process terminates. |
| 723 | } |
| 724 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 725 | __attribute__((noinline)) extern "C" bool raise_debugger_signal(DebuggerdDumpType dump_type) { |
| 726 | siginfo_t siginfo; |
| 727 | siginfo.si_code = SI_QUEUE; |
| 728 | siginfo.si_pid = getpid(); |
| 729 | siginfo.si_uid = getuid(); |
| 730 | |
| 731 | if (dump_type != kDebuggerdNativeBacktrace && dump_type != kDebuggerdTombstone) { |
| 732 | PLOG(FATAL) << "invalid dump type"; |
| 733 | } |
| 734 | |
| 735 | siginfo.si_value.sival_int = dump_type == kDebuggerdNativeBacktrace; |
| 736 | |
| 737 | if (syscall(__NR_rt_tgsigqueueinfo, getpid(), gettid(), DEBUGGER_SIGNAL, &siginfo) != 0) { |
| 738 | PLOG(ERROR) << "libdebuggerd_client: failed to send signal to self"; |
| 739 | return false; |
| 740 | } |
| 741 | |
| 742 | return true; |
| 743 | } |
| 744 | |
| 745 | TEST_F(CrasherTest, seccomp_tombstone) { |
| 746 | int intercept_result; |
| 747 | unique_fd output_fd; |
| 748 | |
| 749 | static const auto dump_type = kDebuggerdTombstone; |
| 750 | StartProcess( |
| 751 | []() { |
| 752 | raise_debugger_signal(dump_type); |
| 753 | _exit(0); |
| 754 | }, |
| 755 | &seccomp_fork); |
| 756 | |
| 757 | StartIntercept(&output_fd, dump_type); |
| 758 | FinishCrasher(); |
| 759 | AssertDeath(0); |
| 760 | FinishIntercept(&intercept_result); |
| 761 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 762 | |
| 763 | std::string result; |
| 764 | ConsumeFd(std::move(output_fd), &result); |
| 765 | ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal"); |
| 766 | } |
| 767 | |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 768 | extern "C" void foo() { |
| 769 | LOG(INFO) << "foo"; |
| 770 | std::this_thread::sleep_for(1s); |
| 771 | } |
| 772 | |
| 773 | extern "C" void bar() { |
| 774 | LOG(INFO) << "bar"; |
| 775 | std::this_thread::sleep_for(1s); |
| 776 | } |
| 777 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 778 | TEST_F(CrasherTest, seccomp_backtrace) { |
| 779 | int intercept_result; |
| 780 | unique_fd output_fd; |
| 781 | |
| 782 | static const auto dump_type = kDebuggerdNativeBacktrace; |
| 783 | StartProcess( |
| 784 | []() { |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 785 | std::thread a(foo); |
| 786 | std::thread b(bar); |
| 787 | |
| 788 | std::this_thread::sleep_for(100ms); |
| 789 | |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 790 | raise_debugger_signal(dump_type); |
| 791 | _exit(0); |
| 792 | }, |
| 793 | &seccomp_fork); |
| 794 | |
| 795 | StartIntercept(&output_fd, dump_type); |
| 796 | FinishCrasher(); |
| 797 | AssertDeath(0); |
| 798 | FinishIntercept(&intercept_result); |
| 799 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 800 | |
| 801 | std::string result; |
| 802 | ConsumeFd(std::move(output_fd), &result); |
| 803 | ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal"); |
Josh Gao | 6f9eeec | 2018-09-12 13:55:47 -0700 | [diff] [blame] | 804 | ASSERT_BACKTRACE_FRAME(result, "foo"); |
| 805 | ASSERT_BACKTRACE_FRAME(result, "bar"); |
Josh Gao | e04ca27 | 2018-01-16 15:38:17 -0800 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | TEST_F(CrasherTest, seccomp_crash_logcat) { |
| 809 | StartProcess([]() { abort(); }, &seccomp_fork); |
| 810 | FinishCrasher(); |
| 811 | |
| 812 | // Make sure we don't get SIGSYS when trying to dump a crash to logcat. |
| 813 | AssertDeath(SIGABRT); |
| 814 | } |
| 815 | |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 816 | TEST_F(CrasherTest, competing_tracer) { |
| 817 | int intercept_result; |
| 818 | unique_fd output_fd; |
| 819 | StartProcess([]() { |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 820 | raise(SIGABRT); |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 821 | }); |
| 822 | |
| 823 | StartIntercept(&output_fd); |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 824 | |
| 825 | ASSERT_EQ(0, ptrace(PTRACE_SEIZE, crasher_pid, 0, 0)); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 826 | FinishCrasher(); |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 827 | |
| 828 | int status; |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 829 | ASSERT_EQ(crasher_pid, TEMP_FAILURE_RETRY(waitpid(crasher_pid, &status, 0))); |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 830 | ASSERT_TRUE(WIFSTOPPED(status)); |
| 831 | ASSERT_EQ(SIGABRT, WSTOPSIG(status)); |
| 832 | |
| 833 | ASSERT_EQ(0, ptrace(PTRACE_CONT, crasher_pid, 0, SIGABRT)); |
| 834 | FinishIntercept(&intercept_result); |
| 835 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 836 | |
| 837 | std::string result; |
| 838 | ConsumeFd(std::move(output_fd), &result); |
| 839 | std::string regex = R"(failed to attach to thread \d+, already traced by )"; |
| 840 | regex += std::to_string(gettid()); |
| 841 | regex += R"( \(.+debuggerd_test)"; |
| 842 | ASSERT_MATCH(result, regex.c_str()); |
| 843 | |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 844 | ASSERT_EQ(crasher_pid, TEMP_FAILURE_RETRY(waitpid(crasher_pid, &status, 0))); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 845 | ASSERT_TRUE(WIFSTOPPED(status)); |
| 846 | ASSERT_EQ(SIGABRT, WSTOPSIG(status)); |
| 847 | |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 848 | ASSERT_EQ(0, ptrace(PTRACE_DETACH, crasher_pid, 0, SIGABRT)); |
| 849 | AssertDeath(SIGABRT); |
| 850 | } |
| 851 | |
Josh Gao | bf06a40 | 2018-08-27 16:34:01 -0700 | [diff] [blame] | 852 | TEST_F(CrasherTest, fdsan_warning_abort_message) { |
| 853 | int intercept_result; |
| 854 | unique_fd output_fd; |
| 855 | |
| 856 | StartProcess([]() { |
| 857 | android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE); |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 858 | unique_fd fd(TEMP_FAILURE_RETRY(open("/dev/null", O_RDONLY | O_CLOEXEC))); |
Josh Gao | bf06a40 | 2018-08-27 16:34:01 -0700 | [diff] [blame] | 859 | if (fd == -1) { |
| 860 | abort(); |
| 861 | } |
| 862 | close(fd.get()); |
| 863 | _exit(0); |
| 864 | }); |
| 865 | |
| 866 | StartIntercept(&output_fd); |
| 867 | FinishCrasher(); |
| 868 | AssertDeath(0); |
| 869 | FinishIntercept(&intercept_result); |
| 870 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 871 | |
| 872 | std::string result; |
| 873 | ConsumeFd(std::move(output_fd), &result); |
| 874 | ASSERT_MATCH(result, "Abort message: 'attempted to close"); |
| 875 | } |
| 876 | |
Josh Gao | c3c8c02 | 2017-02-13 16:36:18 -0800 | [diff] [blame] | 877 | TEST(crash_dump, zombie) { |
| 878 | pid_t forkpid = fork(); |
| 879 | |
Josh Gao | c3c8c02 | 2017-02-13 16:36:18 -0800 | [diff] [blame] | 880 | pid_t rc; |
| 881 | int status; |
| 882 | |
| 883 | if (forkpid == 0) { |
| 884 | errno = 0; |
| 885 | rc = waitpid(-1, &status, WNOHANG | __WALL | __WNOTHREAD); |
| 886 | if (rc != -1 || errno != ECHILD) { |
| 887 | errx(2, "first waitpid returned %d (%s), expected failure with ECHILD", rc, strerror(errno)); |
| 888 | } |
| 889 | |
| 890 | raise(DEBUGGER_SIGNAL); |
| 891 | |
| 892 | errno = 0; |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 893 | rc = TEMP_FAILURE_RETRY(waitpid(-1, &status, __WALL | __WNOTHREAD)); |
Josh Gao | c3c8c02 | 2017-02-13 16:36:18 -0800 | [diff] [blame] | 894 | if (rc != -1 || errno != ECHILD) { |
| 895 | errx(2, "second waitpid returned %d (%s), expected failure with ECHILD", rc, strerror(errno)); |
| 896 | } |
| 897 | _exit(0); |
| 898 | } else { |
Christopher Ferris | 172b0a0 | 2019-09-18 17:48:30 -0700 | [diff] [blame] | 899 | rc = TEMP_FAILURE_RETRY(waitpid(forkpid, &status, 0)); |
Josh Gao | c3c8c02 | 2017-02-13 16:36:18 -0800 | [diff] [blame] | 900 | ASSERT_EQ(forkpid, rc); |
| 901 | ASSERT_TRUE(WIFEXITED(status)); |
| 902 | ASSERT_EQ(0, WEXITSTATUS(status)); |
| 903 | } |
| 904 | } |
Josh Gao | 352a845 | 2017-03-30 16:46:21 -0700 | [diff] [blame] | 905 | |
| 906 | TEST(tombstoned, no_notify) { |
| 907 | // Do this a few times. |
| 908 | for (int i = 0; i < 3; ++i) { |
| 909 | pid_t pid = 123'456'789 + i; |
| 910 | |
| 911 | unique_fd intercept_fd, output_fd; |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 912 | InterceptStatus status; |
| 913 | tombstoned_intercept(pid, &intercept_fd, &output_fd, &status, kDebuggerdTombstone); |
| 914 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
Josh Gao | 352a845 | 2017-03-30 16:46:21 -0700 | [diff] [blame] | 915 | |
| 916 | { |
| 917 | unique_fd tombstoned_socket, input_fd; |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 918 | ASSERT_TRUE(tombstoned_connect(pid, &tombstoned_socket, &input_fd, kDebuggerdTombstone)); |
Josh Gao | 352a845 | 2017-03-30 16:46:21 -0700 | [diff] [blame] | 919 | ASSERT_TRUE(android::base::WriteFully(input_fd.get(), &pid, sizeof(pid))); |
| 920 | } |
| 921 | |
| 922 | pid_t read_pid; |
| 923 | ASSERT_TRUE(android::base::ReadFully(output_fd.get(), &read_pid, sizeof(read_pid))); |
| 924 | ASSERT_EQ(read_pid, pid); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | TEST(tombstoned, stress) { |
| 929 | // Spawn threads to simultaneously do a bunch of failing dumps and a bunch of successful dumps. |
| 930 | static constexpr int kDumpCount = 100; |
| 931 | |
| 932 | std::atomic<bool> start(false); |
| 933 | std::vector<std::thread> threads; |
| 934 | threads.emplace_back([&start]() { |
| 935 | while (!start) { |
| 936 | continue; |
| 937 | } |
| 938 | |
| 939 | // Use a way out of range pid, to avoid stomping on an actual process. |
| 940 | pid_t pid_base = 1'000'000; |
| 941 | |
| 942 | for (int dump = 0; dump < kDumpCount; ++dump) { |
| 943 | pid_t pid = pid_base + dump; |
| 944 | |
| 945 | unique_fd intercept_fd, output_fd; |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 946 | InterceptStatus status; |
| 947 | tombstoned_intercept(pid, &intercept_fd, &output_fd, &status, kDebuggerdTombstone); |
| 948 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
Josh Gao | 352a845 | 2017-03-30 16:46:21 -0700 | [diff] [blame] | 949 | |
| 950 | // Pretend to crash, and then immediately close the socket. |
| 951 | unique_fd sockfd(socket_local_client(kTombstonedCrashSocketName, |
| 952 | ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET)); |
| 953 | if (sockfd == -1) { |
| 954 | FAIL() << "failed to connect to tombstoned: " << strerror(errno); |
| 955 | } |
| 956 | TombstonedCrashPacket packet = {}; |
| 957 | packet.packet_type = CrashPacketType::kDumpRequest; |
| 958 | packet.packet.dump_request.pid = pid; |
| 959 | if (TEMP_FAILURE_RETRY(write(sockfd, &packet, sizeof(packet))) != sizeof(packet)) { |
| 960 | FAIL() << "failed to write to tombstoned: " << strerror(errno); |
| 961 | } |
| 962 | |
| 963 | continue; |
| 964 | } |
| 965 | }); |
| 966 | |
| 967 | threads.emplace_back([&start]() { |
| 968 | while (!start) { |
| 969 | continue; |
| 970 | } |
| 971 | |
| 972 | // Use a way out of range pid, to avoid stomping on an actual process. |
| 973 | pid_t pid_base = 2'000'000; |
| 974 | |
| 975 | for (int dump = 0; dump < kDumpCount; ++dump) { |
| 976 | pid_t pid = pid_base + dump; |
| 977 | |
| 978 | unique_fd intercept_fd, output_fd; |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 979 | InterceptStatus status; |
| 980 | tombstoned_intercept(pid, &intercept_fd, &output_fd, &status, kDebuggerdTombstone); |
| 981 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
Josh Gao | 352a845 | 2017-03-30 16:46:21 -0700 | [diff] [blame] | 982 | |
| 983 | { |
| 984 | unique_fd tombstoned_socket, input_fd; |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 985 | ASSERT_TRUE(tombstoned_connect(pid, &tombstoned_socket, &input_fd, kDebuggerdTombstone)); |
Josh Gao | 352a845 | 2017-03-30 16:46:21 -0700 | [diff] [blame] | 986 | ASSERT_TRUE(android::base::WriteFully(input_fd.get(), &pid, sizeof(pid))); |
| 987 | tombstoned_notify_completion(tombstoned_socket.get()); |
| 988 | } |
| 989 | |
| 990 | // TODO: Fix the race that requires this sleep. |
| 991 | std::this_thread::sleep_for(50ms); |
| 992 | |
| 993 | pid_t read_pid; |
| 994 | ASSERT_TRUE(android::base::ReadFully(output_fd.get(), &read_pid, sizeof(read_pid))); |
| 995 | ASSERT_EQ(read_pid, pid); |
| 996 | } |
| 997 | }); |
| 998 | |
| 999 | start = true; |
| 1000 | |
| 1001 | for (std::thread& thread : threads) { |
| 1002 | thread.join(); |
| 1003 | } |
| 1004 | } |
Narayan Kamath | ca5e908 | 2017-06-02 15:42:06 +0100 | [diff] [blame] | 1005 | |
| 1006 | TEST(tombstoned, java_trace_intercept_smoke) { |
| 1007 | // Using a "real" PID is a little dangerous here - if the test fails |
| 1008 | // or crashes, we might end up getting a bogus / unreliable stack |
| 1009 | // trace. |
| 1010 | const pid_t self = getpid(); |
| 1011 | |
| 1012 | unique_fd intercept_fd, output_fd; |
| 1013 | InterceptStatus status; |
| 1014 | tombstoned_intercept(self, &intercept_fd, &output_fd, &status, kDebuggerdJavaBacktrace); |
| 1015 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
| 1016 | |
| 1017 | // First connect to tombstoned requesting a native backtrace. This |
| 1018 | // should result in a "regular" FD and not the installed intercept. |
| 1019 | const char native[] = "native"; |
| 1020 | unique_fd tombstoned_socket, input_fd; |
| 1021 | ASSERT_TRUE(tombstoned_connect(self, &tombstoned_socket, &input_fd, kDebuggerdNativeBacktrace)); |
| 1022 | ASSERT_TRUE(android::base::WriteFully(input_fd.get(), native, sizeof(native))); |
| 1023 | tombstoned_notify_completion(tombstoned_socket.get()); |
| 1024 | |
| 1025 | // Then, connect to tombstoned asking for a java backtrace. This *should* |
| 1026 | // trigger the intercept. |
| 1027 | const char java[] = "java"; |
| 1028 | ASSERT_TRUE(tombstoned_connect(self, &tombstoned_socket, &input_fd, kDebuggerdJavaBacktrace)); |
| 1029 | ASSERT_TRUE(android::base::WriteFully(input_fd.get(), java, sizeof(java))); |
| 1030 | tombstoned_notify_completion(tombstoned_socket.get()); |
| 1031 | |
| 1032 | char outbuf[sizeof(java)]; |
| 1033 | ASSERT_TRUE(android::base::ReadFully(output_fd.get(), outbuf, sizeof(outbuf))); |
| 1034 | ASSERT_STREQ("java", outbuf); |
| 1035 | } |
| 1036 | |
| 1037 | TEST(tombstoned, multiple_intercepts) { |
| 1038 | const pid_t fake_pid = 1'234'567; |
| 1039 | unique_fd intercept_fd, output_fd; |
| 1040 | InterceptStatus status; |
| 1041 | tombstoned_intercept(fake_pid, &intercept_fd, &output_fd, &status, kDebuggerdJavaBacktrace); |
| 1042 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
| 1043 | |
| 1044 | unique_fd intercept_fd_2, output_fd_2; |
| 1045 | tombstoned_intercept(fake_pid, &intercept_fd_2, &output_fd_2, &status, kDebuggerdNativeBacktrace); |
| 1046 | ASSERT_EQ(InterceptStatus::kFailedAlreadyRegistered, status); |
| 1047 | } |
| 1048 | |
| 1049 | TEST(tombstoned, intercept_any) { |
| 1050 | const pid_t fake_pid = 1'234'567; |
| 1051 | |
| 1052 | unique_fd intercept_fd, output_fd; |
| 1053 | InterceptStatus status; |
| 1054 | tombstoned_intercept(fake_pid, &intercept_fd, &output_fd, &status, kDebuggerdNativeBacktrace); |
| 1055 | ASSERT_EQ(InterceptStatus::kRegistered, status); |
| 1056 | |
| 1057 | const char any[] = "any"; |
| 1058 | unique_fd tombstoned_socket, input_fd; |
| 1059 | ASSERT_TRUE(tombstoned_connect(fake_pid, &tombstoned_socket, &input_fd, kDebuggerdAnyIntercept)); |
| 1060 | ASSERT_TRUE(android::base::WriteFully(input_fd.get(), any, sizeof(any))); |
| 1061 | tombstoned_notify_completion(tombstoned_socket.get()); |
| 1062 | |
| 1063 | char outbuf[sizeof(any)]; |
| 1064 | ASSERT_TRUE(android::base::ReadFully(output_fd.get(), outbuf, sizeof(outbuf))); |
| 1065 | ASSERT_STREQ("any", outbuf); |
| 1066 | } |
Josh Gao | 2b22ae1 | 2018-09-12 14:51:03 -0700 | [diff] [blame] | 1067 | |
| 1068 | TEST(tombstoned, interceptless_backtrace) { |
| 1069 | // Generate 50 backtraces, and then check to see that we haven't created 50 new tombstones. |
| 1070 | auto get_tombstone_timestamps = []() -> std::map<int, time_t> { |
| 1071 | std::map<int, time_t> result; |
| 1072 | for (int i = 0; i < 99; ++i) { |
| 1073 | std::string path = android::base::StringPrintf("/data/tombstones/tombstone_%02d", i); |
| 1074 | struct stat st; |
| 1075 | if (stat(path.c_str(), &st) == 0) { |
| 1076 | result[i] = st.st_mtim.tv_sec; |
| 1077 | } |
| 1078 | } |
| 1079 | return result; |
| 1080 | }; |
| 1081 | |
| 1082 | auto before = get_tombstone_timestamps(); |
| 1083 | for (int i = 0; i < 50; ++i) { |
| 1084 | raise_debugger_signal(kDebuggerdNativeBacktrace); |
| 1085 | } |
| 1086 | auto after = get_tombstone_timestamps(); |
| 1087 | |
| 1088 | int diff = 0; |
| 1089 | for (int i = 0; i < 99; ++i) { |
| 1090 | if (after.count(i) == 0) { |
| 1091 | continue; |
| 1092 | } |
| 1093 | if (before.count(i) == 0) { |
| 1094 | ++diff; |
| 1095 | continue; |
| 1096 | } |
| 1097 | if (before[i] != after[i]) { |
| 1098 | ++diff; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | // We can't be sure that nothing's crash looping in the background. |
| 1103 | // This should be good enough, though... |
| 1104 | ASSERT_LT(diff, 10) << "too many new tombstones; is something crashing in the background?"; |
| 1105 | } |
Christopher Ferris | 481e837 | 2019-07-15 17:13:24 -0700 | [diff] [blame] | 1106 | |
| 1107 | static __attribute__((__noinline__)) void overflow_stack(void* p) { |
| 1108 | void* buf[1]; |
| 1109 | buf[0] = p; |
| 1110 | static volatile void* global = buf; |
| 1111 | if (global) { |
| 1112 | global = buf; |
| 1113 | overflow_stack(&buf); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | TEST_F(CrasherTest, stack_overflow) { |
| 1118 | int intercept_result; |
| 1119 | unique_fd output_fd; |
| 1120 | StartProcess([]() { overflow_stack(nullptr); }); |
| 1121 | |
| 1122 | StartIntercept(&output_fd); |
| 1123 | FinishCrasher(); |
| 1124 | AssertDeath(SIGSEGV); |
| 1125 | FinishIntercept(&intercept_result); |
| 1126 | |
| 1127 | ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; |
| 1128 | |
| 1129 | std::string result; |
| 1130 | ConsumeFd(std::move(output_fd), &result); |
| 1131 | ASSERT_MATCH(result, R"(Cause: stack pointer[^\n]*stack overflow.\n)"); |
| 1132 | } |