From nobody Tue Nov 17 17:01:52 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 4jTWH54Yf0z71QWk for ; Tue, 17 Nov 2026 17:01:53 +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 4jTWH46StGz3PsC for ; Tue, 17 Nov 2026 17:01:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934912; 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=TIcNcImGzjeR/3zwcPtwT7PPWig7xrw+BdXaXIT3cmA=; b=LC/r5gUrg6KvMb4cXchwWfIRjVe5BwuvaCFEFkUN9GIDAkYHTJN3nNALdnPoVsdoaGLQxw 2UhUxkZBXNdirrFNBgVV1DVvfW8+zbAwNF7/3hadZvVLI4vo40fu1U+S53lybNQSKrxwuj CJM3kEv7TBkQVVF3aEpzR989Oi16K4Gj3vVJOH/uG/R3g7zAosT5qoeCr7w3X7PZjkk77r jSfGTG+oEvZs0Tw+zezUZPKoyM6fC0k/K+WXcbrXR7Zqr5E1Qkn7UiozSTnNkbqEtF0sgu 5ky/EUjT4N/36E2nqQH/+VxxXkLpVuN0yA68a2V2BwPUwKki+fSDTGv1U1ML8g== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794934912; b=Wlej+3xGHvclQwAL/lAy2xGZoZOSG55QQphoQbXcXvGbyjSNt86/xrlhyKgkbNMH602WA3 XRJi9EVcrsRAgitgPtovATBySkll5HvYEf88KSMQVcNVbwCUEPcU2Rq+hZU3mFSna01F0e Vm9lCYv4IOSuMOyzds7TxNZ1SL0U/3yv/1nds3N2LmfeXgbv7ZLuCZ7tUF/xNgGky+CQen /Z8ow+C3z5ffx6SQ2/nfdEGKk0VPyCl6Qv45djv75NGgRozXGYbjL+K1+uOgw53n8VjpNg OsmOY7L+Ebrap62TvZSoxcuZufF6QeaUCou7/vN1I2YpEPoIA9B/xdUF1d5gqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934912; 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=TIcNcImGzjeR/3zwcPtwT7PPWig7xrw+BdXaXIT3cmA=; b=b0BUcn/Z4s15Nl9YVFiotpguwkwGMTbTJgG9RmADjX3ZzuPLA/+pAcfCK9w6WN+U+uXRe1 hn90RLm4gdSzWvJa3ejWU6z3mRTWaqB6Ymb7okvKnFkhapYALWT0xSiFLXHR6Hu51fNFXs m7MGaK/MpJsZcC4TvrBXSqfU7NN+VPB4xwvTrKLgQTvU07V47Ka9nvDkENl8QdiE+WY9l8 SwaTcUzZDjGFlx8p/2fNe1PJWotxoRjplTYpfJ9v6unwK21JtWhUZBvr43cA0tPlGFyXWK QlUyDkvvyuOf5dpZpSewjA94wko+0Iq/aKHOHefyCgMP4yGNMXodT+SPFgS7qw== 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 4jTWH467mvzrg0 for ; Tue, 17 Nov 2026 17:01:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1efbf by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:01:52 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c0ce115b714b - main - 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/main X-Git-Reftype: branch X-Git-Commit: c0ce115b714b5f7f7c2c459561201ed8bbf7fb9f Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:01:52 +0000 Message-Id: <6afc8880.1efbf.1bc93e03@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c0ce115b714b5f7f7c2c459561201ed8bbf7fb9f commit c0ce115b714b5f7f7c2c459561201ed8bbf7fb9f Author: Mark Johnston AuthorDate: 2026-11-16 13:46:51 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:01 +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 ba8c63267e84..ed9db7cebc60 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -3136,15 +3136,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 || @@ -3160,7 +3171,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); } } @@ -3184,13 +3195,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);