From nobody Wed Sep 17 14:15:49 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 4cRgm570v6z67Sq9; Wed, 17 Sep 2025 14:15:49 +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 4cRgm53J2nz44TX; Wed, 17 Sep 2025 14:15:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758118549; 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=ftiUiGcyP83PHIERnw6tNsYeB76Wd7gILboepUDAPpk=; b=BIjYt8yuRnozEDqRr7v+8yByZVuQdRp8SP6W2vlPcJmTVjwiw9L3HeYZKXehm4HGUnE/qF 0IiKJ5XJFgQnjr9pIieVuPBNjKCX1FjOvjh5JGa3jxdVuOXe8i9g8Fuj6lckDqIV3582B7 G367RAx/BucA3QYEonugzDtJEQ18UQgtZmKC+oromzAY5vvJTxH41KY5MDIeezOozpd2RZ 7vtEa/GIYS+Xo2x7aJIWmG0p+8JnsMXctXj+tEssSD539mZHlbuiGJYcwASEAmUDbGufx5 P0ISXEul4S8Xs2sLsK1gE6xEhEw9xM2tY0cQzhJ68HPYW4DBiAlH2NAmAaXViw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758118549; 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=ftiUiGcyP83PHIERnw6tNsYeB76Wd7gILboepUDAPpk=; b=e7O2heb2MvwN8K78h0lUK1lbRN2vn2vCnnw6Wmq11eI6ZfMY3TyYD8lYE+cG+uMeisFkle mbRDQXzQkMiVE1PL9ifYuSydr86hX/+cgYUZuc+AdFfSAkdvTWyURGwDOwy1mr+Ha8xVXX u1pDw/fYaYi3PZscLUCJcim6l/K6YdlY0/S40mYpkRKt4qyO0VUEs8g78rt5Fi9xSHIrLm eMhcRtWu1zoV9DkY1gppMGC+IRU7PaTJn6KlO9iF/uqPUFfpyhr0O4GwsAtQf0DDt3EQy2 V2O791I29ciB3oNVeTHtT5f7gfgki1fNRgltHsFI6CRXi9Cc2FkMd74U7qBhbg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758118549; a=rsa-sha256; cv=none; b=fYSLxf/HP0s7r8V/Sf4igPh8WMTRJJNfurl0AwVHSFn8ZcKnZRvOvbJOeV0uQ7Ttqah/IW AGRM7Gfjooru8lUJIMezJcUw76EPMdpaxnpIZiwvn1S5LpXXz9KL5VRSBYke0SlbiWC9o3 2odo9Kv7H7v81Ucj59tupekPd7wOdKkyOShpkOgz0i9xPmWhpCZhtKhNxqyuf9ijFrghux geyyApYFVpuv/HrYUJj6MK1iVpIZSzv0qVosFDeD93rIHtJUlSnbS+Y9UnYd2xR8duzP+M WNHjXHvKTDljPERP0bkHrU1KWTfk8Jte3tL6g85/HKODdOlNtMMDoOpucVfD4A== 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 4cRgm52tsZzTJ5; Wed, 17 Sep 2025 14:15:49 +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 58HEFnjS010464; Wed, 17 Sep 2025 14:15:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58HEFnUQ010461; Wed, 17 Sep 2025 14:15:49 GMT (envelope-from git) Date: Wed, 17 Sep 2025 14:15:49 GMT Message-Id: <202509171415.58HEFnUQ010461@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: e63534edbcd0 - main - pf: fix rules_counter:keepcounters test 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: e63534edbcd050215bc109cd89a31ba30c5ea850 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=e63534edbcd050215bc109cd89a31ba30c5ea850 commit e63534edbcd050215bc109cd89a31ba30c5ea850 Author: Kristof Provost AuthorDate: 2025-09-17 08:12:11 +0000 Commit: Kristof Provost CommitDate: 2025-09-17 14:15:16 +0000 pf: fix rules_counter:keepcounters test The previous pf_krule_global leak fix was a bit too aggressive and cleaned up the inactive tree pointer before we needed it to preserve counters. Only clean up anchors that are entirely unused. Clean up pf_main_ruleset on pf shutdown. PR: 289299 MFC after: 1 week Fixes: 275ff85b25 ("pf: fix struct pf_krule_global leak") Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf_ioctl.c | 5 +++++ sys/netpfil/pf/pf_ruleset.c | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 5bfbb2c83f0e..bd506c092da2 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -6551,6 +6551,11 @@ shutdown_pf(void) pf_kill_srcnodes(NULL); + for (int i = 0; i < PF_RULESET_MAX; i++) { + pf_rule_tree_free(pf_main_ruleset.rules[i].active.tree); + pf_rule_tree_free(pf_main_ruleset.rules[i].inactive.tree); + } + /* status does not use malloced mem so no need to cleanup */ /* fingerprints and interfaces have their own cleanup code */ } while(0); diff --git a/sys/netpfil/pf/pf_ruleset.c b/sys/netpfil/pf/pf_ruleset.c index 1711e690f6bb..4e16eaa76f9d 100644 --- a/sys/netpfil/pf/pf_ruleset.c +++ b/sys/netpfil/pf/pf_ruleset.c @@ -336,12 +336,6 @@ 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 || @@ -352,6 +346,12 @@ pf_remove_if_empty_kruleset(struct pf_kruleset *ruleset) !TAILQ_EMPTY(ruleset->rules[i].inactive.ptr) || ruleset->rules[i].inactive.open) return; + 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; + } RB_REMOVE(pf_kanchor_global, &V_pf_anchors, ruleset->anchor); if ((parent = ruleset->anchor->parent) != NULL) RB_REMOVE(pf_kanchor_node, &parent->children,