Article View: muc.lists.freebsd.bugs
Article #346[Bug 300493] bpf_filter() page-faults on unmapped (M_EXTPG) mbufs when a filter loads past the mapped headers
From: bugzilla-noreply
Date: Wed, 04 Nov 2026 01:10
Date: Wed, 04 Nov 2026 01:10
169 lines
8572 bytes
8572 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300493
Bug ID: 300493
Summary: bpf_filter() page-faults on unmapped (M_EXTPG) mbufs
when a filter loads past the mapped headers
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: alok@dhir.net
Created attachment 276960
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276960&action=edit
bpf_filter.c: read M_EXTPG mbufs with m_copydata() in the filter's mbuf loads
bpf_mtap() runs a descriptor's filter on the mbuf chain (bpf_filter(...,
(u_char *)m, pktlen, 0)). In mbuf mode, bpf_filter.c reads bytes with mtod():
m_xword(), m_xhalf() and the BPF_LD|BPF_B|BPF_ABS / BPF_IND cases
(sys/net/bpf_filter.c on main: lines 103, 112, 152, 161, 256). None of these
handle M_EXTPG mbufs, whose data is an array of unmapped pages, so m_data is
not a valid pointer.
Drivers that advertise IFCAP_MEXTPG receive such chains on transmit; iflib sets
it (iflib.c ~4340, 5051), and iflib_txq_drain() calls ETHER_BPF_MTAP() on them
(iflib.c ~3896). sendfile(2) with kern.ipc.mb_use_ext_pgs=1 (the default on
amd64, arm64 and other direct-map platforms) produces them: headers in a normal
mbuf, file data in M_EXTPG mbufs.
So any BPF descriptor that sees outgoing packets on an iflib interface and
whose filter loads a byte from the payload (e.g. "tcp[((tcp[12] & 0xf0) >> 2)]
= 0x16", a TLS handshake check) dereferences a bogus pointer when the host
sends a file with sendfile, and the kernel panics.
The copy path is fine: catchpacket() -> bpf_buffer_append_mbuf() uses
m_copydata(), which handles M_EXTPG. Only the filter's loads are affected.
if_bridge masks IFCAP_MEXTPG on member interfaces (BRIDGE_IFCAPS_MASK), so the
same filter on a bridged LAN does not trigger it.
A root process with a valid filter program should not be able to panic the
kernel.
Why this is rare: it needs a filter that reads payload (most only read
headers), outgoing packets, a local sendfile(2) sender (forwarded packets are
mapped), and an MEXTPG NIC that isn't a bridge member. Any root user running a
common payload-matching one-liner such as `tcpdump 'tcp[((tcp[12:1] & 0xf0) >>
2):4] = 0x47455420'` on such a host should be exposed. I only tested the 0x16
filter above, but this one reads the payload the same way.
OBSERVED
OPNsense 26.7.8_2 (FreeBSD 15.1-RELEASE-p6, stable/26.7-n284176-c962f76493b6,
amd64), Intel N150, 2x i225 (igc). The trigger was os-loupe
(https://github.com/alokdhir/os-loupe), an OPNsense plugin I maintain that
shows per-device traffic. It takes byte counts from pf's state table and uses
BPF only to read the packets that carry names: DNS answers, TLS and QUIC
ClientHellos (for the server name), DHCP and mDNS. Version 1.0 opened one BPF
descriptor per LAN interface (here igc0/igc1) with the default direction
(INOUT) and a filter that, to pick out ClientHellos, loads the first bytes of
TCP payload. The machine panicked about 1-2 minutes after every boot, as soon
as lighttpd (the web GUI) served a file. Five crash dumps, all identical:
Fatal trap 12: page fault while in kernel mode
fault virtual address = 0x4f5 (also 0x0)
bpf_filter() <- bpf_mtap() <- iflib_txq_drain() <- ... <- sendfile()
current process = lighttpd
Setting the descriptors to BPF_D_IN (and using a header-only filter on a
separate BPF_D_OUT descriptor) stopped the panics: the same filter on incoming
packets is fine, which points at the outgoing sendfile mbufs rather than the
filter program.
REPRODUCED on stock FreeBSD 15.1-RELEASE-p6 GENERIC (amd64), in a QEMU/KVM
guest with an emulated Intel 82576 (QEMU "igb" device; FreeBSD igb0 via iflib,
options include MEXTPG), kern.ipc.mb_use_ext_pgs=1, not bridged:
tcpdump -n -i igb0 -Q out -w /dev/null 'tcp[((tcp[12] & 0xf0) >> 2)] = 0x16'
plus a minimal server that sends a 64 MB file with sendfile(2) to each
connection (sf-reproducer.c, attached), and one download from the host. The
guest panicked on the first download:
Fatal trap 12: page fault while in kernel mode
fault virtual address = 0x0
current process = 1511 (sf)
#4 calltrap
#5 bpf_mtap+0xe3 (faulting IP resolves to bpf_filter+0x4c9)
#6 iflib_txq_drain+0x286
#7 drain_ring_lockless+0x5e
#8 ifmp_ring_enqueue+0x274
#9 iflib_if_transmit+0x24b
#10 ether_output_frame+0xd3
#11 ether_output+0x6b0
#12 ip_output+0x13d1
#13 tcp_default_output+0x1f21
#14 tcp_usr_send+0x1fa
#15 vn_sendfile+0x14d7
#16 sendfile+0x128
FIX (attached: bpf_filter-extpg.diff, against releng/15.1; bpf_filter.c is the
same in main)
A helper m_xbyte() reads one byte with m_copydata() when the mbuf is M_EXTPG
(m_copydata() already handles unmapped pages via m_copyfromunmapped()), used by
the three BPF_B loads; m_xword() and m_xhalf() fall back to
m_copydata()/m_xbyte() when a load touches an M_EXTPG mbuf, after the existing
bounds checks. Mapped mbufs take the same path as before.
Tested in the same guest with a GENERIC kernel built from releng/15.1 plus the
patch (compiles cleanly with -Werror): no panic over 12 x 64 MB sendfile
downloads. The filter's results are right too: two tcpdumps on igb0 -Q out, one
with the payload filter above (plus "tcp src port 8080"), one counting all
data-bearing packets from port 8080, 16 MB capture buffers, 0 drops:
file of 0x16 bytes, mb_use_ext_pgs=1: 8404 matched / 8404 data packets
file of 0x16 bytes, mb_use_ext_pgs=0: 8194 matched / 8194 data packets
file of zero bytes, both settings: 0 matched
The JIT path in bpf_mtap() only runs on single-mbuf packets and still uses
mtod(); a sendfile chain starts with a mapped header mbuf, but a lone M_EXTPG
mbuf there would need the same care (not exercised here: the guest kernel has
no BPF_JITTER).
Analysis done with help from Claude Opus 5.5 (Anthropic); I checked it against
the 15.1 and main sources cited above, and reproduced and tested it as
described. os-loupe 1.0.1 works around it by setting the payload-reading
descriptors to BPF_D_IN.
--
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-300493-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.szaf.org!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.szaf.org!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 300493] bpf_filter() page-faults on unmapped (M_EXTPG) mbufs when a filter loads past the mapped headers Date: Wed, 04 Nov 2026 01:10:26 +0000 Organization: Newsgate at muc.de e.V. Sender: owner-freebsd-bugs@FreeBSD.org Approved: news-admin@muc.de Distribution: world Message-ID: <bug-300493-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="38207"; 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=1793754626; 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=ydL+FWfOEY/q1NP5xcCOv9Fy082OeTD90Ka6INDiNhI=; b=nDqAa7B5gcSIWew3KHyk+QayvDST2lf1Y7G77JJGrqIZ2ivf0F1oyuLUmLHIsIA2/F0vCy 21vCczplfH1cPjTFLwHAGkudAXjsacL+z9T1qv4gqYD8OpBpnfkZDpKwwOviPmF96OLMnJ GMFNTuhBqUlT/C6L6C5y5olIRC57Sas02YDZpDmWBU5pAXTCZ30KK6HvoziuqenmWlkk/f oAizbkJqt+P4EZRK79Dnv/5Dz6YzT/wbGdHBEGFRAYFnU+u3OUNMhUqFHyxYvEamN+xwl7 99u6p4p54UpM9MRRhcUbTf8b3An15y2bGHX36Ji+ozTzsLYMVxIYqZ/J4C0PVg== 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