From nobody Thu Apr 9 02:37:32 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 4frkcK5jwFz6YGS4 for ; Thu, 09 Apr 2026 02:37:37 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4frkcK2SCcz3VRd for ; Thu, 09 Apr 2026 02:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1775702257; 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=+uufCaTZjBEfd45e1G6cyIZphohMPKTm3j/Gkr08g10=; b=dwZYCWaciBAQ1lUG3v9qsavY4e87eIoEpchcDwCq4fqADPpNckbfY9zap3tcYAe9T3dGDM LERegpIjN5Vwn8oTPW7qTHL/V9+cJ6AIVw745uiixIE2+dva1a87lLNOaQJWVfvrJR/52S pc3yOD15JYuoeecyTpiVthcM3I3HTjTWBI/x4qFpKCWSV2ROUShs2R91snYwzsaqvfHKDt cDky7vRU3qYpZbAC9IvJEckZ9IEivHhFE0X6gT+westF8ieAqp2VgVTTN4XY6P+5pjmZZN S8+ik5qEOjbmQjNqczMXxXjPLoNDWGASIE3WF6KlI5SopEBZG8Z81DtLPuiRFA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1775702257; a=rsa-sha256; cv=none; b=xbJbMdDfSD2EK4zixgzbKpKMlFutwbS0LE4aT6H5HtaWNbyo1z7b6Nz1pe4Jl/Ne4TMalB 6mFaLDs5qVvfGOtKI4zIwwO2J6CgISOLmmquRHwtx7MaCdB18FHO8O1m7qWEzpy5fmggkA IHef/2t4jNajAOaJYR30IaFef70sStVutmh1tyURZ/I0IiBc7FgY36DgrhZnMa6J9q+qOQ YTEQ/IO+9CfpkwrrlD3ULLQ3xoCjNrzR8PUJbJe821mBq6Lt1LXhWX3J1TX3JTyRGeNiR3 kwoZVJe8qmv2XUMbepbxRRazlOx49QvOCJwuyhGHSipUWRVzmj4r4fXaNFcG+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1775702257; 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=+uufCaTZjBEfd45e1G6cyIZphohMPKTm3j/Gkr08g10=; b=RN/ZZTeH9kHcrqCaD4KQd7M2BZX4chudbBisn0diHKnp3j/XZ73BvrRhSCY/eE+0vIEfbS 0BuDhgYRM2adrHjDScg4Cu+Sf523HSfLmtHGyxcQf0x5eGDTe0iyCBSuSeP9+Yts6ieUgT fWk832aBx2bwBKiD2kmp/nGoAS33yxg1Ganc/sR1Y35yPYvR6FnLx4CyR1Ase8GYU2cN0B /mNROqzwIyayuU7GwO3aeXcZnXQCB9mdJP8k3pz7wh+QjUZ4QeGS0m/P4tJFi5lkEqnsZf LCviJJXoYNHzJuhR2qvDG6aIcNemUbtERkGBAKSIabNvXuOAPQC+31I0ofdO5g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4frkcK1gQ4zv9Z for ; Thu, 09 Apr 2026 02:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 409d6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 09 Apr 2026 02:37:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 0bf4d22c3708 - main - kqueue: don't leak file refs on failure to knote_attach() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0bf4d22c37083170961c31694b90551538901a1c Auto-Submitted: auto-generated Date: Thu, 09 Apr 2026 02:37:32 +0000 Message-Id: <69d710ec.409d6.57f17cbc@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=0bf4d22c37083170961c31694b90551538901a1c commit 0bf4d22c37083170961c31694b90551538901a1c Author: Kyle Evans AuthorDate: 2026-04-09 02:37:00 +0000 Commit: Kyle Evans CommitDate: 2026-04-09 02:37:11 +0000 kqueue: don't leak file refs on failure to knote_attach() We'll subsequently just knote_free() since the knote is barely constructed, but that bypasses any logic that might release references on owned files/fops. Defer clearing those until the knote actually owns them and update the comment to draw the line more clearly. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D56318 --- sys/kern/kern_event.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 0d37327f14bd..1deb7a705c56 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1822,12 +1822,6 @@ findkn: kn->kn_fp = fp; kn->kn_kq = kq; kn->kn_fop = fops; - /* - * apply reference counts to knote structure, and - * do not release it at the end of this routine. - */ - fops = NULL; - fp = NULL; kn->kn_sfflags = kev->fflags; kn->kn_sdata = kev->data; @@ -1848,6 +1842,16 @@ findkn: goto done; } + /* + * We transfer ownership of fops/fp to the knote + * structure and avoid releasing them at the end of + * this routine, now that all of the remaining exit + * paths will knote_drop() to release the reference + * counts we held on them above. + */ + fops = NULL; + fp = NULL; + if ((error = kn->kn_fop->f_attach(kn)) != 0) { knote_drop_detached(kn, td); goto done;