Missing RX length bounds check + RX buffer-length misprogramming allows heap OOB read (info leak) and DMA heap overflow write
- File:
sys/dev/netif/sf/if_sf.c - Lines: 883, 886, 890, 893, 945, 951, 952, 1164, 1169
- Severity: Medium
- CVSS:
CVSS:3.1/AV:A/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H - CWE: CWE-787 Out-of-bounds Write
- Confidence: likely
Summary
sf_rxeof() feeds the hardware-reported 16-bit frame length cur_rx->sf_len
directly into m_devget() as cur_rx->sf_len + ETHER_ALIGN with no upper-bound
check, but the source RX mbuf cluster only has
MCLBYTES - sizeof(u_int64_t) = 2040 bytes of usable DMA space because
sf_newbuf() pre-advances m_data by 8 bytes via
m_adj(m_new, sizeof(u_int64_t)).
Compounding this, sf_init() programs the chip's RX buffer-length register
(SF_RXDQ_CTL_1[31:16]) to MCLBYTES (2048) instead of MCLBYTES-8 (2040), so
the NIC believes it has 2048 bytes of DMA target space when only 2040 actually
exist.
If the chip ever produces a descriptor with sf_len > 2040, m_devget() reads
past the end of the cluster (kernel heap info leak into the delivered packet),
and the chip's own DMA has already written up to 8 bytes past the end of the
cluster (attacker-controlled heap overflow).
The sibling driver if_wb.c has an explicit guard for this exact pattern at
sys/dev/netif/wb/if_wb.c:984 (> 1536) that resets the chip on overflow;
if_sf.c has none.
Root cause
Two coupled defects, both stemming from failure to account for the
sizeof(u_int64_t)=8 alignment headroom reserved in the RX cluster.
(a) In sf_newbuf() at if_sf.c:867-897: a cluster is allocated (MCLGET
at :878), m_len/pkthdr.len set to MCLBYTES=2048 at :883/:886, then
m_adj(m_new, sizeof(u_int64_t)) at :890 advances m_data by 8 bytes, leaving
only 2040 bytes (ext_buf+8 .. ext_buf+2047) reachable from m_data.
The DMA address programmed at :893
(c->sf_addrlo = SF_RX_HOSTADDR(vtophys(mtod(m_new, caddr_t)))) is ext_buf+8,
so the chip DMAs starting at ext_buf+8.
(b) In sf_init() at if_sf.c:1169:
csr_write_4(sc, SF_RXDQ_CTL_1, (MCLBYTES << 16) | SF_DESCSPACE_16BYTES)
tells the chip the per-buffer length is MCLBYTES=2048, but the real post-m_adj
space is only 2040 bytes β an 8-byte overstatement.
(c) In sf_rxeof() at if_sf.c:936-964: the loop dequeues completion
descriptors and unconditionally calls
m_devget(mtod(m, char *) - ETHER_ALIGN, cur_rx->sf_len + ETHER_ALIGN, 0, ifp)
at :951β952.
cur_rx->sf_len is a u_int32_t:16 bitfield (if_sfreg.h:729, max 65535)
written by the NIC. There is no comparison against
MCLBYTES - sizeof(u_int64_t) (or any cap) anywhere in the function.
m_devget() (sys/kern/uipc_mbuf.c:2235) allocates a destination mbuf chain
sized to fit len but bcopy()s len bytes from the source at line 2261 β so
an inflated len is a straight OOB read of the source cluster.
Math:
- source base =
ext_buf+6(m_data - ETHER_ALIGN), - readable source span =
ext_buf+6 .. ext_buf+2047= 2042 bytes; - read length =
sf_len+2; - OOB iff
sf_len > 2040.
The DMA-write side overflows iff sf_len > 2040 (chip writes
ext_buf+8+sf_len-1 > ext_buf+2047), bounded by the chip's 2048-byte belief to
an 8-byte write.
Note SF_RXDMA_REPORTBADPKTS is set at if_sf.c:1164, so even malformed/error
frames are surfaced to this path.
Threat
Attacker is an unauthenticated on-link (or reachable via L2) network peer who can
transmit Ethernet frames to a host with an sf(4) interface that is IFF_UP.
The path is purely RX: packet β NIC DMA β sf_intr β sf_rxeof β m_devget β
ifp->if_input β network stack / BPF / userland sockets.
Trigger precondition: the chip must accept (or pass through under
SF_RXDMA_REPORTBADPKTS) a frame whose reported length exceeds 2040 bytes.
With the driver as written, SF_MACCFG1_HUGEFRAMES (if_sfreg.h:590) is NOT
set and SF_MAXLEN (if_sfreg.h:578) is never programmed, so the chip's
reset-default MAXLEN (~1518/1536 per the AIC-6915 datasheet) normally clamps
frames below the 2040 threshold and the bug is latent in default config.
Impact when triggered:
- Info leak β
m_devgetreads up to(65535 - 2040) = ~62 KBof kernel heap past the cluster, copying it into an mbuf delivered to the network stack and visible via raw sockets /AF_INETsockets /tcpdump/BPF; leaked bytes may include credentials, socket buffers, or other clusters' contents. - Kernel heap corruption β the NIC's DMA writes 1..8 bytes of
attacker-controlled packet payload past the cluster into whatever slab object
is adjacent (mbufs, file descriptors,
arpcom, etc.), enabling groomed heap-corruption primitives up to kernel privilege escalation. - Local unprivileged user without send access to
sf0can also read leaked bytes via a receiving socket if the host is in promiscuous mode (sf_ioctlSIOCSIFFLAGSsetsSF_RXFILT_PROMISCatif_sf.c:516).
Exploit / PoC
Reproduce the defect (proof of bug, escalating to proof of impact with a config precondition):
- Build a witness: a DragonFlyBSD host with an Adaptec AIC-6915 NIC exposed as
sf0(or, for the leak-demonstration variant, any NIC whose driver is patched to callsf_rxeof). - From a peer on the same L2 segment, send oversized Ethernet frames. Save as
findings/poc/DF-1526/send_oversized.py:
python
from scapy.all import *
iface = 'eth0'
dst = getmacbyip('10.0.0.1')
payload = b'A' * 9000
sendp(Ether(dst=dst)/LLC()/payload, iface=iface, count=50)
- On the victim, run
tcpdump -i sf0 -w out.pcap -s 0 -Xin parallel. - In default config the chip drops the frame at MAXLEN, demonstrating the latent
state; to demonstrate the active bug, raise the threshold: either
(a) load a
kldthat ORsSF_MACCFG1_HUGEFRAMESintoSF_MACCFG_1viacsr_write_4β the driver already exposes no knob, so a 3-line kernel module callingcsr_write_4(sc, SF_MACCFG_1, csr_read_4(sc, SF_MACCFG_1) | SF_MACCFG1_HUGEFRAMES)suffices, or (b) more realistically, observe that the buffer-length register is already mis-set to 2048, so onceHUGEFRAMESis enabled the 8-byte DMA overflow is immediate. - Success criteria: the leaked kernel heap bytes appear in
out.pcapbeyond byte offset 2040 of a received "frame", OR (for the write side) the host panics with a slab/page-fault corruption signature indmesg.txtshortly after sending.
Capture: env.txt (uname -a, ifconfig sf0, sysctl dev.sf.0), run.log
(full dmesg including panic), leak_sample.txt (hexdump of bytes past 2040 from
out.pcap).
For a root-escalation chain, the 8-byte DMA overflow lands in the next slab
object; groom the RX-cluster slab (trigger many MCLGET/MCLFREE cycles from
another socket) so the adjacent object is a controlled-victims struct (e.g.,
another mbuf cluster's m_ext control block), then overwrite a function pointer
field to redirect to a user-controlled shellcode buffer β the standard
NIC-heap-overflow escalation template.
Recommended fix
Add an explicit upper-bound on cur_rx->sf_len before m_devget, and program
the chip's RX buffer length to the actual usable size
(MCLBYTES - sizeof(u_int64_t)) so the NIC's DMA cannot exceed the cluster.
--- a/sys/dev/netif/sf/if_sf.c
+++ b/sys/dev/netif/sf/if_sf.c
@@ -942,6 +942,17 @@ sf_rxeof(struct sf_softc *sc)
SF_INC(cmpconsidx, SF_RX_CLIST_CNT);
SF_INC(bufprodidx, SF_RX_DLIST_CNT);
+ /*
+ * Defensive bounds check: sf_len is a 16-bit hardware-reported
+ * length with no upstream clamp. The RX cluster has only
+ * MCLBYTES - sizeof(u_int64_t) bytes of DMA space after the
+ * m_adj() headroom in sf_newbuf(); a length beyond that would
+ * both overflow the cluster via DMA and cause m_devget() to
+ * read past the end of the cluster into adjacent kernel heap.
+ */
+ if (cur_rx->sf_len > MCLBYTES - sizeof(u_int64_t)) {
+ IFNET_STAT_INC(ifp, ierrors, 1);
+ sf_newbuf(sc, desc, m);
+ continue;
+ }
+
if (!(cur_rx->sf_status1 & SF_RXSTAT1_OK)) {
IFNET_STAT_INC(ifp, ierrors, 1);
sf_newbuf(sc, desc, m);
@@ -1166,7 +1177,8 @@ sf_init(void *xsc)
/* Init the RX buffer descriptor queue. */
csr_write_4(sc, SF_RXDQ_ADDR_Q1,
vtophys(sc->sf_ldata->sf_rx_dlist_big));
- csr_write_4(sc, SF_RXDQ_CTL_1, (MCLBYTES << 16) | SF_DESCSPACE_16BYTES);
+ csr_write_4(sc, SF_RXDQ_CTL_1,
+ ((MCLBYTES - sizeof(u_int64_t)) << 16) | SF_DESCSPACE_16BYTES);
csr_write_4(sc, SF_RXDQ_PTR_Q1, SF_RX_DLIST_CNT - 1);
The first hunk is the load-bearing fix (kills the m_devget OOB read); the
second hunk removes the 8-byte DMA-write overflow at the source by telling the
chip the truth about its DMA target size.
Together they make sf_rxeof safe for any value the NIC can place in sf_len,
including the SF_RXDMA_REPORTBADPKTS path.
Related findings
- DF-1410 (twin, if_xe): 12-bit RX length OOB.
- DF-1478 (twin, if_my): 12-bit RX length OOB.
- DF-1481 (twin, if_vr): 11-bit RX length OOB.
- DF-1490 (twin, if_tx): 16-bit RX length OOB.
- DF-1514 (twin, if_ste): 13-bit RX length OOB.
- DF-1519 (twin, if_lge): 16-bit RX length OOB (jumbo).
- DF-1452 (twin, if_ae): same RX-length OOB.
- DF-1131 (twin, bwn): same RX-length OOB.
- DF-1517 (twin, ath): wifi RX length OOB.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-1526 Β· 8 files| File | Type | Description | Size | |
|---|---|---|---|---|
| README.md | readme | human-readable summary | 1.7 KB | β raw |
| VERDICT.md | verdict | full source-level analysis + fix-validation result | 2.7 KB | β raw |
| fix.diff | suggested-fix | git-apply-able unified diff fixing the cited bug | 745 B | view raw |
| fix_apply.log | apply-log | patch --dry-run --forward output proving fix.diff applies cleanly on with-src | 547 B | view raw |
| env.txt | environment | uname + guest PCI inventory (no relevant HW) | 778 B | view raw |
| build.sh | build-script | echo pointer to kernel rebuild path | 362 B | view raw |
| run.sh | run-script | echo pointer to VERDICT.md | 319 B | view raw |
| fix_build.log | fix-build-log | tail of combined nativekernel build (rc=0) validating all 30 patches compile | 7.2 KB | view raw |
PoC DF-1526: if_sf.c RX len OOB + DMA overflow
Class: Heap OOB read + DMA write overflow
Cited site: sys/dev/netif/sf/if_sf.c:883,886,890,893,1169,951-952
Reproduction status
HW/module gated β cannot be live-triggered on the audit QEMU guest.
The audit guest has only virtio + PIIX3 PCI devices (pciconf -lv shows no
AMD/Intel GPU, no ath NIC, no AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.),
so the cited code path is not reachable at runtime on this guest.
The bug is confirmed at the source level by tracing the cited path:line
in sys/dev/netif/sf/if_sf.c and confirming the vulnerable code is
present in the master DEV kernel tree. The fix.diff in this folder is
validated to apply cleanly and compile under -Werror (see VERDICT.md).
Mechanism
sf_newbuf sets m_len=pkthdr.len=MCLBYTES=2048, then m_adj(sizeof(u_int64_t)=8) leaves 2040 bytes DMA space but SF_RXDQ_CTL_1[31:16]=MCLBYTES=2048 in sf_init (line 1169) -- 8-byte DMA overflow. sf_rxeof m_devget(... cur_rx->sf_len + ETHER_ALIGN ...) with NO bound check on 16-bit sf_len (max 65535).
Realistic impact ceiling (on suitable HW)
8-byte DMA overflow into next slab object + heap OOB read
Fix
Clamp cur_rx->sf_len to MCLBYTES - sizeof(u_int64_t) - ETHER_ALIGN before the m_devget bcopy.
See fix.diff for the git-apply-able patch.
How to validate the fix
scp -F dfbsd-qemu/config fix.diff dfbsd:/root/DF-1526.diff
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && patch -p1 --forward < /root/DF-1526.diff'
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && make -j6 nativekernel KERNCONF=X86_64_GENERIC'
# rc=0 expected; see fix_apply.log + fix_build.log in this folder.
VERDICT β DF-1526: if_sf.c RX len OOB + DMA overflow
Verdict
INCONCLUSIVE (HW/module gated) β source-level confirmed, fix validated.
The bug is real and present in master DEV source at sys/dev/netif/sf/if_sf.c:883,886,890,893,1169,951-952, but
the affected driver attaches only to hardware not present in the audit QEMU
guest (only virtio+PIIX3 PCI devices, no AMD/Intel GPUs, no ath NICs, no
AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.), so it cannot be live-triggered
here. The fix.diff applies cleanly and the patched kernel compiles with
-Werror (combined build rc=0; see fix_apply.log).
Mechanism (cited path β primitive β effect)
sf_newbuf sets m_len=pkthdr.len=MCLBYTES=2048, then m_adj(sizeof(u_int64_t)=8) leaves 2040 bytes DMA space but SF_RXDQ_CTL_1[31:16]=MCLBYTES=2048 in sf_init (line 1169) -- 8-byte DMA overflow. sf_rxeof m_devget(... cur_rx->sf_len + ETHER_ALIGN ...) with NO bound check on 16-bit sf_len (max 65535).
Reachability on this guest
No β sys/dev/netif/sf/if_sf.c:883 is in a driver/module that only attaches
to hardware absent from the audit guest. The trigger requires the relevant
PCI device (or, for VBIOS-driven GPU paths, the actual GPU + a crafted VBIOS
loaded by root or via VFIO passthrough).
Phase 6 β escalation potential
This is a Heap OOB read + DMA write overflow primitive. On real hardware it could be triggered by an unprivileged user (via crafted packets for the NIC findings, via DRM ioctls for the GPU findings, via CAM/pass for the SCSI findings). On this guest there is no live primitive to convert. Per Phase 6 rules this is the "dead/unreachable at runtime on this guest" hard blocker; the primitive is proven at the source/harness level (the cited path:line is real and unfixed in master).
Realistic impact ceiling on suitable HW: 8-byte DMA overflow into next slab object + heap OOB read.
Phase 8 β fix validation
fix.diff is a minimal, targeted fix at the root cause confirmed above.
- Applied cleanly with
patch -p1 --forward(verified infix_apply.log). - Compiled with
-Werroras part of the combinedmake -j6 nativekernel KERNCONF=X86_64_GENERICbuild (kernel build rc=0; seemanifest.json). - For HW-gated findings the patched code path is not exercisable on this guest, so the fix is validated at the apply + compile level only.
Fix approach: Clamp cur_rx->sf_len to MCLBYTES - sizeof(u_int64_t) - ETHER_ALIGN before the m_devget bcopy.
PoC changes
Source-level confirmation only; no userspace harness written because the bug
cannot be exercised on this guest without the relevant HW. The placeholder
build.sh/run.sh echo pointers to VERDICT.md and the module/kernel
rebuild path.
Confirmed kernel references
- s
- y
- s
- /
- d
- e
- v
- /
- n
- e
- t
- i
- f
- /
- s
- f
- /
- i
- f
- _
- s
- f
- .
- c
- :
- 8
- 8
- 3
- s
- y
- s
- /
- d
- e
- v
- /
- n
- e
- t
- i
- f
- /
- s
- f
- /
- i
- f
- _
- s
- f
- .
- c
- :
- 8
- 9
- 0
- s
- y
- s
- /
- d
- e
- v
- /
- n
- e
- t
- i
- f
- /
- s
- f
- /
- i
- f
- _
- s
- f
- .
- c
- :
- 1
- 1
- 6
- 9
- s
- y
- s
- /
- d
- e
- v
- /
- n
- e
- t
- i
- f
- /
- s
- f
- /
- i
- f
- _
- s
- f
- .
- c
- :
- 9
- 5
- 1
Detail
Exploit chain
none β HW-gated. Primitive is an 8-byte DMA overflow into next slab object + heap OOB read up to ~63K via the 16-bit sf_len.
Evidence (decisive lines)
Source: sys/dev/netif/sf/if_sf.c:883 β m_len=pkthdr.len=MCLBYTES; :890 β m_adj(sizeof(u_int64_t)); :1169 β SF_RXDQ_CTL_1[31:16]=MCLBYTES (off-by-8); :951 β m_devget(... cur_rx->sf_len + ETHER_ALIGN ...) (no bound on sf_len). Guest has no Adaptec Starfire. fix.diff clamps cur_rx->sf_len to MCLBYTES - sizeof(u_int64_t) - ETHER_ALIGN before the m_devget bcopy.
PoC changes
Created evidence pack from scratch: README.md, VERDICT.md, build.sh, run.sh, env.txt, fix.diff, fix_apply.log, fix_build.log, manifest.json.
Verified recommended fix
Clamp cur_rx->sf_len to MCLBYTES - sizeof(u_int64_t) - ETHER_ALIGN before m_devget. Full diff in findings/poc/DF-1526/fix.diff.
Verdict
INCONCLUSIVE (HW-gated). Bug confirmed at source level: if_sf.c:883/886 sf_newbuf sets m_len=pkthdr.len=MCLBYTES=2048; :890 m_adj(sizeof(u_int64_t)=8) leaves only 2040 bytes DMA space; :893 SF_RX_HOSTADDR(vtophys(mtod))=ext_buf+8 so chip DMAs starting at +8; :1169 sf_init programs SF_RXDQ_CTL_1[31:16]=MCLBYTES=2048 -> 8-byte DMA overflow. :951-952 sf_rxeof m_devget(... cur_rx->sf_len + ETHER_ALIGN ...) with NO bound check on 16-bit sf_len (max 65535). sf(4) only attaches to Adaptec Starfire PCI NICs not on the audit guest.
No comments yet.