🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #702

[Bug 301072] procdesc: procdesc_close() links a traced child onto its own reaper's orphan list, panicking the kernel at child ex...

#702
From: bugzilla-noreply
Date: Tue, 24 Nov 2026 08:08
141 lines
8263 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301072

            Bug ID: 301072
           Summary: procdesc: procdesc_close() links a traced child onto
                    its own reaper's orphan list, panicking the kernel at
                    child exit
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me
                CC: kib@FreeBSD.org

procdesc: procdesc_close() links a traced child onto its own reaper's
orphan list, panicking the kernel at child exit

procdesc_close() handles the last close of a process descriptor for a
still-running traced child by linking it onto its reaper's orphan
list without checking that the reaper is not already the child's
parent:

                        } else {
                                proc_clear_orphan(p);
                                p->p_oppid = p->p_reaper->p_pid;
                                proc_add_orphan(p, p->p_reaper);
                        }

(sys/kern/sys_procdesc.c:473-477, verified on main 408af93b4bb3; the
same unconditional call is on stable/15 and releng/15.1.)

When the closing process has PROC_REAP_ACQUIRE'd, p_reaper == p_pptr,
so the child ends up on its own parent's orphan list. The
proc_realparent() invariant asserts an orphaned child's real parent
differs from the list owner (sys/kern/kern_exit.c:127,
af495ad4a98a "proc_realparent(): assert that an orphaned child has
real parent != parent"), and killjobc() calls proc_realparent() on
exit1() of the child, so the child's exit after the close panics an
INVARIANTS kernel. The reproducer exits the child with kill(2)
after a PT_DETACH (observed, twice); the SIGKILL that
procdesc_close_tail() itself sends for a non-PD_DAEMON descriptor
takes the same exit1() path (verified from source, not run
separately).

The trigger needs no privilege:

  procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL);
  pdfork(&fd, PD_DAEMON | PD_NOWAITPID);
  /* child: close(fd); ptrace(PT_TRACE_ME); raise(SIGSTOP); */
  /* parent: waitpid(stop); close(fd);
             ptrace(PT_DETACH, child); kill(child, SIGKILL); */

PD_NOWAITPID is required on main/stable-15 because kern_fork.c sets
PZOMBIEREF_PARENT for the child otherwise, and procdesc_close()'s
outer guard skips the whole branch when that bit is present
(bcdb6ba94d08 "processes: add zombie references, each of them
prevents reap"). On releng/15.1 the call runs for plain PD_DAEMON
too, since the zombieref guard does not exist there.

Two effects, both reproduced on 16.0-CURRENT GENERIC-KASAN
(main-6edecf52def6-dirty, Nov 22 2026 build) as a non-root user:

1. Kernel panic. Two runs, two boots, identical panic:

panic: proc 2147 0xfffffe0145327038 orphaned but parent 2146
0xfffffe00f2830000 is realparent
KDB: stack backtrace:
proc_realparent() at proc_realparent+0x173
killjobc() at killjobc+0x421
exit1() at exit1+0xa40
kern_exit() at kern_exit+0x13f
sigexit() at sigexit+0x137

Reading the crash dump with kgdb (first run's dump, vmcore.0)
shows the panicking thread is the CHILD (PID 2131, command "rso"),
in exit1(td, rval=0, signo=9): the parent's explicit SIGKILL is
delivered on the child's return to user mode, and its exit walks
the self-orphan link through killjobc() -> jobc_parent() ->
proc_realparent() (panic at kern_exit.c:127). The second run's
dump (vmcore.1, pids 2147/2146, cpuid=1) has the identical stack.
Full traces of both panics are in the observed-evidence
attachment.

2. Unreapable zombie, no panic. Verified from source on main: a
traced child that exits while still traced (no detach) becomes a
zombie with p_zombieref == 0 that no waitpid() can collect, since
kern_wait's P_ALL guard (kern_exit.c:1225) and proc_to_reap
(kern_exit.c:1281) both reject it. The same strand reproduces in
the untraced arm (observed on the same kernel):

waitpid(2114, WNOHANG) = -1 errno=10
kill(2114, 0) = 0 errno=10

The untraced arm reaches the same p_zombieref == 0 state through
proc_reparent()'s early return: for a self-reaper,
proc_reparent(p, p->p_reaper, true) returns at the
"if (child->p_pptr == parent)" check without executing the tail
that re-grants PZOMBIEREF_PARENT (kern_exit.c:1710-1714), so an
untraced PD_NOWAITPID child of a self-reaper SIGKILLs at close
and its zombie is equally stranded. The observed line above is
that untraced run (repro_untraced_strand.c); I did not run the
still-traced variant on a non-INVARIANTS main kernel.

Controls: with CONTROL=1 (same sequence, no PROC_REAP_ACQUIRE) the
child is handed to init and both reproducers reap cleanly. On
15.1-RELEASE-p7 GENERIC the trigger and control both reap normally
(the orphan-add is present but self-heals: proc_realparent() has no
assert there, and exit1()'s traced-children loop clears the orphan
link before any walk); on 16.0-CURRENT main-n287061 (June 2026
GENERIC, predating bcdb6ba94d08) both run clean as well. So the
user-visible defect is main and stable/15: on main, amd64 GENERIC
includes std.debug, so the stock GENERIC kernel has the assert and
panics; stable/15 GENERIC does not include std.debug, so there the
defect is the unreapable zombie.

The attached patch checks p_pptr != p_reaper before adding the
orphan link, and grants PZOMBIEREF_PARENT to the child in the two
self-reaper arms so the zombie stays collectable, mirroring what
proc_reparent()'s tail does for a real reparent. I booted a
GENERIC-KASAN kernel built from main + this patch (build and boot
2026-11-24, same config as the panic kernel): the traced trigger
that panicked the stock kernel now returns from waitpid with the
child's status (status=0x9), the untraced trigger collects normally
instead of stranding a zombie, and the control run is unchanged.
No KASAN report fired on the patched kernel.

I have not tested the patch on stable/15 or on any release branch,
and not on arm64.

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <bug-301072-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 301072] procdesc: procdesc_close() links a traced child onto
 its own reaper's orphan list, panicking the kernel at child exit
Date: Tue, 24 Nov 2026 08:08:07 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301072-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="62711"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1795507687;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=stnmgX1t1A3vQDAIpTsPNUNJm3Dzlb0wxljWVzkmZww=;
	b=dBE0RhZVO2g9G3gfX2afNYemTXfPKQPvWRV2iROcnNpL5mCQpR0A6Q6tB2UT3Lj6Q8pe8p
	Yv4IhmmPfDwhb4OQhOTEYSuO2jYrN4lN4tiIdgNbmsyNv/R+mHuHhUAmYuLd+8PsbAkfYJ
	g5hLeSfQZtuBjB3tWiYSDjHfApT9mSToQkxyUYtzZuYzCBHNXN+hiSznGBC1xpXFqcrLab
	skckmjTW/YlD6yZBvNtDNcKB+tNHatjSbZd4dXyoRA+HQSis5S93hsS2msUWCpylI6lugj
	RHswIkWbCARaPIDOKQx7iiYKwDYab9XhuYZ+Jeu4E6uZnS+VHO3q60fEM5LKKg==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes