blob: 388facb45c103e10facb94d7c892b86cbc5bf061 [file] [log] [blame]
Josh Gaocbe70cb2016-10-18 18:17:52 -07001/*
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 Gaocdea7502017-11-01 15:00:40 -070019#include <stdlib.h>
Josh Gao502cfd22017-02-17 01:39:15 -080020#include <sys/capability.h>
Josh Gaofca7ca32017-01-23 12:05:35 -080021#include <sys/prctl.h>
Josh Gaofd13bf02017-08-18 15:37:26 -070022#include <sys/ptrace.h>
Josh Gao70adac62018-02-22 11:38:33 -080023#include <sys/resource.h>
Dan Albertc38057a2017-10-11 11:35:40 -070024#include <sys/syscall.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070025#include <sys/types.h>
Josh Gaofd13bf02017-08-18 15:37:26 -070026#include <unistd.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070027
28#include <chrono>
29#include <regex>
30#include <thread>
31
Josh Gaobf06a402018-08-27 16:34:01 -070032#include <android/fdsan.h>
Josh Gao502cfd22017-02-17 01:39:15 -080033#include <android/set_abort_message.h>
34
Josh Gaocbe70cb2016-10-18 18:17:52 -070035#include <android-base/file.h>
36#include <android-base/logging.h>
Josh Gao2e7b8e22017-05-04 17:12:57 -070037#include <android-base/macros.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070038#include <android-base/parseint.h>
39#include <android-base/properties.h>
40#include <android-base/strings.h>
Josh Gao30171a82017-04-27 19:48:44 -070041#include <android-base/test_utils.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070042#include <android-base/unique_fd.h>
43#include <cutils/sockets.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070044#include <gtest/gtest.h>
45
Josh Gaoe04ca272018-01-16 15:38:17 -080046#include <libminijail.h>
47#include <scoped_minijail.h>
48
Narayan Kamath2d377cd2017-05-10 10:58:59 +010049#include "debuggerd/handler.h"
50#include "protocol.h"
51#include "tombstoned/tombstoned.h"
52#include "util.h"
53
Josh Gaocbe70cb2016-10-18 18:17:52 -070054using namespace std::chrono_literals;
55using android::base::unique_fd;
56
57#if defined(__LP64__)
Josh Gaocbe70cb2016-10-18 18:17:52 -070058#define ARCH_SUFFIX "64"
59#else
Josh Gaocbe70cb2016-10-18 18:17:52 -070060#define ARCH_SUFFIX ""
61#endif
62
63constexpr char kWaitForGdbKey[] = "debug.debuggerd.wait_for_gdb";
64
65#define TIMEOUT(seconds, expr) \
66 [&]() { \
67 struct sigaction old_sigaction; \
68 struct sigaction new_sigaction = {}; \
69 new_sigaction.sa_handler = [](int) {}; \
70 if (sigaction(SIGALRM, &new_sigaction, &new_sigaction) != 0) { \
71 err(1, "sigaction failed"); \
72 } \
73 alarm(seconds); \
74 auto value = expr; \
75 int saved_errno = errno; \
76 if (sigaction(SIGALRM, &old_sigaction, nullptr) != 0) { \
77 err(1, "sigaction failed"); \
78 } \
79 alarm(0); \
80 errno = saved_errno; \
81 return value; \
82 }()
83
Chih-Hung Hsieh3249b3a2018-05-11 16:01:21 -070084// Backtrace frame dump could contain:
85// #01 pc 0001cded /data/tmp/debuggerd_test32 (raise_debugger_signal+80)
86// or
87// #01 pc 00022a09 /data/tmp/debuggerd_test32 (offset 0x12000) (raise_debugger_signal+80)
Josh Gaoe04ca272018-01-16 15:38:17 -080088#define ASSERT_BACKTRACE_FRAME(result, frame_name) \
Chih-Hung Hsieh3249b3a2018-05-11 16:01:21 -070089 ASSERT_MATCH(result, \
90 R"(#\d\d pc [0-9a-f]+\s+ \S+ (\(offset 0x[0-9a-f]+\) )?\()" frame_name R"(\+)");
Jaesung Chung58778e12017-06-15 18:20:34 +090091
Narayan Kamatha73df602017-05-24 15:07:25 +010092static void tombstoned_intercept(pid_t target_pid, unique_fd* intercept_fd, unique_fd* output_fd,
Narayan Kamathca5e9082017-06-02 15:42:06 +010093 InterceptStatus* status, DebuggerdDumpType intercept_type) {
Josh Gao460b3362017-03-30 16:40:47 -070094 intercept_fd->reset(socket_local_client(kTombstonedInterceptSocketName,
95 ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET));
96 if (intercept_fd->get() == -1) {
97 FAIL() << "failed to contact tombstoned: " << strerror(errno);
98 }
99
Narayan Kamatha73df602017-05-24 15:07:25 +0100100 InterceptRequest req = {.pid = target_pid, .dump_type = intercept_type};
Josh Gao460b3362017-03-30 16:40:47 -0700101
102 unique_fd output_pipe_write;
103 if (!Pipe(output_fd, &output_pipe_write)) {
104 FAIL() << "failed to create output pipe: " << strerror(errno);
105 }
106
107 std::string pipe_size_str;
108 int pipe_buffer_size;
109 if (!android::base::ReadFileToString("/proc/sys/fs/pipe-max-size", &pipe_size_str)) {
110 FAIL() << "failed to read /proc/sys/fs/pipe-max-size: " << strerror(errno);
111 }
112
113 pipe_size_str = android::base::Trim(pipe_size_str);
114
115 if (!android::base::ParseInt(pipe_size_str.c_str(), &pipe_buffer_size, 0)) {
116 FAIL() << "failed to parse pipe max size";
117 }
118
119 if (fcntl(output_fd->get(), F_SETPIPE_SZ, pipe_buffer_size) != pipe_buffer_size) {
120 FAIL() << "failed to set pipe size: " << strerror(errno);
121 }
122
Josh Gao5675f3c2017-06-01 12:19:53 -0700123 ASSERT_GE(pipe_buffer_size, 1024 * 1024);
124
Josh Gao460b3362017-03-30 16:40:47 -0700125 if (send_fd(intercept_fd->get(), &req, sizeof(req), std::move(output_pipe_write)) != sizeof(req)) {
126 FAIL() << "failed to send output fd to tombstoned: " << strerror(errno);
127 }
128
129 InterceptResponse response;
130 ssize_t rc = TEMP_FAILURE_RETRY(read(intercept_fd->get(), &response, sizeof(response)));
131 if (rc == -1) {
132 FAIL() << "failed to read response from tombstoned: " << strerror(errno);
133 } else if (rc == 0) {
134 FAIL() << "failed to read response from tombstoned (EOF)";
135 } else if (rc != sizeof(response)) {
136 FAIL() << "received packet of unexpected length from tombstoned: expected " << sizeof(response)
137 << ", received " << rc;
138 }
139
Narayan Kamathca5e9082017-06-02 15:42:06 +0100140 *status = response.status;
Josh Gao460b3362017-03-30 16:40:47 -0700141}
142
Josh Gaocbe70cb2016-10-18 18:17:52 -0700143class CrasherTest : public ::testing::Test {
144 public:
145 pid_t crasher_pid = -1;
146 bool previous_wait_for_gdb;
147 unique_fd crasher_pipe;
148 unique_fd intercept_fd;
149
150 CrasherTest();
151 ~CrasherTest();
152
Narayan Kamatha73df602017-05-24 15:07:25 +0100153 void StartIntercept(unique_fd* output_fd, DebuggerdDumpType intercept_type = kDebuggerdTombstone);
Josh Gaocbe70cb2016-10-18 18:17:52 -0700154
155 // Returns -1 if we fail to read a response from tombstoned, otherwise the received return code.
156 void FinishIntercept(int* result);
157
Josh Gao2e7b8e22017-05-04 17:12:57 -0700158 void StartProcess(std::function<void()> function, std::function<pid_t()> forker = fork);
Josh Gaocbe70cb2016-10-18 18:17:52 -0700159 void StartCrasher(const std::string& crash_type);
160 void FinishCrasher();
161 void AssertDeath(int signo);
162};
163
164CrasherTest::CrasherTest() {
165 previous_wait_for_gdb = android::base::GetBoolProperty(kWaitForGdbKey, false);
166 android::base::SetProperty(kWaitForGdbKey, "0");
167}
168
169CrasherTest::~CrasherTest() {
170 if (crasher_pid != -1) {
171 kill(crasher_pid, SIGKILL);
172 int status;
173 waitpid(crasher_pid, &status, WUNTRACED);
174 }
175
176 android::base::SetProperty(kWaitForGdbKey, previous_wait_for_gdb ? "1" : "0");
177}
178
Narayan Kamatha73df602017-05-24 15:07:25 +0100179void CrasherTest::StartIntercept(unique_fd* output_fd, DebuggerdDumpType intercept_type) {
Josh Gaocbe70cb2016-10-18 18:17:52 -0700180 if (crasher_pid == -1) {
181 FAIL() << "crasher hasn't been started";
182 }
183
Narayan Kamathca5e9082017-06-02 15:42:06 +0100184 InterceptStatus status;
185 tombstoned_intercept(crasher_pid, &this->intercept_fd, output_fd, &status, intercept_type);
186 ASSERT_EQ(InterceptStatus::kRegistered, status);
Josh Gaocbe70cb2016-10-18 18:17:52 -0700187}
188
189void CrasherTest::FinishIntercept(int* result) {
190 InterceptResponse response;
191
192 // Timeout for tombstoned intercept is 10 seconds.
193 ssize_t rc = TIMEOUT(20, read(intercept_fd.get(), &response, sizeof(response)));
194 if (rc == -1) {
195 FAIL() << "failed to read response from tombstoned: " << strerror(errno);
196 } else if (rc == 0) {
197 *result = -1;
198 } else if (rc != sizeof(response)) {
199 FAIL() << "received packet of unexpected length from tombstoned: expected " << sizeof(response)
200 << ", received " << rc;
201 } else {
Josh Gao460b3362017-03-30 16:40:47 -0700202 *result = response.status == InterceptStatus::kStarted ? 1 : 0;
Josh Gaocbe70cb2016-10-18 18:17:52 -0700203 }
204}
205
Josh Gao2e7b8e22017-05-04 17:12:57 -0700206void CrasherTest::StartProcess(std::function<void()> function, std::function<pid_t()> forker) {
Josh Gaofca7ca32017-01-23 12:05:35 -0800207 unique_fd read_pipe;
Josh Gaocbe70cb2016-10-18 18:17:52 -0700208 unique_fd crasher_read_pipe;
209 if (!Pipe(&crasher_read_pipe, &crasher_pipe)) {
210 FAIL() << "failed to create pipe: " << strerror(errno);
211 }
212
Josh Gao2e7b8e22017-05-04 17:12:57 -0700213 crasher_pid = forker();
Josh Gaocbe70cb2016-10-18 18:17:52 -0700214 if (crasher_pid == -1) {
215 FAIL() << "fork failed: " << strerror(errno);
216 } else if (crasher_pid == 0) {
Josh Gao502cfd22017-02-17 01:39:15 -0800217 char dummy;
218 crasher_pipe.reset();
219 TEMP_FAILURE_RETRY(read(crasher_read_pipe.get(), &dummy, 1));
Josh Gaofca7ca32017-01-23 12:05:35 -0800220 function();
221 _exit(0);
222 }
223}
224
Josh Gaocbe70cb2016-10-18 18:17:52 -0700225void CrasherTest::FinishCrasher() {
226 if (crasher_pipe == -1) {
227 FAIL() << "crasher pipe uninitialized";
228 }
229
230 ssize_t rc = write(crasher_pipe.get(), "\n", 1);
231 if (rc == -1) {
232 FAIL() << "failed to write to crasher pipe: " << strerror(errno);
233 } else if (rc == 0) {
234 FAIL() << "crasher pipe was closed";
235 }
236}
237
238void CrasherTest::AssertDeath(int signo) {
239 int status;
240 pid_t pid = TIMEOUT(5, waitpid(crasher_pid, &status, 0));
241 if (pid != crasher_pid) {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700242 printf("failed to wait for crasher (pid %d)\n", crasher_pid);
243 sleep(100);
Josh Gaocbe70cb2016-10-18 18:17:52 -0700244 FAIL() << "failed to wait for crasher: " << strerror(errno);
245 }
246
Josh Gaoe06f2a42017-04-27 16:50:38 -0700247 if (signo == 0) {
248 ASSERT_TRUE(WIFEXITED(status));
249 ASSERT_EQ(0, WEXITSTATUS(signo));
250 } else {
251 ASSERT_FALSE(WIFEXITED(status));
252 ASSERT_TRUE(WIFSIGNALED(status)) << "crasher didn't terminate via a signal";
253 ASSERT_EQ(signo, WTERMSIG(status));
Josh Gaocbe70cb2016-10-18 18:17:52 -0700254 }
Josh Gaocbe70cb2016-10-18 18:17:52 -0700255 crasher_pid = -1;
256}
257
258static void ConsumeFd(unique_fd fd, std::string* output) {
259 constexpr size_t read_length = PAGE_SIZE;
260 std::string result;
261
262 while (true) {
263 size_t offset = result.size();
264 result.resize(result.size() + PAGE_SIZE);
265 ssize_t rc = TEMP_FAILURE_RETRY(read(fd.get(), &result[offset], read_length));
266 if (rc == -1) {
267 FAIL() << "read failed: " << strerror(errno);
268 } else if (rc == 0) {
269 result.resize(result.size() - PAGE_SIZE);
270 break;
271 }
272
273 result.resize(result.size() - PAGE_SIZE + rc);
274 }
275
276 *output = std::move(result);
277}
278
279TEST_F(CrasherTest, smoke) {
280 int intercept_result;
281 unique_fd output_fd;
Josh Gao502cfd22017-02-17 01:39:15 -0800282 StartProcess([]() {
283 *reinterpret_cast<volatile char*>(0xdead) = '1';
284 });
285
Josh Gaocbe70cb2016-10-18 18:17:52 -0700286 StartIntercept(&output_fd);
287 FinishCrasher();
288 AssertDeath(SIGSEGV);
289 FinishIntercept(&intercept_result);
290
291 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
292
293 std::string result;
294 ConsumeFd(std::move(output_fd), &result);
295 ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0xdead)");
296}
297
Josh Gaocdea7502017-11-01 15:00:40 -0700298TEST_F(CrasherTest, LD_PRELOAD) {
299 int intercept_result;
300 unique_fd output_fd;
301 StartProcess([]() {
302 setenv("LD_PRELOAD", "nonexistent.so", 1);
303 *reinterpret_cast<volatile char*>(0xdead) = '1';
304 });
305
306 StartIntercept(&output_fd);
307 FinishCrasher();
308 AssertDeath(SIGSEGV);
309 FinishIntercept(&intercept_result);
310
311 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
312
313 std::string result;
314 ConsumeFd(std::move(output_fd), &result);
315 ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0xdead)");
316}
317
Josh Gaocbe70cb2016-10-18 18:17:52 -0700318TEST_F(CrasherTest, abort) {
319 int intercept_result;
320 unique_fd output_fd;
Josh Gao502cfd22017-02-17 01:39:15 -0800321 StartProcess([]() {
322 abort();
323 });
Josh Gaocbe70cb2016-10-18 18:17:52 -0700324 StartIntercept(&output_fd);
325 FinishCrasher();
326 AssertDeath(SIGABRT);
327 FinishIntercept(&intercept_result);
328
329 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
330
331 std::string result;
332 ConsumeFd(std::move(output_fd), &result);
Andreas Gampe26cbafb2017-06-22 20:14:43 -0700333 ASSERT_BACKTRACE_FRAME(result, "abort");
Josh Gaocbe70cb2016-10-18 18:17:52 -0700334}
335
336TEST_F(CrasherTest, signal) {
337 int intercept_result;
338 unique_fd output_fd;
Josh Gao502cfd22017-02-17 01:39:15 -0800339 StartProcess([]() {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700340 while (true) {
341 sleep(1);
342 }
Josh Gao502cfd22017-02-17 01:39:15 -0800343 });
Josh Gaocbe70cb2016-10-18 18:17:52 -0700344 StartIntercept(&output_fd);
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700345 FinishCrasher();
Josh Gaocbe70cb2016-10-18 18:17:52 -0700346 ASSERT_EQ(0, kill(crasher_pid, SIGSEGV));
347
348 AssertDeath(SIGSEGV);
349 FinishIntercept(&intercept_result);
350
351 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
352
353 std::string result;
354 ConsumeFd(std::move(output_fd), &result);
Elliott Hughes89722702018-05-02 10:47:00 -0700355 ASSERT_MATCH(
356 result,
357 R"(signal 11 \(SIGSEGV\), code 0 \(SI_USER from pid \d+, uid \d+\), fault addr --------)");
Josh Gaocbe70cb2016-10-18 18:17:52 -0700358 ASSERT_MATCH(result, R"(backtrace:)");
359}
360
361TEST_F(CrasherTest, abort_message) {
362 int intercept_result;
363 unique_fd output_fd;
Josh Gao502cfd22017-02-17 01:39:15 -0800364 StartProcess([]() {
Josh Gao1cc7bd82018-02-13 13:16:17 -0800365 // Arrived at experimentally;
366 // logd truncates at 4062.
367 // strlen("Abort message: ''") is 17.
368 // That's 4045, but we also want a NUL.
369 char buf[4045 + 1];
370 memset(buf, 'x', sizeof(buf));
371 buf[sizeof(buf) - 1] = '\0';
372 android_set_abort_message(buf);
Josh Gao502cfd22017-02-17 01:39:15 -0800373 abort();
374 });
Josh Gaocbe70cb2016-10-18 18:17:52 -0700375 StartIntercept(&output_fd);
376 FinishCrasher();
377 AssertDeath(SIGABRT);
378 FinishIntercept(&intercept_result);
379
380 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
381
382 std::string result;
383 ConsumeFd(std::move(output_fd), &result);
Josh Gao1cc7bd82018-02-13 13:16:17 -0800384 ASSERT_MATCH(result, R"(Abort message: 'x{4045}')");
Josh Gaocbe70cb2016-10-18 18:17:52 -0700385}
386
Josh Gaoe06f2a42017-04-27 16:50:38 -0700387TEST_F(CrasherTest, abort_message_backtrace) {
388 int intercept_result;
389 unique_fd output_fd;
390 StartProcess([]() {
391 android_set_abort_message("not actually aborting");
392 raise(DEBUGGER_SIGNAL);
393 exit(0);
394 });
395 StartIntercept(&output_fd);
396 FinishCrasher();
397 AssertDeath(0);
398 FinishIntercept(&intercept_result);
399
400 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
401
402 std::string result;
403 ConsumeFd(std::move(output_fd), &result);
404 ASSERT_NOT_MATCH(result, R"(Abort message:)");
405}
406
Josh Gaocbe70cb2016-10-18 18:17:52 -0700407TEST_F(CrasherTest, intercept_timeout) {
408 int intercept_result;
409 unique_fd output_fd;
Josh Gao502cfd22017-02-17 01:39:15 -0800410 StartProcess([]() {
411 abort();
412 });
Josh Gaocbe70cb2016-10-18 18:17:52 -0700413 StartIntercept(&output_fd);
414
415 // Don't let crasher finish until we timeout.
416 FinishIntercept(&intercept_result);
417
418 ASSERT_NE(1, intercept_result) << "tombstoned reported success? (intercept_result = "
419 << intercept_result << ")";
420
421 FinishCrasher();
422 AssertDeath(SIGABRT);
423}
424
425TEST_F(CrasherTest, wait_for_gdb) {
426 if (!android::base::SetProperty(kWaitForGdbKey, "1")) {
427 FAIL() << "failed to enable wait_for_gdb";
428 }
429 sleep(1);
430
Josh Gao502cfd22017-02-17 01:39:15 -0800431 StartProcess([]() {
432 abort();
433 });
Josh Gaocbe70cb2016-10-18 18:17:52 -0700434 FinishCrasher();
435
436 int status;
437 ASSERT_EQ(crasher_pid, waitpid(crasher_pid, &status, WUNTRACED));
438 ASSERT_TRUE(WIFSTOPPED(status));
439 ASSERT_EQ(SIGSTOP, WSTOPSIG(status));
440
441 ASSERT_EQ(0, kill(crasher_pid, SIGCONT));
442
443 AssertDeath(SIGABRT);
444}
445
Josh Gaocbe70cb2016-10-18 18:17:52 -0700446TEST_F(CrasherTest, backtrace) {
447 std::string result;
448 int intercept_result;
449 unique_fd output_fd;
Josh Gao502cfd22017-02-17 01:39:15 -0800450
451 StartProcess([]() {
452 abort();
453 });
Narayan Kamatha73df602017-05-24 15:07:25 +0100454 StartIntercept(&output_fd, kDebuggerdNativeBacktrace);
Josh Gaocbe70cb2016-10-18 18:17:52 -0700455
456 std::this_thread::sleep_for(500ms);
457
458 sigval val;
459 val.sival_int = 1;
460 ASSERT_EQ(0, sigqueue(crasher_pid, DEBUGGER_SIGNAL, val)) << strerror(errno);
461 FinishIntercept(&intercept_result);
462 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
463 ConsumeFd(std::move(output_fd), &result);
Jaesung Chung58778e12017-06-15 18:20:34 +0900464 ASSERT_BACKTRACE_FRAME(result, "read");
Josh Gaocbe70cb2016-10-18 18:17:52 -0700465
466 int status;
467 ASSERT_EQ(0, waitpid(crasher_pid, &status, WNOHANG | WUNTRACED));
468
469 StartIntercept(&output_fd);
470 FinishCrasher();
471 AssertDeath(SIGABRT);
472 FinishIntercept(&intercept_result);
473 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
474 ConsumeFd(std::move(output_fd), &result);
Andreas Gampe26cbafb2017-06-22 20:14:43 -0700475 ASSERT_BACKTRACE_FRAME(result, "abort");
Josh Gaocbe70cb2016-10-18 18:17:52 -0700476}
Josh Gaofca7ca32017-01-23 12:05:35 -0800477
478TEST_F(CrasherTest, PR_SET_DUMPABLE_0_crash) {
Josh Gao502cfd22017-02-17 01:39:15 -0800479 int intercept_result;
480 unique_fd output_fd;
Josh Gaofca7ca32017-01-23 12:05:35 -0800481 StartProcess([]() {
482 prctl(PR_SET_DUMPABLE, 0);
Josh Gao502cfd22017-02-17 01:39:15 -0800483 abort();
Josh Gaofca7ca32017-01-23 12:05:35 -0800484 });
Josh Gao502cfd22017-02-17 01:39:15 -0800485
486 StartIntercept(&output_fd);
487 FinishCrasher();
488 AssertDeath(SIGABRT);
489 FinishIntercept(&intercept_result);
490
491 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
492
493 std::string result;
494 ConsumeFd(std::move(output_fd), &result);
Andreas Gampe26cbafb2017-06-22 20:14:43 -0700495 ASSERT_BACKTRACE_FRAME(result, "abort");
Josh Gaofca7ca32017-01-23 12:05:35 -0800496}
497
Josh Gao502cfd22017-02-17 01:39:15 -0800498TEST_F(CrasherTest, capabilities) {
499 ASSERT_EQ(0U, getuid()) << "capability test requires root";
500
Josh Gaofca7ca32017-01-23 12:05:35 -0800501 StartProcess([]() {
Josh Gao502cfd22017-02-17 01:39:15 -0800502 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {
503 err(1, "failed to set PR_SET_KEEPCAPS");
504 }
505
506 if (setresuid(1, 1, 1) != 0) {
507 err(1, "setresuid failed");
508 }
509
510 __user_cap_header_struct capheader;
511 __user_cap_data_struct capdata[2];
512 memset(&capheader, 0, sizeof(capheader));
513 memset(&capdata, 0, sizeof(capdata));
514
515 capheader.version = _LINUX_CAPABILITY_VERSION_3;
516 capheader.pid = 0;
517
518 // Turn on every third capability.
519 static_assert(CAP_LAST_CAP > 33, "CAP_LAST_CAP <= 32");
520 for (int i = 0; i < CAP_LAST_CAP; i += 3) {
521 capdata[CAP_TO_INDEX(i)].permitted |= CAP_TO_MASK(i);
522 capdata[CAP_TO_INDEX(i)].effective |= CAP_TO_MASK(i);
523 }
524
525 // Make sure CAP_SYS_PTRACE is off.
526 capdata[CAP_TO_INDEX(CAP_SYS_PTRACE)].permitted &= ~(CAP_TO_MASK(CAP_SYS_PTRACE));
527 capdata[CAP_TO_INDEX(CAP_SYS_PTRACE)].effective &= ~(CAP_TO_MASK(CAP_SYS_PTRACE));
528
529 if (capset(&capheader, &capdata[0]) != 0) {
530 err(1, "capset failed");
531 }
532
533 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0) != 0) {
534 err(1, "failed to drop ambient capabilities");
535 }
536
Josh Gaoa5199a92017-04-03 13:18:34 -0700537 pthread_setname_np(pthread_self(), "thread_name");
Josh Gao502cfd22017-02-17 01:39:15 -0800538 raise(SIGSYS);
Josh Gaofca7ca32017-01-23 12:05:35 -0800539 });
Josh Gao502cfd22017-02-17 01:39:15 -0800540
541 unique_fd output_fd;
542 StartIntercept(&output_fd);
543 FinishCrasher();
544 AssertDeath(SIGSYS);
545
546 std::string result;
547 int intercept_result;
548 FinishIntercept(&intercept_result);
549 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
550 ConsumeFd(std::move(output_fd), &result);
Josh Gaoa5199a92017-04-03 13:18:34 -0700551 ASSERT_MATCH(result, R"(name: thread_name\s+>>> .+debuggerd_test(32|64) <<<)");
Jaesung Chung58778e12017-06-15 18:20:34 +0900552 ASSERT_BACKTRACE_FRAME(result, "tgkill");
Josh Gaofca7ca32017-01-23 12:05:35 -0800553}
Josh Gaoc3c8c022017-02-13 16:36:18 -0800554
Josh Gao2e7b8e22017-05-04 17:12:57 -0700555TEST_F(CrasherTest, fake_pid) {
556 int intercept_result;
557 unique_fd output_fd;
558
559 // Prime the getpid/gettid caches.
560 UNUSED(getpid());
561 UNUSED(gettid());
562
563 std::function<pid_t()> clone_fn = []() {
564 return syscall(__NR_clone, SIGCHLD, nullptr, nullptr, nullptr, nullptr);
565 };
566 StartProcess(
567 []() {
568 ASSERT_NE(getpid(), syscall(__NR_getpid));
569 ASSERT_NE(gettid(), syscall(__NR_gettid));
570 raise(SIGSEGV);
571 },
572 clone_fn);
573
574 StartIntercept(&output_fd);
575 FinishCrasher();
576 AssertDeath(SIGSEGV);
577 FinishIntercept(&intercept_result);
578
579 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
580
581 std::string result;
582 ConsumeFd(std::move(output_fd), &result);
Jaesung Chung58778e12017-06-15 18:20:34 +0900583 ASSERT_BACKTRACE_FRAME(result, "tgkill");
Josh Gao2e7b8e22017-05-04 17:12:57 -0700584}
585
Josh Gaoe04ca272018-01-16 15:38:17 -0800586static const char* const kDebuggerdSeccompPolicy =
587 "/system/etc/seccomp_policy/crash_dump." ABI_STRING ".policy";
588
Josh Gao70adac62018-02-22 11:38:33 -0800589static pid_t seccomp_fork_impl(void (*prejail)()) {
Josh Gao6f9eeec2018-09-12 13:55:47 -0700590 std::string policy;
591 if (!android::base::ReadFileToString(kDebuggerdSeccompPolicy, &policy)) {
592 PLOG(FATAL) << "failed to read policy file";
593 }
594
595 // Allow a bunch of syscalls used by the tests.
596 policy += "\nclone: 1";
597 policy += "\nsigaltstack: 1";
598 policy += "\nnanosleep: 1";
599
600 FILE* tmp_file = tmpfile();
601 if (!tmp_file) {
602 PLOG(FATAL) << "tmpfile failed";
603 }
604
605 unique_fd tmp_fd(dup(fileno(tmp_file)));
606 if (!android::base::WriteStringToFd(policy, tmp_fd.get())) {
607 PLOG(FATAL) << "failed to write policy to tmpfile";
608 }
609
610 if (lseek(tmp_fd.get(), 0, SEEK_SET) != 0) {
611 PLOG(FATAL) << "failed to seek tmp_fd";
Josh Gaoe04ca272018-01-16 15:38:17 -0800612 }
613
614 ScopedMinijail jail{minijail_new()};
615 if (!jail) {
616 LOG(FATAL) << "failed to create minijail";
617 }
618
619 minijail_no_new_privs(jail.get());
620 minijail_log_seccomp_filter_failures(jail.get());
621 minijail_use_seccomp_filter(jail.get());
Josh Gao6f9eeec2018-09-12 13:55:47 -0700622 minijail_parse_seccomp_filters_from_fd(jail.get(), tmp_fd.release());
Josh Gaoe04ca272018-01-16 15:38:17 -0800623
624 pid_t result = fork();
625 if (result == -1) {
626 return result;
627 } else if (result != 0) {
628 return result;
629 }
630
631 // Spawn and detach a thread that spins forever.
632 std::atomic<bool> thread_ready(false);
633 std::thread thread([&jail, &thread_ready]() {
634 minijail_enter(jail.get());
635 thread_ready = true;
636 for (;;)
637 ;
638 });
639 thread.detach();
640
641 while (!thread_ready) {
642 continue;
643 }
644
Josh Gao70adac62018-02-22 11:38:33 -0800645 if (prejail) {
646 prejail();
647 }
648
Josh Gaoe04ca272018-01-16 15:38:17 -0800649 minijail_enter(jail.get());
650 return result;
651}
652
Josh Gao70adac62018-02-22 11:38:33 -0800653static pid_t seccomp_fork() {
654 return seccomp_fork_impl(nullptr);
655}
656
Josh Gaoe04ca272018-01-16 15:38:17 -0800657TEST_F(CrasherTest, seccomp_crash) {
658 int intercept_result;
659 unique_fd output_fd;
660
661 StartProcess([]() { abort(); }, &seccomp_fork);
662
663 StartIntercept(&output_fd);
664 FinishCrasher();
665 AssertDeath(SIGABRT);
666 FinishIntercept(&intercept_result);
667 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
668
669 std::string result;
670 ConsumeFd(std::move(output_fd), &result);
671 ASSERT_BACKTRACE_FRAME(result, "abort");
672}
673
Josh Gao70adac62018-02-22 11:38:33 -0800674static pid_t seccomp_fork_rlimit() {
675 return seccomp_fork_impl([]() {
676 struct rlimit rlim = {
677 .rlim_cur = 512 * 1024 * 1024,
678 .rlim_max = 512 * 1024 * 1024,
679 };
680
681 if (setrlimit(RLIMIT_AS, &rlim) != 0) {
682 raise(SIGINT);
683 }
684 });
685}
686
687TEST_F(CrasherTest, seccomp_crash_oom) {
688 int intercept_result;
689 unique_fd output_fd;
690
691 StartProcess(
692 []() {
693 std::vector<void*> vec;
694 for (int i = 0; i < 512; ++i) {
695 char* buf = static_cast<char*>(malloc(1024 * 1024));
696 if (!buf) {
697 abort();
698 }
699 memset(buf, 0xff, 1024 * 1024);
700 vec.push_back(buf);
701 }
702 },
703 &seccomp_fork_rlimit);
704
705 StartIntercept(&output_fd);
706 FinishCrasher();
707 AssertDeath(SIGABRT);
708 FinishIntercept(&intercept_result);
709 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
710
711 // We can't actually generate a backtrace, just make sure that the process terminates.
712}
713
Josh Gaoe04ca272018-01-16 15:38:17 -0800714__attribute__((noinline)) extern "C" bool raise_debugger_signal(DebuggerdDumpType dump_type) {
715 siginfo_t siginfo;
716 siginfo.si_code = SI_QUEUE;
717 siginfo.si_pid = getpid();
718 siginfo.si_uid = getuid();
719
720 if (dump_type != kDebuggerdNativeBacktrace && dump_type != kDebuggerdTombstone) {
721 PLOG(FATAL) << "invalid dump type";
722 }
723
724 siginfo.si_value.sival_int = dump_type == kDebuggerdNativeBacktrace;
725
726 if (syscall(__NR_rt_tgsigqueueinfo, getpid(), gettid(), DEBUGGER_SIGNAL, &siginfo) != 0) {
727 PLOG(ERROR) << "libdebuggerd_client: failed to send signal to self";
728 return false;
729 }
730
731 return true;
732}
733
734TEST_F(CrasherTest, seccomp_tombstone) {
735 int intercept_result;
736 unique_fd output_fd;
737
738 static const auto dump_type = kDebuggerdTombstone;
739 StartProcess(
740 []() {
741 raise_debugger_signal(dump_type);
742 _exit(0);
743 },
744 &seccomp_fork);
745
746 StartIntercept(&output_fd, dump_type);
747 FinishCrasher();
748 AssertDeath(0);
749 FinishIntercept(&intercept_result);
750 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
751
752 std::string result;
753 ConsumeFd(std::move(output_fd), &result);
754 ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal");
755}
756
Josh Gao6f9eeec2018-09-12 13:55:47 -0700757extern "C" void foo() {
758 LOG(INFO) << "foo";
759 std::this_thread::sleep_for(1s);
760}
761
762extern "C" void bar() {
763 LOG(INFO) << "bar";
764 std::this_thread::sleep_for(1s);
765}
766
Josh Gaoe04ca272018-01-16 15:38:17 -0800767TEST_F(CrasherTest, seccomp_backtrace) {
768 int intercept_result;
769 unique_fd output_fd;
770
771 static const auto dump_type = kDebuggerdNativeBacktrace;
772 StartProcess(
773 []() {
Josh Gao6f9eeec2018-09-12 13:55:47 -0700774 std::thread a(foo);
775 std::thread b(bar);
776
777 std::this_thread::sleep_for(100ms);
778
Josh Gaoe04ca272018-01-16 15:38:17 -0800779 raise_debugger_signal(dump_type);
780 _exit(0);
781 },
782 &seccomp_fork);
783
784 StartIntercept(&output_fd, dump_type);
785 FinishCrasher();
786 AssertDeath(0);
787 FinishIntercept(&intercept_result);
788 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
789
790 std::string result;
791 ConsumeFd(std::move(output_fd), &result);
792 ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal");
Josh Gao6f9eeec2018-09-12 13:55:47 -0700793 ASSERT_BACKTRACE_FRAME(result, "foo");
794 ASSERT_BACKTRACE_FRAME(result, "bar");
Josh Gaoe04ca272018-01-16 15:38:17 -0800795}
796
797TEST_F(CrasherTest, seccomp_crash_logcat) {
798 StartProcess([]() { abort(); }, &seccomp_fork);
799 FinishCrasher();
800
801 // Make sure we don't get SIGSYS when trying to dump a crash to logcat.
802 AssertDeath(SIGABRT);
803}
804
Josh Gaofd13bf02017-08-18 15:37:26 -0700805TEST_F(CrasherTest, competing_tracer) {
806 int intercept_result;
807 unique_fd output_fd;
808 StartProcess([]() {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700809 raise(SIGABRT);
Josh Gaofd13bf02017-08-18 15:37:26 -0700810 });
811
812 StartIntercept(&output_fd);
Josh Gaofd13bf02017-08-18 15:37:26 -0700813
814 ASSERT_EQ(0, ptrace(PTRACE_SEIZE, crasher_pid, 0, 0));
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700815 FinishCrasher();
Josh Gaofd13bf02017-08-18 15:37:26 -0700816
817 int status;
818 ASSERT_EQ(crasher_pid, waitpid(crasher_pid, &status, 0));
819 ASSERT_TRUE(WIFSTOPPED(status));
820 ASSERT_EQ(SIGABRT, WSTOPSIG(status));
821
822 ASSERT_EQ(0, ptrace(PTRACE_CONT, crasher_pid, 0, SIGABRT));
823 FinishIntercept(&intercept_result);
824 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
825
826 std::string result;
827 ConsumeFd(std::move(output_fd), &result);
828 std::string regex = R"(failed to attach to thread \d+, already traced by )";
829 regex += std::to_string(gettid());
830 regex += R"( \(.+debuggerd_test)";
831 ASSERT_MATCH(result, regex.c_str());
832
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700833 ASSERT_EQ(crasher_pid, waitpid(crasher_pid, &status, 0));
834 ASSERT_TRUE(WIFSTOPPED(status));
835 ASSERT_EQ(SIGABRT, WSTOPSIG(status));
836
Josh Gaofd13bf02017-08-18 15:37:26 -0700837 ASSERT_EQ(0, ptrace(PTRACE_DETACH, crasher_pid, 0, SIGABRT));
838 AssertDeath(SIGABRT);
839}
840
Josh Gaobf06a402018-08-27 16:34:01 -0700841TEST_F(CrasherTest, fdsan_warning_abort_message) {
842 int intercept_result;
843 unique_fd output_fd;
844
845 StartProcess([]() {
846 android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE);
847 unique_fd fd(open("/dev/null", O_RDONLY | O_CLOEXEC));
848 if (fd == -1) {
849 abort();
850 }
851 close(fd.get());
852 _exit(0);
853 });
854
855 StartIntercept(&output_fd);
856 FinishCrasher();
857 AssertDeath(0);
858 FinishIntercept(&intercept_result);
859 ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
860
861 std::string result;
862 ConsumeFd(std::move(output_fd), &result);
863 ASSERT_MATCH(result, "Abort message: 'attempted to close");
864}
865
Josh Gaoc3c8c022017-02-13 16:36:18 -0800866TEST(crash_dump, zombie) {
867 pid_t forkpid = fork();
868
Josh Gaoc3c8c022017-02-13 16:36:18 -0800869 pid_t rc;
870 int status;
871
872 if (forkpid == 0) {
873 errno = 0;
874 rc = waitpid(-1, &status, WNOHANG | __WALL | __WNOTHREAD);
875 if (rc != -1 || errno != ECHILD) {
876 errx(2, "first waitpid returned %d (%s), expected failure with ECHILD", rc, strerror(errno));
877 }
878
879 raise(DEBUGGER_SIGNAL);
880
881 errno = 0;
882 rc = waitpid(-1, &status, __WALL | __WNOTHREAD);
883 if (rc != -1 || errno != ECHILD) {
884 errx(2, "second waitpid returned %d (%s), expected failure with ECHILD", rc, strerror(errno));
885 }
886 _exit(0);
887 } else {
888 rc = waitpid(forkpid, &status, 0);
889 ASSERT_EQ(forkpid, rc);
890 ASSERT_TRUE(WIFEXITED(status));
891 ASSERT_EQ(0, WEXITSTATUS(status));
892 }
893}
Josh Gao352a8452017-03-30 16:46:21 -0700894
895TEST(tombstoned, no_notify) {
896 // Do this a few times.
897 for (int i = 0; i < 3; ++i) {
898 pid_t pid = 123'456'789 + i;
899
900 unique_fd intercept_fd, output_fd;
Narayan Kamathca5e9082017-06-02 15:42:06 +0100901 InterceptStatus status;
902 tombstoned_intercept(pid, &intercept_fd, &output_fd, &status, kDebuggerdTombstone);
903 ASSERT_EQ(InterceptStatus::kRegistered, status);
Josh Gao352a8452017-03-30 16:46:21 -0700904
905 {
906 unique_fd tombstoned_socket, input_fd;
Narayan Kamatha73df602017-05-24 15:07:25 +0100907 ASSERT_TRUE(tombstoned_connect(pid, &tombstoned_socket, &input_fd, kDebuggerdTombstone));
Josh Gao352a8452017-03-30 16:46:21 -0700908 ASSERT_TRUE(android::base::WriteFully(input_fd.get(), &pid, sizeof(pid)));
909 }
910
911 pid_t read_pid;
912 ASSERT_TRUE(android::base::ReadFully(output_fd.get(), &read_pid, sizeof(read_pid)));
913 ASSERT_EQ(read_pid, pid);
914 }
915}
916
917TEST(tombstoned, stress) {
918 // Spawn threads to simultaneously do a bunch of failing dumps and a bunch of successful dumps.
919 static constexpr int kDumpCount = 100;
920
921 std::atomic<bool> start(false);
922 std::vector<std::thread> threads;
923 threads.emplace_back([&start]() {
924 while (!start) {
925 continue;
926 }
927
928 // Use a way out of range pid, to avoid stomping on an actual process.
929 pid_t pid_base = 1'000'000;
930
931 for (int dump = 0; dump < kDumpCount; ++dump) {
932 pid_t pid = pid_base + dump;
933
934 unique_fd intercept_fd, output_fd;
Narayan Kamathca5e9082017-06-02 15:42:06 +0100935 InterceptStatus status;
936 tombstoned_intercept(pid, &intercept_fd, &output_fd, &status, kDebuggerdTombstone);
937 ASSERT_EQ(InterceptStatus::kRegistered, status);
Josh Gao352a8452017-03-30 16:46:21 -0700938
939 // Pretend to crash, and then immediately close the socket.
940 unique_fd sockfd(socket_local_client(kTombstonedCrashSocketName,
941 ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET));
942 if (sockfd == -1) {
943 FAIL() << "failed to connect to tombstoned: " << strerror(errno);
944 }
945 TombstonedCrashPacket packet = {};
946 packet.packet_type = CrashPacketType::kDumpRequest;
947 packet.packet.dump_request.pid = pid;
948 if (TEMP_FAILURE_RETRY(write(sockfd, &packet, sizeof(packet))) != sizeof(packet)) {
949 FAIL() << "failed to write to tombstoned: " << strerror(errno);
950 }
951
952 continue;
953 }
954 });
955
956 threads.emplace_back([&start]() {
957 while (!start) {
958 continue;
959 }
960
961 // Use a way out of range pid, to avoid stomping on an actual process.
962 pid_t pid_base = 2'000'000;
963
964 for (int dump = 0; dump < kDumpCount; ++dump) {
965 pid_t pid = pid_base + dump;
966
967 unique_fd intercept_fd, output_fd;
Narayan Kamathca5e9082017-06-02 15:42:06 +0100968 InterceptStatus status;
969 tombstoned_intercept(pid, &intercept_fd, &output_fd, &status, kDebuggerdTombstone);
970 ASSERT_EQ(InterceptStatus::kRegistered, status);
Josh Gao352a8452017-03-30 16:46:21 -0700971
972 {
973 unique_fd tombstoned_socket, input_fd;
Narayan Kamatha73df602017-05-24 15:07:25 +0100974 ASSERT_TRUE(tombstoned_connect(pid, &tombstoned_socket, &input_fd, kDebuggerdTombstone));
Josh Gao352a8452017-03-30 16:46:21 -0700975 ASSERT_TRUE(android::base::WriteFully(input_fd.get(), &pid, sizeof(pid)));
976 tombstoned_notify_completion(tombstoned_socket.get());
977 }
978
979 // TODO: Fix the race that requires this sleep.
980 std::this_thread::sleep_for(50ms);
981
982 pid_t read_pid;
983 ASSERT_TRUE(android::base::ReadFully(output_fd.get(), &read_pid, sizeof(read_pid)));
984 ASSERT_EQ(read_pid, pid);
985 }
986 });
987
988 start = true;
989
990 for (std::thread& thread : threads) {
991 thread.join();
992 }
993}
Narayan Kamathca5e9082017-06-02 15:42:06 +0100994
995TEST(tombstoned, java_trace_intercept_smoke) {
996 // Using a "real" PID is a little dangerous here - if the test fails
997 // or crashes, we might end up getting a bogus / unreliable stack
998 // trace.
999 const pid_t self = getpid();
1000
1001 unique_fd intercept_fd, output_fd;
1002 InterceptStatus status;
1003 tombstoned_intercept(self, &intercept_fd, &output_fd, &status, kDebuggerdJavaBacktrace);
1004 ASSERT_EQ(InterceptStatus::kRegistered, status);
1005
1006 // First connect to tombstoned requesting a native backtrace. This
1007 // should result in a "regular" FD and not the installed intercept.
1008 const char native[] = "native";
1009 unique_fd tombstoned_socket, input_fd;
1010 ASSERT_TRUE(tombstoned_connect(self, &tombstoned_socket, &input_fd, kDebuggerdNativeBacktrace));
1011 ASSERT_TRUE(android::base::WriteFully(input_fd.get(), native, sizeof(native)));
1012 tombstoned_notify_completion(tombstoned_socket.get());
1013
1014 // Then, connect to tombstoned asking for a java backtrace. This *should*
1015 // trigger the intercept.
1016 const char java[] = "java";
1017 ASSERT_TRUE(tombstoned_connect(self, &tombstoned_socket, &input_fd, kDebuggerdJavaBacktrace));
1018 ASSERT_TRUE(android::base::WriteFully(input_fd.get(), java, sizeof(java)));
1019 tombstoned_notify_completion(tombstoned_socket.get());
1020
1021 char outbuf[sizeof(java)];
1022 ASSERT_TRUE(android::base::ReadFully(output_fd.get(), outbuf, sizeof(outbuf)));
1023 ASSERT_STREQ("java", outbuf);
1024}
1025
1026TEST(tombstoned, multiple_intercepts) {
1027 const pid_t fake_pid = 1'234'567;
1028 unique_fd intercept_fd, output_fd;
1029 InterceptStatus status;
1030 tombstoned_intercept(fake_pid, &intercept_fd, &output_fd, &status, kDebuggerdJavaBacktrace);
1031 ASSERT_EQ(InterceptStatus::kRegistered, status);
1032
1033 unique_fd intercept_fd_2, output_fd_2;
1034 tombstoned_intercept(fake_pid, &intercept_fd_2, &output_fd_2, &status, kDebuggerdNativeBacktrace);
1035 ASSERT_EQ(InterceptStatus::kFailedAlreadyRegistered, status);
1036}
1037
1038TEST(tombstoned, intercept_any) {
1039 const pid_t fake_pid = 1'234'567;
1040
1041 unique_fd intercept_fd, output_fd;
1042 InterceptStatus status;
1043 tombstoned_intercept(fake_pid, &intercept_fd, &output_fd, &status, kDebuggerdNativeBacktrace);
1044 ASSERT_EQ(InterceptStatus::kRegistered, status);
1045
1046 const char any[] = "any";
1047 unique_fd tombstoned_socket, input_fd;
1048 ASSERT_TRUE(tombstoned_connect(fake_pid, &tombstoned_socket, &input_fd, kDebuggerdAnyIntercept));
1049 ASSERT_TRUE(android::base::WriteFully(input_fd.get(), any, sizeof(any)));
1050 tombstoned_notify_completion(tombstoned_socket.get());
1051
1052 char outbuf[sizeof(any)];
1053 ASSERT_TRUE(android::base::ReadFully(output_fd.get(), outbuf, sizeof(outbuf)));
1054 ASSERT_STREQ("any", outbuf);
1055}