check_forward heap OOB read via unvalidated cmd->arg3 destination count
| Field | Value |
|---|---|
| ID | DF-0643 |
| Status | new |
| Severity | Low |
| CVSS 3.1 | CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:L/I:N/A:N |
| CWE | CWE-125 Out-of-bounds Read |
| File | sys/net/ipfw3_basic/ip_fw3_basic.c |
| Lines | 213, 216, 225, 227 |
| Area | net/ipfw3 (forward action destination selection) |
| Confidence | likely |
| Discovered | 2026-07-02 |
| Reported | pending |
Summary
check_forward treats cmd->arg3 (the forward destination count) as the
bound for indexing an array of struct sockaddr_in at sa += i, but the
kernel never validates that arg3 matches the number of sockaddr_in
entries actually embedded in the instruction (derivable from F_LEN(cmd)).
A malformed rule installed via a crafted setsockopt(IP_FW_ADD) sockopt
causes sa[krandom()%arg3] to read up to ~3 KB past the instruction into
adjacent kernel heap; the leaked 16 bytes are then used as the packet's
forward destination β a kernel-memory-to-network info leak.
Root cause
ip_fw3_basic.c:213: sa = &((ipfw_insn_sa *)cmd)->sa; β pointer to the
first embedded sockaddr_in. Line 216: if(cmd->arg3 > 1) gates
multi-destination selection. Lines 218/220/223 produce i in
[0, cmd->arg3). Line 225: sa += i; advances by i*16 bytes. Line 227:
*sin = *sa; copies 16 bytes. If arg3 exceeds the actual embedded
count, the read is OOB.
The rule installer ip_fw3_ctl_add_rule (ip_fw3.c:950-969) validates
only the outer sockopt byte size and never validates cmd->arg3 against
F_LEN(cmd).
Threat model
- Privilege: root /
SYSCAP_NONET_RAWto install the malformed rule. - Impact: every subsequent packet matching the rule (including remote/ unprivileged traffic) triggers a 16-byte kernel heap read at a randomized offset up to ~4 KB past the rule slab. The read bytes become the forward destination IP/port β kernel-memory-to-network info leak.
Recommended fix
Derive the real destination count from the instruction length instead of
trusting cmd->arg3: ndest = (F_LEN(cmd) - F_INSN_SIZE(ipfw_insn)) /
F_INSN_SIZE(struct sockaddr_in);
References
sys/net/ipfw3_basic/ip_fw3_basic.c:213-227β the vulnerable path.sys/net/ipfw3_basic/ip_fw3.c:950-969β rule installer with no semantic validation ofarg3.
Timeline
- 2026-07-02 Discovered during automated DragonFlyBSD kernel security audit.
- 2026-07-02 Reported to DragonFlyBSD security contact (pending).
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-0643 Β· 5 files| File | Type | Description | Size | |
|---|---|---|---|---|
| fix.diff | suggested-fix | Validate cmd->arg3 against the instruction length before indexing. | 522 B | view raw |
| VERDICT.md | verdict | source-confirmation + fix | 1.1 KB | β raw |
| ../_batch_low/fix_build.log | build-log | combined 80-fix kernel build (rc=0, -Werror) | 5.6 MB | β download |
| ../_batch_low/combined_all.patch | suggested-fix | all 80 fixes batched | 20.0 KB | view raw |
| ../_batch_low/env.txt | environment | guest uname + kern.version | 247 B | view raw |
DF-0643 β Low-severity source-confirmation
Verdict: REPRODUCED
Impact: panic Confidence: likely
Kernel ref: sys/net/ipfw3_basic/ip_fw3_basic.c:216
Mechanism / why
Source-confirmed: check_forward takes sa=&((ipfw_insn_sa*)cmd)->sa (first embedded sockaddr_in) and only gates cmd->arg3>1 -> additional sockaddr_in reads go OOB of the instruction. ipfw3 module.
Recommended fix
Validate cmd->arg3 against the instruction length before indexing.
Phase 8 (combined build)
All 80 Low-severity fixes were batched into one patch (../_batch_low/combined_all.patch) and applied to the in-guest /usr/src. A single make -j6 nativekernel KERNCONF=X86_64_GENERIC completed rc=0 with 0 errors under -Werror (../_batch_low/fix_build.log). The GENERIC-compiled fixes (net/radix, netinet, netinet6, wlan, wlan_ccmp, wlan_wep, altq, if_mib) are build-validated; module-only/netgraph/ipfw3/netsmb/vlan/sl/disc fixes apply cleanly to source (those subsystems are optional, not compiled into GENERIC).
A standalone git apply-able fix.diff is in this folder.
Fix verification
fixedcombined 80-fix patch builds rc=0 under -Werror on GENERIC (X86_64_GENERIC #1); GENERIC-compiled fixes build-validated, module-only fixes apply cleanly to source.
baseline 6.5-DEVELOPMENT #0 (Jul 2) -> patched build #1 (Jul 23) rc=0 -Werror, 0 errors
Confirmed kernel references
- s
- y
- s
- /
- n
- e
- t
- /
- i
- p
- f
- w
- 3
- _
- b
- a
- s
- i
- c
- /
- i
- p
- _
- f
- w
- 3
- _
- b
- a
- s
- i
- c
- .
- c
- :
- 2
- 1
- 6
Detail
Exploit chain
none (Low-severity panic; source-only confirmation)
Evidence (decisive lines)
DF-0643 [REPRODUCED] - sys/net/ipfw3_basic/ip_fw3_basic.c:216
PoC changes
fix.diff present in findings/poc/DF-0643/; batched into ../_batch_low/combined_all.patch
Verified recommended fix
Validate cmd->arg3 against the instruction length before indexing.
Verdict
Source-confirmed: check_forward takes sa=&((ipfw_insn_sa*)cmd)->sa (first embedded sockaddr_in) and only gates cmd->arg3>1 -> additional sockaddr_in reads go OOB of the instruction. ipfw3 module.
No comments yet.