From nobody Mon Oct 12 16:05:58 2026 X-Original-To: dev-commits-src-main@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 4j3MlJ0Rftz6w2LB for ; Mon, 12 Oct 2026 16:06:04 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j3MlH6XnZz4HJM for ; Mon, 12 Oct 2026 16:06:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791821163; 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=dXUNSu4tzhi3yZOr1ksNi+GUPokF8driUVmLphgADwQ=; b=eRSyMloCC1DXt6wku3YFFu0mlZMdb8t5UJw7MC5B6Ps2dfO3f2zFOgZbIclSOteRSXCia1 Qq/3g+iGzycRILha4GdOIHhuS+VmpNnL9gW9+yjlKZDGaDTpkgcsHb6g2EHXmb9sid8M7v lwFAfVk6ryrwfr5evuruGLiVq3tYYWlf6DdGui6D0a2yLJ5SjkgD4Gx+dovqr/XHZC8bQ1 XYCG5XVqlwRQRTHALJL5S5arNnJjWdM538YB1bE0n4Q0V4rE8bcvueEAftsaI1ovdxMJdR 5hnsyj2n6LTylNex2AxG4IZfiwuNVMCbB07hZxkmqBG9h5O9jFvGHGUHvYaRfg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791821163; b=asnGKnBCKX68j2NCoC8SyWUv2AR4FGtvm+Q53k8uZZZHAa42dymflKCEDGR7oLLE98k5IC GSsoO+ScYzfFaPOu3J/lb+P0EVTHp6IsNoVq9SeI97ahD7vr/LZmf1/bV71SI69Y/QO+VT Msx/taNnLgw0JLu+zGZyGYpEm36gIf7EoSJy0YXkw4SJCYg8nEOFbaIhTUIfpDsJYNX8Ew s4guKpla9SoQc50t8a5YdvZTaE3RGWKdBpufTKtTU5EeN9GVRJu58Aw/a1Fdo31EMLuZhx HDnhCvhX+c2emqEK8YNbR0MZUNehuTrugAqwfocksTlGQrmGZ2FoCTDIV5NiXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791821163; 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=dXUNSu4tzhi3yZOr1ksNi+GUPokF8driUVmLphgADwQ=; b=UleItwbOyMXEKmrX56B1BY/PdYu3ofF8MPa39Qx9vHyXGQrdWoMSp9BjjpBNB7MVCvUFIa 2+yKuz1vaN9ePIZmZ7J9vxCZbsPqAnHzSZ422e+Kp83IQjjOuARtvn6AywSbTQrXkhJS51 CX5LxaPnLs0aQk/7ZT3liKhj+9kNohLETOw40tFc6ExkO1ClLnvbE4MPudoosBD3KmTMaB LCaIIKPDpRNwJmqIDGBNsFavYYTeOCYO1byELa0ejNSseJwbWRA4orFdyufjs+MOZAtTaD 7m7NG1syr/0c06MTEGFjcQ+4q39Tq26M5LgGT0QI/sLSv/fKeJrhxGjULBRxiQ== 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 4j3MlH5K2FzcHH for ; Mon, 12 Oct 2026 16:06:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2081b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 12 Oct 2026 16:05:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 25f04bf42786 - main - pf: do not free the caller's ruleset when attaching a table fails List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 25f04bf42786806e2661b7a09c283b83f568380a Auto-Submitted: auto-generated Date: Mon, 12 Oct 2026 16:05:58 +0000 Message-Id: <6acd0566.2081b.99a829e@gitrepo.freebsd.org> The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=25f04bf42786806e2661b7a09c283b83f568380a commit 25f04bf42786806e2661b7a09c283b83f568380a Author: Kristof Provost AuthorDate: 2026-10-12 08:00:11 +0000 Commit: Kristof Provost CommitDate: 2026-10-12 13:08:59 +0000 pf: do not free the caller's ruleset when attaching a table fails pfr_attach_table() takes a struct pf_ruleset * from its caller and, on its own error paths, calls pfr_destroy_ktable() on the table it just made. That drops the table's reference on the ruleset and calls pf_remove_if_empty_ruleset(), which may unlink and free the anchor the ruleset is embedded in -- and then pfr_attach_table() returns NULL to a caller still holding the pointer. Reached from userland with DIOCADDRULE and a PF_ADDR_DYNIFTL source, after DIOCSETLIMIT has lowered PF_LIMIT_TABLES to one item of headroom: the first pfr_create_ktable() takes it and the root table's fails. Hold a table reference on the ruleset for the duration instead, so the ruleset outlives every failure path inside pfr_attach_table() and stays the caller's to remove. OK sashan@ Obtained from: OpenBSD, gnezdo , e0a25791f4 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf_table.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c index 7fc3b0a6380b..94ea5181ee74 100644 --- a/sys/netpfil/pf/pf_table.c +++ b/sys/netpfil/pf/pf_table.c @@ -2285,15 +2285,26 @@ pfr_attach_table(struct pf_kruleset *rs, char *name) strlcpy(tbl.pfrt_anchor, ac->path, sizeof(tbl.pfrt_anchor)); kt = pfr_lookup_table(&tbl); if (kt == NULL) { + /* + * Hold rs across the table creation below. A new table takes + * a reference on the ruleset, and pfr_destroy_ktable() drops + * it again on the failure paths, which lets + * pf_remove_if_empty_ruleset() free the anchor rs points into + * while our caller still holds rs. + */ + rs->tables++; kt = pfr_create_ktable(&tbl, time_second, 1); - if (kt == NULL) + if (kt == NULL) { + rs->tables--; return (NULL); + } if (ac != NULL) { bzero(tbl.pfrt_anchor, sizeof(tbl.pfrt_anchor)); rt = pfr_lookup_table(&tbl); if (rt == NULL) { rt = pfr_create_ktable(&tbl, 0, 1); if (rt == NULL) { + rs->tables--; pfr_destroy_ktable(kt, 0); return (NULL); } @@ -2302,6 +2313,7 @@ pfr_attach_table(struct pf_kruleset *rs, char *name) kt->pfrkt_root = rt; } pfr_insert_ktable(kt); + rs->tables--; } if (!kt->pfrkt_refcnt[PFR_REFCNT_RULE]++) pfr_setflags_ktable(kt, kt->pfrkt_flags|PFR_TFLAG_REFERENCED);