🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

[Bug 301101] kqueue: KQUEUE_CPONFORK leaves copied EVFILT_SIGNAL knotes attached to the parent

#745
From: bugzilla-noreply
Date: Wed, 25 Nov 2026 14:54
93 lines
5922 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301101

            Bug ID: 301101
           Summary: kqueue: KQUEUE_CPONFORK leaves copied EVFILT_SIGNAL
                    knotes attached to the parent
           Product: Base System
           Version: 15.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me

A KQUEUE_CPONFORK child that inherits an EVFILT_SIGNAL knote
reports the parent's signals, while its own signals produce no
event on the inherited kqueue.

sig_filtops.f_copy is knote_triv_copy, a no-op. It was
added by 36138969847b (D52045), which set f_copy for several
filters; for EVFILT_SIGNAL the knote is process-specific.
kqueue_fork_copy_knote() copies the knote with *kn1 = *kn, keeping
kn_ptr.p_proc set to the parent, and adds the child's knote to the
parent's p_klist, where filt_sigattach() had bound the original.
releng/15.1 has both the flag (2002e0712320) and the line
(a8bf2a1a3c27); releng/14.4 has neither. This is the fork-copy
counterpart of the detach bug fixed by EN-24:03.kqueue (PR 275286,
ed410b78edc5).

On 15.1-RELEASE-p7 GENERIC amd64, unprivileged:

$ cc -Wall -Wextra -Werror -o kqueue_cponfork_signal kqueue_cponfork_signal.c
$ ./kqueue_cponfork_signal
kqueue CPONFORK EVFILT_SIGNAL
[parent] pid=1888, kq=3, EVFILT_SIGNAL(SIGUSR1) registered
[tester] pid=1889, inherited kq=3, parent pid=1888
[tester] control: raising SIGUSR1 on self
[tester] control: own SIGUSR1 produced no event
[parent] sending SIGUSR1 to self
[parent] exiting
[tester] event: filter=-6 ident=30 flags=0x20 fflags=0x0 data=1
[tester] parent pid=1888 is gone (exited and reaped)
[tester] kevent(EV_ADD) after reap returned 0
RESULT: WRONG_PROCESS

The control line is the tester's own SIGUSR1 producing no event;
the event line is the parent's SIGUSR1 in the tester's kqueue. The
reproducer exited 0. 16.0-CURRENT produced the same result; the
event and parent-exit lines appeared in the opposite order. The
program does not read the mutex word; it reports kevent's return
code only.

After the reap, that kevent locks and unlocks
kn->kn_knlist->kl_lockarg, the reaped parent's &p_mtx. proc_zone
is created UMA_ZONE_NOFREE, so the mutex is never destroyed and the
slot stays type-stable; when it is reallocated, that kevent locks
and unlocks the new process's p_mtx. A DTrace run on
16.0-CURRENT recorded proc_reap of the parent's address, no
proc_fini, proc_ctor reusing that address for a new process 26
microseconds later, and the child's kqueue_register after that. No
panic or hang was observed, and KASAN does not instrument this
zone (UMA_ZONE_NOFREE zones are excluded).

The patch restores the behavior before 36138969847b by making
EVFILT_SIGNAL ineligible for copying. kqueue_fork_copy_knote()
calls knlist_add() on the parent's list after f_copy returns, so
a reattaching copy is not a one-line replacement. The other
filters changed by D52045 watch objects whose attachment remains
valid in the child.

A 15.1-RELEASE-p7 kernel built from pristine releng/15.1
sources with only this patch prints RESULT: CLEAN. The tester
reports no event from the parent's signal. In the cross-UID
test, the stock kernel counts a root parent's signals with
security.bsd.see_other_uids=0; the patched kernel reports no
event. The root parent had to create the kqueue and fork the
tester before the tester dropped to uid 65534. On the stock
kernel, three SIGUSR1s sent to a process that reused the
parent's struct proc slot produced no event. DTrace confirmed
that process occupied the parent's former slot. Not tested:
releng/14.4 (which lacks KQUEUE_CPONFORK) and 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-301101-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 301101] kqueue: KQUEUE_CPONFORK leaves copied EVFILT_SIGNAL
 knotes attached to the parent
Date: Wed, 25 Nov 2026 14:54:08 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301101-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="85713"; 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=1795618448;
	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=xzgyv3Nk3ZBU/v4kj67RWInUmJeiYAHjsEfTuRgM110=;
	b=BEm03DCttNYS1brY9y/AAAXuFcFK4Qdf27Sz+yVq3ESnXUO5p8VjqEcFcDlp3w9Nuhszwn
	Q+5+eCN4D85yWkjNBlUgfym6Gsg9R8Qobd6YDVD1OxBMh4t2QPiYDCJSHzrIOcu1OxHIHT
	+ky+5RdwFYprpl1ebXYaCqS7ooNYvvmSKxcHSKdccDM4alsN5I6Z9HiZ6/WbXMGr3+3AIh
	BDy5kcTi84f7sM1gFR3XlvR043bMGpzPiN4taCyXWUUgBw/NTiqfW3rGLcAk44NvLLHe/K
	JqLq/a1PL4zkY38+1TMC5C4Z4bEL5eQQbduFOdwLt5iZ14GEVwFdluzlpqCx0g==
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