🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
4 messages
4 total messages Started by bugzilla-noreply Fri, 27 Nov 2026 13:04
[Bug 301184] pf_free_rule() dereferences a NULL table or dynaddr pointer when pf_ioctl_addrule() fails before pf_addr_setup()
#793
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 13:04
100 lines
6082 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301184

            Bug ID: 301184
           Summary: pf_free_rule() dereferences a NULL table or dynaddr
                    pointer when pf_ioctl_addrule() fails before
                    pf_addr_setup()
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me

On main, since c556863aad24, pf_ioctl_addrule() frees a rule that
failed after the rules lock with pf_free_rule(). If that failure is
before pf_addr_setup() and the address is a table, pfr_detach_table()
is called with a NULL pointer and the kernel page-faults.

c556863aad24 ("pf: fully free rule on error", 2026-11-23) replaced
pf_krule_free() on that path. pf_krule_free() does not touch the table
pointer. A mismatched transaction ticket fails there, and so does
rtableid 100 when net.fibs is 1. struct pf_addr_wrap keeps the table
name and the table pointer in different unions, so a parsed table
address has type PF_ADDR_TABLE and p.tbl NULL until pf_addr_setup().
pf_check_rule_addr() rejects a non-NULL p.dyn, and p.dyn is the same
storage as p.tbl, so the pointer passed to pfr_detach_table() is NULL.

pfctl does not submit this. With net.fibs set to 1:

# printf 'pass in from <foo> rtable 100\n' > /tmp/r100.conf
# pfctl -nf /tmp/r100.conf
/tmp/r100.conf:1: invalid rtable id

DIOCADDRULE has no such check. pf_free_rule_null.c opens /dev/pf,
begins a filter transaction, and submits rtableid 100 twice: source
"any", then source table <foo>. It must run as root.

$ cc -Wall -Wextra -Werror -o pf_free_rule_null pf_free_rule_null.c

The kernel is FreeBSD 16.0-CURRENT #9 main-6edecf52def6-dirty
GENERIC-KASAN, built Thu Nov 26 10:23:49 UTC 2026. It does not contain
c556863aad24, and its error path still calls pf_krule_free(). Its
pf.ko (sha256 9f3f340bd54d) returned EBUSY for both rules at 12:05 UTC:

ticket 1
pool_ticket 1
control: pass in from any rtable 100
errno 16 (Device busy)
control: EBUSY
trigger: pass in from <foo> rtable 100
errno 16 (Device busy)
trigger: EBUSY
RESULT: both EBUSY, no panic

I rebuilt pf.ko with the two lines from c556863aad24 (sha256
f54436084761). At 12:12:22 UTC the "any" rule returned EBUSY and the
table rule did not return. vmcore.9 (12:13 UTC) is a page fault:

panic: page fault
#9  0xffffffff86b1ce82 in pfr_detach_table ()
   from /usr/obj/usr/src/amd64.amd64/sys/modules/pf/pf.ko
#10 0xffffffff86ae29d7 in pf_free_rule ()
   from /usr/obj/usr/src/amd64.amd64/sys/modules/pf/pf.ko
#11 0xffffffff86ae65ed in pf_ioctl_addrule ()
   from /usr/obj/usr/src/amd64.amd64/sys/modules/pf/pf.ko
#12 0xffffffff86afbb6d in pfioctl ()
   from /usr/obj/usr/src/amd64.amd64/sys/modules/pf/pf.ko
#13 0xffffffff81002335 in devfs_ioctl (ap=0x0)
    at /usr/src/sys/fs/devfs/devfs_vnops.c:987

The faulting instruction is movl 0x514(%rbx), %r14d at
pfr_detach_table+98, and rbx is 0. That load is the table reference
count. The return address in pf_free_rule is the call for the source
address's PF_ADDR_TABLE case.

dde37e7d2014 added the NULL test to pf_free_eth_rule() three days
later, and pf_empty_kpool() already skips a NULL table. The patch
does not detach a dynaddr or table pointer that is still NULL. I
rebuilt pf.ko with that patch on top of the c556863aad24 lines
(sha256 1d7a4085fbc6) and ran the program twice at 12:42:48 UTC. Both
calls returned EBUSY, it exited 0, and the kernel stayed up.

stable/15, stable/14, releng/15.1 and releng/14.4 still call
pf_krule_free() on this path. I have not built a kernel from main tip
748b510477b3, and I have not sent the rule from a vnet jail. In the
source, PFNL_CMD_ADDRULE calls the same pf_ioctl_addrule(), and
prison_priv_check() grants PRIV_NETINET_PF to a vnet jail.

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

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301184] pf_free_rule() dereferences a NULL table or dynaddr pointer when pf_ioctl_addrule() fails before pf_addr_setup()
#794
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 13:04
17 lines
2569 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301184

--- Comment #1 from laamalif@proton.me ---
Created attachment 277803
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277803&action=edit
skip a NULL dynaddr or table pointer in pf_free_rule(), the dde37e7d2014
pf_free_eth_rule() shape

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

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301184] pf_free_rule() dereferences a NULL table or dynaddr pointer when pf_ioctl_addrule() fails before pf_addr_setup()
#795
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 13:04
17 lines
2611 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301184

--- Comment #2 from laamalif@proton.me ---
Created attachment 277804
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277804&action=edit
reproducer: opens /dev/pf, begins a transaction, submits rtableid 100 twice
(source any, then source table); control EBUSY then the trigger

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

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301184] pf_free_rule() dereferences a NULL table or dynaddr pointer when pf_ioctl_addrule() fails before pf_addr_setup()
#806
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 16:01
16 lines
2559 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301184

Mark Linimon <linimon@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|bugs@FreeBSD.org            |pf@FreeBSD.org

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

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads