Skip to content

fragroute: size ip_frag/tcp_seg fragments by packet length (OSS-Fuzz 589370950) - #1229

Merged
fklassen merged 2 commits into
appneta:4.6.5from
tcpreplay-dev:fix-fragroute-frag-buf-growth
Nov 29, 2026
Merged

fklassen merged 2 commits into
appneta:4.6.5from
tcpreplay-dev:fix-fragroute-frag-buf-growth

Conversation

@tcpreplay-dev

Copy link
Copy Markdown
Contributor

OSS-Fuzz 589370950: fuzz_fragroute timeout in ip_frag_apply_ipv4(). It regressed in 4.6.2.

ip_frag (IPv4 and IPv6) and tcp_seg allocated each new fragment with pkt_new(pkt->pkt_buf_size). Since 1bb3eaa (#1163), pkt_new() adds PKT_BUF_SLACK on top of the length it's given, so each stacked ip_frag rule made every fragment's buffer 86 bytes bigger. The pkt_buf_size-sized tmp_buf VLA used for overlap grew along with it. If a long rules file also multiplies the queue with ip_chaff dup, the run takes minutes and exhausts memory. For example, 10× ip_chaff dup followed by 4000× ip_frag 8 OOMs at 2.2 GB under ASan on master; with this change it finishes in 3.7 s.

Fix: size each fragment by its source packet's length, plus the inserted fragment header for IPv6. A fragment is never larger than the packet it came from.

Test: test/unit/test_fragroute.c applies ip_frag (IPv4 and IPv6, 50 rounds) and tcp_seg directly and asserts that no fragment's buffer is larger than its source's. Without the fix the three new assertions fail (1516 → 5816 bytes after 50 rounds); with it all 7 pass. make check and the fragroute_* test targets pass under ASan+UBSan.

First PR targeting the new 4.6.5 release branch.

ip_frag and tcp_seg allocated each new fragment with
pkt_new(pkt->pkt_buf_size). Since 1bb3eaa pkt_new() adds PKT_BUF_SLACK
on top of the length it's given, so every stacked ip_frag rule grew each
fragment's buffer by 86 bytes. A long rules file multiplied by ip_chaff
dup made fuzz_fragroute time out (and run out of memory), and the
pkt_buf_size-sized tmp_buf VLA grew with it.

Size fragments by the source packet's length instead (plus the inserted
fragment header for IPv6); a fragment is never larger than its source.

OSS-Fuzz 589370950

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fklassen
fklassen merged commit 870c0b7 into appneta:4.6.5 Nov 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants