Article View: muc.lists.freebsd.bugs
Article #793[Bug 301184] pf_free_rule() dereferences a NULL table or dynaddr pointer when pf_ioctl_addrule() fails before pf_addr_setup()
From: bugzilla-noreply
Date: Fri, 27 Nov 2026 13:04
Date: Fri, 27 Nov 2026 13:04
100 lines
6082 bytes
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
Technical Details
Message-ID:
<bug-301184-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301184] pf_free_rule() dereferences a NULL table or dynaddr pointer when pf_ioctl_addrule() fails before pf_addr_setup() Date: Fri, 27 Nov 2026 13:04:04 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301184-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="76791"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795784643; 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=TPwe5pfYdeW7rHeXa55lqmnSUEccDMYLnkja+Zl317w=; b=CYZ7Yli8izMEZlKunkE2v8ee5ucjV36+nhGvM55wr1a7Vkqf9PPnlWDdqpSVZKNfTEIL2h eREs+igZ4x+CnryCbG/l0jeKZCrLi5zdCVR8JjgvJB594TiRKFel7E1ots0Cg/kLFAutvf bwllDQDcxuaWnGaOHn4fXOjo+NLUe98TcHEGi5cfE5mGKk/7QGGdh5tdSVv1DtMhhxSCFO LQt2ikpgy3bR1MQjxXnJeM+gn381T99NsoAhnJQWcn+I9pVIo0AQcEJzIeFU8QRvtCak2u ZxoA/qbGkeOKibElUWnl0LsfNOaTwJBkvK5vec9go6MeIGQLVLJBALhfmBNSFQ== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes