git: c514361dbe90 - main - pf: fix memory leak on failure in DIOCADDETHRULE

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 26 Nov 2026 17:16:54 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=c514361dbe90e8199ac3cf8be61ec0b0093a1dc3

commit c514361dbe90e8199ac3cf8be61ec0b0093a1dc3
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2026-11-25 17:13:03 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-11-26 17:16:40 +0000

    pf: fix memory leak on failure in DIOCADDETHRULE
    
    If we fail pf_nveth_rule_to_keth_rule() we jumped to
    DIOCADDETHRULE_error, which doesn't free the rule.
    Free the rule directly, because pf_free_eth_rule() expects the rules
    lock to be held, and at this point we've only allocated the rule itself,
    not any of the child objects.
    
    Reported by:    llm-postcr
    Fixes:          e732e742b37f ("pf: Initial Ethernet level filtering code")
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/netpfil/pf/pf_ioctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index d1872ea12d69..9b692b3954a7 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -4410,8 +4410,10 @@ DIOCGETETHRULE_error:
 		rule->timestamp = NULL;
 
 		error = pf_nveth_rule_to_keth_rule(nvl, rule);
-		if (error != 0)
+		if (error != 0) {
+			free(rule, M_PFRULE);
 			ERROUT(error);
+		}
 
 		if (rule->ifname[0])
 			kif = pf_kkif_create(M_WAITOK);