Skip to content

Commit

Permalink
Handle cases where the pid-1 process in a pid namespace can't be targ…
Browse files Browse the repository at this point in the history
…eted by ptrace() (ESRCH) because it's waiting for other processes in the namespace to exit.

These cases generate a fake PTRACE_EVENT_EXIT event, but we need to wait for the real exit event.

Resolves #3504
  • Loading branch information
rocallahan committed Jul 16, 2023
1 parent 0e37796 commit 3ef59d9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/RecordSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ static bool handle_ptrace_exit_event(RecordTask* t) {
return false;
}

if (t->waiting_for_pid_namespace_tasks_to_exit()) {
// We could be waiting for other processes in the pid namespace to exit,
// which causes ptrace to report ESRCH, triggering our synthetic-PTRACE_EVENT_EXIT
// cleanup path. Check if we're in a real ptrace stop.
siginfo_t dummy_siginfo;
if (!t->ptrace_if_alive(PTRACE_GETSIGINFO, nullptr, &dummy_siginfo)) {
t->waiting_for_ptrace_exit = true;
return true;
}
}

if (t->stable_exit) {
LOG(debug) << "stable exit";
} else {
Expand Down

0 comments on commit 3ef59d9

Please sign in to comment.