From d43d09c74656250c57a5974a47bd095947f02d9b Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Fri, 20 Sep 2019 06:13:08 -0700 Subject: [PATCH] fail soft if sandboxee exits before init is ptraced PiperOrigin-RevId: 270254470 Change-Id: Ifa13f4fe0e7ae91b79fc689e1d7dcb2a49b09cde --- sandboxed_api/sandbox2/monitor.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sandboxed_api/sandbox2/monitor.cc b/sandboxed_api/sandbox2/monitor.cc index b7ca26e..aaf74c2 100644 --- a/sandboxed_api/sandbox2/monitor.cc +++ b/sandboxed_api/sandbox2/monitor.cc @@ -205,7 +205,13 @@ void Monitor::Run() { &init_pid); if (init_pid > 0) { - PCHECK(ptrace(PTRACE_SEIZE, init_pid, 0, PTRACE_O_EXITKILL) == 0); + if (ptrace(PTRACE_SEIZE, init_pid, 0, PTRACE_O_EXITKILL) != 0) { + if (errno == ESRCH) { + SetExitStatusCode(Result::SETUP_ERROR, Result::FAILED_PTRACE); + return; + } + PLOG(FATAL) << "attaching to init process failed"; + } } if (pid_ <= 0 || (should_have_init && init_pid <= 0)) {