git: a16f0b2e5c6a - main - procdesc_close(): grant waitpid(2) when the reaper is already the parent
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 25 Nov 2026 09:50:33 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=a16f0b2e5c6a9ea396147e6a832d8d999e85a95a
commit a16f0b2e5c6a9ea396147e6a832d8d999e85a95a
Author: Laam Alif <laamalif@proton.me>
AuthorDate: 2026-11-24 08:11:56 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-25 09:49:59 +0000
procdesc_close(): grant waitpid(2) when the reaper is already the parent
When the process is already a child of its reaper, proc_reparent()
returns early and does not re-enable waitpid(2), so after the last
process descriptor was closed nobody could reap the zombie. If the
reaper was also tracing the process, it was additionally linked onto
the reaper's own orphan list, and after PT_DETACH it stayed there
untraced, again without a waitpid(2) reference.
PR: 301072
Reviewed by: kib, markj
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61975
---
sys/kern/sys_procdesc.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 95ce028c6f15..9f5ca155bfe5 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -468,11 +468,23 @@ procdesc_close(struct file *fp, struct thread *td)
* finally, terminate with prejudice.
*/
p->p_sigparent = SIGCHLD;
- if ((p->p_flag & P_TRACED) == 0) {
- proc_reparent(p, p->p_reaper, true);
- } else {
+ if ((p->p_flag & P_TRACED) != 0) {
+ /* Make the reaper the real parent. */
proc_clear_orphan(p);
p->p_oppid = p->p_reaper->p_pid;
+ }
+ if (p->p_pptr == p->p_reaper) {
+ /*
+ * The reaper is already the parent, and
+ * maybe the tracer. Nothing needs
+ * relinking, and proc_reparent() would
+ * not re-enable waitpid(2), so grant
+ * the reference.
+ */
+ p->p_zombieref |= PZOMBIEREF_PARENT;
+ } else if ((p->p_flag & P_TRACED) == 0) {
+ proc_reparent(p, p->p_reaper, true);
+ } else {
proc_add_orphan(p, p->p_reaper);
}
}