DragonFlyBSD Kernel Audit
DF-0113 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -352,8 +352,13 @@
 			if (p->p_oppid != p->p_pptr->p_pid) {
 				struct proc *pp;
 
+				/*
+				 * p_oppid may have been recycled since PT_ATTACH;
+				 * only reparent if the found proc is a plausible parent
+				 * (different from current parent and from ourselves).
+				 */
 				pp = pfind(p->p_oppid);
-				if (pp) {
+				if (pp && pp != p->p_pptr && pp != p) {
 					proc_reparent(p, pp);
 					PRELE(pp);
 				}