From nobody Tue Nov 17 17:01:51 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 4jTWH41Yb2z71QDq for ; Tue, 17 Nov 2026 17:01:52 +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 4jTWH36TYDz3Pp0 for ; Tue, 17 Nov 2026 17:01:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934911; 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=6c/IJzO1eosagOHtaMG1Tam44agMM4j+TqLdIUhlQk0=; b=Pm74uWenYPyIf/mOeMyAleAhqxX1Rq30u7LKzqtM8yNWnABDtfPpizdDGsC0d/0XeBpEBM /YSEBNQo/zBzHbXasigw5baIm9JyVTufoqPIfv/3b5udoRC9pDrNxejF4Gt0fdECJmgOkn fpQEgirmMtw4Cif/lduU+8wsX5/Zrf8HuPnAjHCK856PpbAh4Hl1fAegFdj4EQHCGT8oW+ 5fxP7HnEURtCrTpTkMpKAv2m6RxZzkh6jxLRjWvlwRygbHdOjZLtXHncZneVdmYhFbnzn4 SWA7cV7XkdJYbuLBX8BPoxNGsihFLdpvb0KemXaqYHcAmyHWYIUMYt3Ixs0KQw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794934911; b=gYZ1eEb7lOZ5lJyJS9jQQFzb8KBPnpK4zzBVmvaWz4LQsrRup2+i0Tuc8xYIMpoajalx8i YE1H8/BCPX+qcvqjjoSRmM7Ob4S7ZNgxVZ+V3k5Yk9t3zMeH/EXZha/UNjn1wmS2RvC8Mp ALJVWy667Gv1+DbIQAyuQGvVTjQgJi7NhfT99G7X74/Zdj4YdSlo9urp3tkUi+OL8Ai+sV FZtz1BebALu8ensLbQBntjxHQU5CZoDk7KeSY0pxK/NXmcZETeA0tzOnhgGxSv2mQlAmCP zxaktryVxs9M9vW+j0q5pCTPhCwe7Jymyba8pmuB3AiyHw25yiyB8TgUAZAr+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934911; 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=6c/IJzO1eosagOHtaMG1Tam44agMM4j+TqLdIUhlQk0=; b=Dys9v6L0P67FmzZIrvKMEMb9z07KzYJDlZR7AUPZwNJBq90iTKyVEYweK8wDQ2WsCh83UB oyHSJRCGgz3lHZVEY95NHOxJNGYb7LuYRGsS65u0L95pbMAbd7/YpBimkh3ZaPna51tkfw CnaAwQiQk6aGN9FEADwD31YAHSrlm7psMCFR/DpcpWEix7XgqIOsUqxcbdwtyJf3FSxlzO m5UefFDle3sVENqpNEXk9JTkb9E22EGTKGZz2PA136f3KXaK48dsRqORYCpQInrrNhzd6a Ye6fUI6M6vEVGxm1wTHKES2rfZO31JxvcysykZ9DkWA3/K6MV9WsolRpidKrQw== 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 4jTWH35fm2zrTg for ; Tue, 17 Nov 2026 17:01:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1c0fb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:01:51 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 3140e1888175 - main - kqueue: Fix a race when detaching a timer knote 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: 3140e1888175bb3920ae9f88c1b631833b73f97b Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:01:51 +0000 Message-Id: <6afc887f.1c0fb.5afb911c@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3140e1888175bb3920ae9f88c1b631833b73f97b commit 3140e1888175bb3920ae9f88c1b631833b73f97b Author: Mark Johnston AuthorDate: 2026-11-12 19:16:53 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:01 +0000 kqueue: Fix a race when detaching a timer knote We currently maintain a per-process list of stopped timer knotes, used when the owning process receives SIGSTOP. Upon receiving SIGCONT, queued timers are re-armed. When detaching a timer knote, we drain the callout and remove it from the queue, then check to see if the callout was re-armed by SIGCONT; if so, then we loop. However, the callout timer may fire before this check, and softclock_call_cc() clears the pending bit without the associated callout lock held, in which case filt_timerdetach() fails to observe that the callout is still running and doesn't drain. The callout handler then races with a free of the knote, and the resulting memory corruption can be exploited to obtain root privileges. Fix the problem by using an explicit flag that prevents re-arming a timer whose knote is in the process of being detached. Approved by: so Security: FreeBSD-SA-26:85.kqueue Security: CVE-2026-101320 Reported by: OpenAI Security Research Team Fixes: 2fd1ffefaa4d ("Stop arming kqueue timers on knote owner suspend or terminate") Sponsored by: The FreeBSD Foundation Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D61359 --- sys/kern/kern_event.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index e90397eb2c96..ba8c63267e84 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -808,7 +808,8 @@ struct kq_timer_cb_data { sbintime_t to; /* precalculated timer period, 0 for abs */ }; -#define KQ_TIMER_CB_ENQUEUED 0x01 +#define KQ_TIMER_CB_ENQUEUED 0x01 /* in queue of stopped timers */ +#define KQ_TIMER_CB_DETACHING 0x02 /* detach started, don't requeue */ static void kqtimer_sched_callout(struct kq_timer_cb_data *kc) @@ -876,7 +877,8 @@ filt_timerexpire_l(struct knote *kn, bool proc_locked) if (!proc_locked) PROC_LOCK(p); if (P_SHOULDSTOP(p) || P_KILLED(p)) { - if ((kc->flags & KQ_TIMER_CB_ENQUEUED) == 0) { + if ((kc->flags & (KQ_TIMER_CB_ENQUEUED | + KQ_TIMER_CB_DETACHING)) == 0) { /* * Insert into head so that * kqtimer_proc_continue() does not @@ -983,7 +985,8 @@ filt_timercopy(struct knote *kn, struct proc *p) kn->kn_ptr.p_v = kc = malloc(sizeof(*kc), M_KQUEUE, M_WAITOK); kc->kn = kn; kc->p = p; - kc->flags = kc_src->flags & ~KQ_TIMER_CB_ENQUEUED; + kc->flags = kc_src->flags & + ~(KQ_TIMER_CB_ENQUEUED | KQ_TIMER_CB_DETACHING); kc->next = kc_src->next; kc->to = kc_src->to; kc->cpuid = PCPU_GET(cpuid); @@ -1013,24 +1016,16 @@ filt_timerdetach(struct knote *kn) { struct kq_timer_cb_data *kc; unsigned int old __unused; - bool pending; kc = kn->kn_ptr.p_v; - do { - callout_drain(&kc->c); - - /* - * kqtimer_proc_continue() might have rescheduled this callout. - * Double-check, using the process mutex as an interlock. - */ - PROC_LOCK(kc->p); - if ((kc->flags & KQ_TIMER_CB_ENQUEUED) != 0) { - kc->flags &= ~KQ_TIMER_CB_ENQUEUED; - TAILQ_REMOVE(&kc->p->p_kqtim_stop, kc, link); - } - pending = callout_pending(&kc->c); - PROC_UNLOCK(kc->p); - } while (pending); + PROC_LOCK(kc->p); + kc->flags |= KQ_TIMER_CB_DETACHING; + if ((kc->flags & KQ_TIMER_CB_ENQUEUED) != 0) { + kc->flags &= ~KQ_TIMER_CB_ENQUEUED; + TAILQ_REMOVE(&kc->p->p_kqtim_stop, kc, link); + } + PROC_UNLOCK(kc->p); + callout_drain(&kc->c); free(kc, M_KQUEUE); old = atomic_fetchadd_int(&kq_ncallouts, -1); KASSERT(old > 0, ("Number of callouts cannot become negative"));