From 66700b2c86dbef43c2b14800f84caa06eb9d2864 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 5 Dec 2016 15:50:47 +0100 Subject: executor: change the way we wait for children waitpid(pid) does not work if child invokes ptrace(PTRACE_TRACEME): https://groups.google.com/forum/#!topic/syzkaller/SjWzOnNRRIU Use waitpid(-1) instead. --- executor/common.h | 5 +++-- executor/executor.cc | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'executor') diff --git a/executor/common.h b/executor/common.h index 19da79b5e..472db554c 100644 --- a/executor/common.h +++ b/executor/common.h @@ -658,7 +658,7 @@ void loop() int status = 0; uint64_t start = current_time_ms(); for (;;) { - int res = waitpid(pid, &status, __WALL | WNOHANG); + int res = waitpid(-1, &status, __WALL | WNOHANG); int errno0 = errno; if (res == pid) break; @@ -666,7 +666,8 @@ void loop() if (current_time_ms() - start > 5 * 1000) { kill(-pid, SIGKILL); kill(pid, SIGKILL); - waitpid(pid, &status, __WALL); + while (waitpid(-1, &status, __WALL) != pid) { + } break; } } diff --git a/executor/executor.cc b/executor/executor.cc index a51bd2e46..677d2919f 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -186,7 +186,7 @@ int main(int argc, char** argv) fail("clone failed"); debug("spawned loop pid %d\n", pid); int status = 0; - while (waitpid(pid, &status, __WALL) != pid) { + while (waitpid(-1, &status, __WALL) != pid) { } status = WEXITSTATUS(status); if (status == kFailStatus) @@ -241,7 +241,7 @@ void loop() int status = 0; uint64_t start = current_time_ms(); for (;;) { - int res = waitpid(pid, &status, __WALL | WNOHANG); + int res = waitpid(-1, &status, __WALL | WNOHANG); int errno0 = errno; if (res == pid) { debug("waitpid(%d)=%d (%d)\n", pid, res, errno0); @@ -253,10 +253,12 @@ void loop() debug("killing\n"); kill(-pid, SIGKILL); kill(pid, SIGKILL); - int res = waitpid(pid, &status, __WALL); - debug("waitpid(%d)=%d (%d)\n", pid, res, errno); - if (res != pid) - fail("waitpid failed"); + for (;;) { + int res = waitpid(-1, &status, __WALL); + debug("waitpid(%d)=%d (%d)\n", pid, res, errno); + if (res == pid) + break; + } break; } } -- cgit mrf-deployment