exit1(): clear P_TRACED before reparenting a traced child
When the exiting process traced a child, exit1() handed the child to
its real parent or to its reaper with P_TRACED still set, and cleared
the flag only afterwards. proc_reparent() does not re-enable
waitpid(2) for a traced child. A PD_NOWAITPID child whose last
process descriptor was closed while it was traced has no other zombie
reference, so after the SIGKILL that follows, nobody could reap it,
and with init as the reaper, the zombie and its pid leaked for good.
The tracer's own exit is enough to close the descriptor, since
fdescfree() runs before the children are reparented.
Clear P_TRACED before calling proc_reparent(), as PT_DETACH does.
This also keeps proc_reparent() from linking the child onto the orphan
list of the exiting process, so the explicit proc_clear_orphan() is no
longer needed.
Reported by: llm-postcr
Fixes: bcdb6ba94d08 ("processes: add zombie references, each of them prevents reap")
tests/sys/kern/procdesc: test exit of a non-reaper tracer
Check that the reaper can waitpid(2) for a PD_NOWAITPID child, after
the child's parent traced it and exited with the descriptor open.
proc_to_reap(): let the debugger wait for its exited tracee
exit1() clears P_TRACED of the exiting process, while proc_to_reap()
accepts a child without the PZOMBIEREF_PARENT reference only if the
waiter traces it. A PD_NOWAITPID process whose last process
descriptor was closed while it was traced has no zombie references at
all, so once it exited, its debugger got ECHILD from waitpid(2), and
the zombie stayed with the debugger until the debugger exited. Before
the zombie references, the debugger's wait collected the status and
gave the zombie back to the real parent, which proc_reap() still does.
For a zombie, recognize the debugger as the parent which is not the
real parent, and let it wait. The debugger holds none of the child's
zombie references, so proc_reap() now gives the child back without
dropping any. Otherwise a reference held elsewhere, e.g. by a process
descriptor, would leave the zombie on the debugger's children list,
and every later waitpid(2) would collect it again. For a child that
can be waited for, PZOMBIEREF_PARENT is now kept over the give-back
instead of being dropped.
Reported by: llm-postcr
Fixes: bcdb6ba94d08 ("processes: add zombie references, each of them prevents reap")
tests/sys/kern/procdesc: test the debugger's wait for its tracee
Check that a debugger, which is not the reaper, can waitpid(2) for its
killed PD_NOWAITPID tracee after closing the last process descriptor,
and that the reaper collects the child afterwards.
ptrace_test: use PD_NOWAITPID in procdesc_reparent_wait_child
The test expects that, after a debugger collected the exit status of
a child created by pdfork(2), the parent cannot collect the child with
wait(2). With the zombie references, a child created without
PD_NOWAITPID is waitable by its parent, and the test only passed
because the debugger's waitpid(2) dropped the parent's reference.
proc_reap() no longer lets the debugger take the exit status away
from the parent, so the parent's wait(2) now collects the child.
Create the child with PD_NOWAITPID, which is what hides it from
wait(2) now. Since waitpid(2) does not see it either, wait for its
stop with pdwait(2). The debugger's waitpid(2) in the test then also
covers collecting a tracee that has no waitpid reference.Details
Details
- Reviewers
markj
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
Comment Actions
Disclosure: the tests were auto-generated. Also an LLM helps me to formulate commit messages (perhaps you already see that).