[Bug 297678] pf: page fault in pf_step_into_anchor()

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 25 Aug 2026 15:29:12 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=297678

Kristof Provost <kp@freebsd.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kp@freebsd.org

--- Comment #1 from Kristof Provost <kp@freebsd.org> ---
I've not yet been able to reproduce this, but I suspect the issue is related to
ctx->last_match_rule.
We use that to find the last entry in the ctx->match_rules (an SLIST), and I
think that we can end up in a situation (i.e. when we enter an anchor and have
already matched a rule) where the last_match_rule is NULL, but match_rules is
not empty, which would explain the panic.

I think I should be able to build a test case to reproduce this, but it would
also help if you could confirm this prevents the crash:

diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 7dc9d59e8300..9356e5271b4e 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -6272,9 +6272,10 @@ pf_match_rule(struct pf_test_ctx *ctx, struct
pf_kruleset *ruleset)
                                }
                                ri->r = r;

-                               if (SLIST_EMPTY(ctx->match_rules)) {
+                               if (SLIST_EMPTY(ctx->match_rules) ||
ctx->last_match_rule == NULL) {
                                        SLIST_INSERT_HEAD(ctx->match_rules, ri,
entry);
                                } else {

(That's not quite a correct fix, but if my theory is right that should at least
no longer panic, and the downside is mostly out-of-order match rules logging.)

-- 
You are receiving this mail because:
You are the assignee for the bug.