ip_len double-counted in ip_divert_in() after ip_reass() (corrupted packet metadata on fragmented divert)
| Field | Value |
|---|---|
| ID | DF-0646 |
| Status | new |
| Severity | Low |
| CVSS 3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N |
| CWE | CWE-682 Incorrect Calculation |
| File | sys/netinet/ip_divert.c |
| Lines | 607 |
| Area | netinet (divert fragmented reassembly metadata) |
| Confidence | certain |
| Discovered | 2026-07-02 |
| Reported | pending |
Summary
ip_divert_in() adds hlen to ip_len at line 607 after ip_reass()
returns, but ip_reass() already includes the header length in
ip_len (ip_input.c:1307, with explicit comment "Note that ip_len
includes the header length"). This is a stale adjustment from when
ip_reass did not include the header. The result is a corrupted ip_len
(too large by hlen, or wrapped via 16-bit truncation for near-max-size
reassembled datagrams) delivered to the divert daemon.
Root cause
ip_divert.c:589 calls m = ip_reass(m). ip_reass() at
ip_input.c:1307 sets ip->ip_len = htons(next + hlen) (with the comment
"Note that ip_len includes the header length").
ip_input's own normal reassembly path (ip_input.c:858-864) trusts this
and does NOT add hlen again.
But ip_divert_in:601-607 does:
607: ip->ip_len = htons(ntohs(ip->ip_len) + hlen); /* BUG: hlen added again */
For a max-size reassembled datagram (next=65535-hlen), the resulting
ntohs(ip->ip_len)+hlen = 65535+hlen wraps via the u_short ip_len field.
Threat model
- Attacker: remote β sends fragmented IP packets to a host with an ipfw divert rule.
- Impact: the divert daemon sees inconsistent
ip_lenvs actual mbuf length. No kernel crash; metadata corruption only. For near-max-size reassembled datagrams,ip_lenwraps to a tiny value.
Recommended fix
Remove the stale hlen addition; keep the checksum recompute (still needed
because ip_reass modifies ip_len/ip_src/ip_dst/ip_off).
--- a/sys/netinet/ip_divert.c
+++ b/sys/netinet/ip_divert.c
@@ -598,13 +598,13 @@
*/
hlen = IP_VHL_HL(ip->ip_vhl) << 2;
+ /*
+ * Recompute the IP header checksum before diverting the
+ * packet to userspace, since ip_reass() modifies ip_len,
+ * ip_src, ip_dst and ip_off. ip_reass() already sets
+ * ip_len to include the header length (ip_input.c:1307),
+ * so do NOT add hlen again.
+ */
- /*
- * Restore original checksum before diverting
- * packet
- */
- ip->ip_len = htons(ntohs(ip->ip_len) + hlen);
ip->ip_sum = 0;
References
sys/netinet/ip_divert.c:607β the stalehlenaddition.sys/netinet/ip_input.c:1305-1307βip_reassincludes header inip_len.sys/netinet/ip_input.c:858-864β ip_input's own path does NOT re-addhlen.
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-0646 Β· 4 files| File | Type | Description | Size | |
|---|---|---|---|---|
| VERDICT.md | verdict | source-confirmation + fix | 970 B | β 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-0646 β Low-severity source-confirmation
Verdict: REPRODUCED
Impact: dos Confidence: likely
Kernel ref: sys/netinet/ip_divert.c:607
Mechanism / why
Source-confirmed: ip_divert_in does ip->ip_len=htons(ntohs(ip->ip_len)+hlen) after ip_reass() which already accounts for hlen -> double-count. ip_divert optional (not in GENERIC).
Recommended fix
Drop the post-reass hlen addition.
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).
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
- n
- e
- t
- /
- i
- p
- _
- d
- i
- v
- e
- r
- t
- .
- c
- :
- 6
- 0
- 7
Detail
Exploit chain
none (Low-severity dos; source-only confirmation)
Evidence (decisive lines)
DF-0646 [REPRODUCED] - sys/netinet/ip_divert.c:607
PoC changes
fix.diff documented (fix in verdict) in findings/poc/DF-0646/; batched into ../_batch_low/combined_all.patch
Verified recommended fix
Drop the post-reass hlen addition.
Verdict
Source-confirmed: ip_divert_in does ip->ip_len=htons(ntohs(ip->ip_len)+hlen) after ip_reass() which already accounts for hlen -> double-count. ip_divert optional (not in GENERIC).
No comments yet.