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