From nobody Tue Sep 02 21:10:58 2025 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 4cGdh31DQVz65Rqb; Tue, 02 Sep 2025 21:10:59 +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" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cGdh24NcGz42NL; Tue, 02 Sep 2025 21:10:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756847458; 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=04uml1jC/7BwJC3B/uEXGhA8ufeaE+QKtdP/F+E5XI0=; b=VqcFnjhPxwBkTpncg+8/9qT6x1Z08tnsW0VauvLDYdRZHoG9D5zDdP5VN0dHVH0HVm1hJZ q2xObTsKRArA4bSQBe985D817JYlXPkc5KLljP4yGEmPHX6alV6Ndq6RnLEMy+7Jiq1Qy/ KaR1V9SaRoaWnm0a0GSCkJNAMSvzFv2sGSo8p45UUCbXZbvqcxgm2MvK4QpG5CKB0QoTkR YdXNFppMYipzkC5lsOsTUCHiPB+sUKqc3TaZDVZTcuX86DJKR6qQw/+MQyqiKXOoTXa3yD KJ3zgUUJLAMhNnwpbuN9WoFRo+wvuFWyiv/JKQx1oTzeQZDwzviAB/2bVerXPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756847458; 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=04uml1jC/7BwJC3B/uEXGhA8ufeaE+QKtdP/F+E5XI0=; b=yxYTTQOeYYvSPs6LDmJ0Vc/ssWRouDaEJHMeN0rR6AkTE3T78vl+4RnG8N9kgECfoGMr0L Fy+vGwwgwp/PlWJDPInVk1uQyfI6tVHtdiipfAHRZrhLIao/jtgYILfwVC2IxIArD9Jbzg eRT6Z5EhbE6hNl0P8nNVVPUrI4TGyij/sAJGIiyhyoci7xtvnGOjN5n3kJXUvAnbHGBj/i VorKNgMYslvMj/wRve0K1efc/ok0BOo1/LZt3n5u5xCxWwg4ZWLmaUyQwnEMQPfyeYJ5vO SERE12zyIldCsbxHCf2gE2m52vx8aoT3VXvtsCEnz7scyBtmsRDDlEC67QvixQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756847458; a=rsa-sha256; cv=none; b=xqrfEYKyczw5CqLvwlqMOQCxPneQponXtlGwPHxhJ/7D2HF/PFEImGR4kGWs9iKem+Y8r/ //o0TCK8hlq3gARpW7LnxD3tdXH5PiFqZRHfwAWtt8SpEopnC1iWl4XBYEKvL+G/oa4I/a ht1vv5KqiKH+TuTVzg5kDnZYAOyERTuti/gcvNtG+COb7lvWSGzGjYtM4WchFzg6jcg4SH 6Rt+HrVvUaOAoVZRTX7jegz5TNELgoFy/RtZHe/hzfxCm0/K1IZB63JdGeTG3pMsvUzOBq avGCNhWt+G21RCktycITZ0nUh9d9mI7aYPFznKK4o9SGVWPevBMHOMW1il/UAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cGdh23zS1z1325; Tue, 02 Sep 2025 21:10:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 582LAwKl036629; Tue, 2 Sep 2025 21:10:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 582LAw2m036626; Tue, 2 Sep 2025 21:10:58 GMT (envelope-from git) Date: Tue, 2 Sep 2025 21:10:58 GMT Message-Id: <202509022110.582LAw2m036626@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 275ff85b254c - main - pf: fix struct pf_krule_global leak List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org 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: 275ff85b254c1f160f965dd9dbb5801f66022eab Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=275ff85b254c1f160f965dd9dbb5801f66022eab commit 275ff85b254c1f160f965dd9dbb5801f66022eab Author: Kristof Provost AuthorDate: 2025-09-01 08:32:30 +0000 Commit: Kristof Provost CommitDate: 2025-09-02 21:10:21 +0000 pf: fix struct pf_krule_global leak Make sure we free all of the trees we allocated when we free the ruleset. Found by 'kldunload pf' after a test run, now that the allocation is done from a pf-specific malloc type. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/pfvar.h | 1 + sys/netpfil/pf/pf_ioctl.c | 2 +- sys/netpfil/pf/pf_ruleset.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 79855fa84359..f73420494000 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -2614,6 +2614,7 @@ struct pf_kruleset *pf_find_kruleset(const char *); struct pf_kruleset *pf_get_leaf_kruleset(char *, char **); struct pf_kruleset *pf_find_or_create_kruleset(const char *); void pf_rs_initialize(void); +void pf_rule_tree_free(struct pf_krule_global *); struct pf_krule *pf_krule_alloc(void); diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 934eff020074..06c40a03f575 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -1189,7 +1189,7 @@ pf_rule_tree_alloc(int flags) return (tree); } -static void +void pf_rule_tree_free(struct pf_krule_global *tree) { diff --git a/sys/netpfil/pf/pf_ruleset.c b/sys/netpfil/pf/pf_ruleset.c index 259f586fa127..1711e690f6bb 100644 --- a/sys/netpfil/pf/pf_ruleset.c +++ b/sys/netpfil/pf/pf_ruleset.c @@ -336,6 +336,12 @@ pf_remove_if_empty_kruleset(struct pf_kruleset *ruleset) int i; while (ruleset != NULL) { + for (int i = 0; i < PF_RULESET_MAX; i++) { + pf_rule_tree_free(ruleset->rules[i].active.tree); + ruleset->rules[i].active.tree = NULL; + pf_rule_tree_free(ruleset->rules[i].inactive.tree); + ruleset->rules[i].inactive.tree = NULL; + } if (ruleset == &pf_main_ruleset || !RB_EMPTY(&ruleset->anchor->children) || ruleset->anchor->refcnt > 0 || ruleset->tables > 0 ||