Thread View: muc.lists.freebsd.bugs
2 messages
2 total messages
Started by bugzilla-noreply
Wed, 04 Nov 2026 01:10
[Bug 300493] bpf_filter() page-faults on unmapped (M_EXTPG) mbufs when a filter loads past the mapped headers
Author: 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
[Bug 300493] bpf_filter() page-faults on unmapped (M_EXTPG) mbufs when a filter loads past the mapped headers
Author: bugzilla-noreply
Date: Wed, 04 Nov 2026 01:11
Date: Wed, 04 Nov 2026 01:11
17 lines
2700 bytes
2700 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300493
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |crash
Assignee|bugs@FreeBSD.org |net@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