From nobody Tue Nov 17 17:08:22 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTWQZ6NxFz71SLn for ; Tue, 17 Nov 2026 17:08:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTWQZ0yLDz4N1S for ; Tue, 17 Nov 2026 17:08:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935302; 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=9TiIeVYwORWtshPCuivKiKJk5L6c0mqkLxiMAd9VqQI=; b=Mp8SxYftoeeRWokBC0jYAuB2NRM5Iaxv4QHv4A636JqTOkwP12iKqdS1i7zNaP9VyTnZgv Y9sGvdYkjMy28NRx6e3gX74U/h4wG5ewoECFDGkTePJ75+GQXMNHu8k/AxXlFmKXFtkLvO SxcUn2b2yzXfV2tUEck1VgLYqeiaQZSJsrknDlf2f9L8d0RRCuo8qTeQns4Z19qWBLEcsg rnqEY0Hhkx8V5h+5O63oA5FAs1rTjy5O7nJ7J9VRBRxYHKVfGfSGMxTEcTptVvDQYGj2tp YQUX4rEL1+1iPmFvAVmXF4p30LAD8ermYLt1K9X1lbCLththBt3w8ck2P3XSlA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935302; b=yC3RyD30/MOBNubkO+mSegnX/HtvL07IOJ5aBmReKt9sN13qJV0elbfNl4HSWN9nKXkemp z+S4t/0Q33rdV8+uH6IYPopU8u3CZ0VoukVv1mHuvUwGfd+KspbGhY1wr54aCUS5xTB4Wh 5Q58bSQZQ82X2J5BWi8e0uJ19eRafy7qGcXDW9tRo/WacQ+wuyj3hAKGtWUSKafsy1B9Qw 7jfPc/Q0qjqlag2OQY49qCUNtR1sXhOZ6gL3YDBP2hQKsetlV0DgNP9iYWNZcFLnwT88o1 qvYgBQvkeByVLsYr0xJE3+ruIHEvzx4i4YjU3JmgzrEbsfjgCE3pNzT/dg/YWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935302; 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=9TiIeVYwORWtshPCuivKiKJk5L6c0mqkLxiMAd9VqQI=; b=cZP3A+LPDkIOIhsI0IO1b9xVDS1nz75EUyODRwednc39nk3oUUwCaur40h1+lQPOVibbpT PwTcy+BZg2QOLkax6/TpgRvKB3Z2PvnIYElc7fwGERa4OFp/1ML+56tV/YbDeGIGzc94cb 6f48lbH2jcIMQQJycYmqwNu2hIhtxUdBtZ5WJyo+Mb33cknbUsC26LIKZX6T+/B74p/b+0 b9aXeeY7TsdM0sPzsChEYDZ1JHvKj44niHLxQW4Mom9I+nxIkLsRQ2elrISlgm1JRzDBmZ HAdax/NjOHDWt8gXIUG6A2mPhRpxDXTy0upK2EaxKn7/QPake8YSGoINhg1MlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTWQZ0c5tzrsT for ; Tue, 17 Nov 2026 17:08:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1e555 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:08:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 701478cfd697 - releng/15.1 - kqueue: Fix a race between kqueue_fork_copy_list() and kqueue_expand() List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.1 X-Git-Reftype: branch X-Git-Commit: 701478cfd69762403b9c38c7204ec5beb5962313 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:08:22 +0000 Message-Id: <6afc8a06.1e555.f5398a7@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=701478cfd69762403b9c38c7204ec5beb5962313 commit 701478cfd69762403b9c38c7204ec5beb5962313 Author: Mark Johnston AuthorDate: 2026-11-16 13:46:51 +0000 Commit: Mark Johnston CommitDate: 2026-11-16 21:25:02 +0000 kqueue: Fix a race between kqueue_fork_copy_list() and kqueue_expand() While kqueue_fork_copy_list() is iterating over the knote lists, the backing array may change while the kqueue lock is dropped. Since each list is a singly-linked list, kqueue_fork_copy_list() must start iterating from the list head in order to remove the marker, but that list head pointer is invalid after kqueue_expand() runs. Add a bit of indirection to re-compute the correct list head each time the kqueue lock is dropped. Avoid changing the layout of struct knote since I want to backport this to releng branches. Approved by: so Security: FreeBSD-SA-26:85.kqueue Security: CVE-2026-127750 Reported by: Dennys Kaluzny Pereira Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D61608 --- sys/kern/kern_event.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 937a5c87cb5f..476e48b072ae 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -3138,15 +3138,26 @@ kqueue_fork_copy_knote(struct kqueue *kq, struct kqueue *kq1, struct knote *kn, KQ_UNLOCK(kq1); } +enum klist_which { + KLIST_FD, + KLIST_HASH, +}; + +static struct klist * +kqueue_list(struct kqueue *kq, enum klist_which which, int i) +{ + return (which == KLIST_FD ? &kq->kq_knlist[i] : &kq->kq_knhash[i]); +} + static void -kqueue_fork_copy_list(struct klist *knlist, struct knote *marker, +kqueue_fork_copy_list(enum klist_which which, int i, struct knote *marker, struct kqueue *kq, struct kqueue *kq1, struct proc *p1, struct filedesc *fdp) { struct knote *kn; KQ_OWNED(kq); - kn = SLIST_FIRST(knlist); + kn = SLIST_FIRST(kqueue_list(kq, which, i)); while (kn != NULL) { MPASS(kn->kn_kq == kq); if ((kn->kn_status & (KN_DETACHED | KN_MARKER)) != 0 || @@ -3162,7 +3173,7 @@ kqueue_fork_copy_list(struct klist *knlist, struct knote *marker, kn_leave_flux(kn); kn = SLIST_NEXT(marker, kn_link); /* XXXKIB switch kn_link to LIST? */ - SLIST_REMOVE(knlist, marker, knote, kn_link); + SLIST_REMOVE(kqueue_list(kq, which, i), marker, knote, kn_link); } } @@ -3186,13 +3197,12 @@ kqueue_fork_copy(struct filedesc *fdp, struct file *fp, struct file *fp1, KQ_LOCK(kq); for (i = 0; i < kq->kq_knlistsize; i++) { - kqueue_fork_copy_list(&kq->kq_knlist[i], marker, kq, kq1, - p1, fdp); + kqueue_fork_copy_list(KLIST_FD, i, marker, kq, kq1, p1, fdp); } if (kq->kq_knhashmask != 0) { for (i = 0; i <= kq->kq_knhashmask; i++) { - kqueue_fork_copy_list(&kq->kq_knhash[i], marker, kq, - kq1, p1, fdp); + kqueue_fork_copy_list(KLIST_HASH, i, marker, kq, kq1, + p1, fdp); } } kqueue_release(kq, 1);