ip_frag: fix reassembly defects and add test
cover ip_frag: fix reassembly defects and add test
The IP reassembly library tracks only a running byte total and reserved slots for the first and last fragments, with no coverage map. As a result it mishandles duplicate, overlapping, oversized, and misheadered fragments, and the IPv4 key is missing a field RFC 791 requires. There was also no functional test to catch any of it.
These came out of reviewing a duplicate-fragment report on the list.
Patches 1 and 2 are interdependent: the overlap discard relies on the duplicate handling so an exact duplicate is dropped on its own rather than discarding the whole datagram. The rest are independent.
Patch 6 adds a functional test modeled on the Linux selftest ip_defrag.c. It passes on this series; with any single fix reverted the matching case fails.
Stephen Hemminger (6):
ip_frag: tolerate duplicate fragments
ip_frag: discard datagrams with overlapping fragments
ip_frag: include protocol in IPv4 reassembly key
ip_frag: drop IPv6 fragments with unexpected headers
ip_frag: reject oversized reassembled datagrams app/test: add test for IP reassembly
app/test/meson.build | 1 + app/test/test_reassembly.c | 644 ++++++++++++++++++++++++++++++ lib/ip_frag/ip_frag_internal.c | 36 +- lib/ip_frag/rte_ipv4_reassembly.c | 17 +- lib/ip_frag/rte_ipv6_reassembly.c | 22 +- 5 files changed, 714 insertions(+), 6 deletions(-) create mode 100644 app/test/test_reassembly.c
Signature · 1 line
2.53.0
PATCH 1/6 ip_frag: tolerate duplicate fragments
The reassembly code tracked only a running byte total and reserved slots for the first and last fragments, with no check for a fragment duplicating data already received. A single duplicate could destroy a recoverable datagram:
- a duplicate first or last fragment collided with the reserved slot and sent the whole entry down the error path, freeing every collected fragment;
- a duplicate intermediate fragment was appended to a new slot, inflating frag_size past total_size so reassembly never completed.
RFC 791 reassembly tolerates duplicates: a fragment covering bytes already present carries no new information. Check for an exact duplicate (stored fragment with the same offset and length) and drop only that mbuf, before frag_size is updated, leaving the entry's accounting unchanged.
Overlapping fragments with differing bounds are a separate issue addressed in the next patch.
--- lib/ip_frag/ip_frag_internal.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
lib/ip_frag/ip_frag_internal.c +17 -1
@@ -89,7 +89,23 @@ struct rte_mbuf * ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb, uint16_t ofs, uint16_t len, uint16_t more_frags) { - uint32_t idx; + uint32_t i, idx; + +/* +* Discard an exact duplicate fragment. If a previously stored fragment +* already covers the same offset and length, this fragment carries no +* new data. Reassembly is tolerant of duplicates (RFC 791), so drop +* only this mbuf and keep the reassembly entry intact rather than +* treating it as an error. Fragments overlapping an existing one with +* different bounds are not handled here. +*/ +for (i =0 ; i != fp->last_idx; i++) { +if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && + fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + } fp->frag_size += len;
Signature · 1 line
2.53.0
RE: [PATCH 1/6] ip_frag: tolerate duplicate fragments
Quoted 18 lines
The reassembly code tracked only a running byte total and reserved slots for the first and last fragments, with no check for a fragment duplicating data already received. A single duplicate could destroy a recoverable datagram:
- a duplicate first or last fragment collided with the reserved slot and sent the whole entry down the error path, freeing every collected fragment;
- a duplicate intermediate fragment was appended to a new slot, inflatingfrag_sizepasttotal_sizeso reassembly never completed.RFC 791 reassembly tolerates duplicates: a fragment covering bytes already present carries no new information. Check for an exact duplicate (stored fragment with the same offset and length) and drop only that mbuf, before
frag_sizeis updated, leaving the entry's accounting unchanged.
Quoted 5 lines
Overlapping fragments with differing bounds are a separate issue addressed in the next patch.
Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")
I am not sure it is a bug and needs to be propagated into the stable releases. To me it is more like feature improvement.
BTW, as this and next patch does change the behavior and probably overall performance numbers, - it probably worth to add a line in the release notes. As another thought - it might be squashed with next patch in the series (ip_frag: discard datagrams with overlapping fragments).
Apart from that:
Quoted 37 lines
Reported-by Samyak Jain <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/ip_frag_internal.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)lib/ip_frag/ip_frag_internal.c +17
-2@@ -89,7 +89,23 @@ struct rte_mbuf * ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb, uint16_t ofs, uint16_t len, uint16_t more_frags) { - uint32_t idx; + uint32_t i, idx; + +/* +* Discard an exact duplicate fragment. If a previously stored fragment +* already covers the same offset and length, this fragment carries no +* new data. Reassembly is tolerant of duplicates (RFC 791), so drop +* only this mbuf and keep the reassembly entry intact rather than +* treating it as an error. Fragments overlapping an existing one with +* different bounds are not handled here. +*/ +for (i =0 ; i != fp->last_idx; i++) { +if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && + fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + } fp->frag_size += len; --2.53.0
Re: [PATCH 1/6] ip_frag: tolerate duplicate fragments
Quoted 22 lines · On Tue, 30 Jun 2026 08:08:46 +0000 Konstantin Ananyev…
Quoted 16 lines
The reassembly code tracked only a running byte total and reserved slots for the first and last fragments, with no check for a fragment duplicating data already received. A single duplicate could destroy a recoverable datagram:
- a duplicate first or last fragment collided with the reserved slot and sent the whole entry down the error path, freeing every collected fragment;
- a duplicate intermediate fragment was appended to a new slot, inflatingfrag_sizepasttotal_sizeso reassembly never completed.RFC 791 reassembly tolerates duplicates: a fragment covering bytes already present carries no new information. Check for an exact duplicate (stored fragment with the same offset and length) and drop only that mbuf, before
frag_sizeis updated, leaving the entry's accounting unchanged.Quoted 5 lines
Overlapping fragments with differing bounds are a separate issue addressed in the next patch.
Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")
Quoted 8 lines
I am not sure it is a bug and needs to be propagated into the stable releases. To me it is more like feature improvement.
BTW, as this and next patch does change the behavior and probably overall performance numbers, - it probably worth to add a line in the release notes. As another thought - it might be squashed with next patch in the series (ip_frag: discard datagrams with overlapping fragments).
Apart from that:
The problem is that duplicate fragments are used to workaround firewalls. So latent security issue
PATCH 2/6 ip_frag: discard datagrams with overlapping fragments
In reply to Stephen HemmingerExisting code does not handle overlapping fragments.
RFC 8200 (IPv6) requires that on overlap all reassembly is abandoned andall received fragments are dropped. RFC 791 (IPv4) originally called fortrimming and rewriting, but Linux discards for IPv4 as well, since overlap has no legitimate use and is a known attack vector.
Depends on the duplicate-tolerance change so that an exact duplicate is dropped on its own rather than discarding the whole datagram.
--- lib/ip_frag/ip_frag_internal.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
lib/ip_frag/ip_frag_internal.c +26 -8
@@ -92,16 +92,34 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,uint32_t i, idx;/* -* Discard an exact duplicate fragment. If a previously stored fragment -* already covers the same offset and length, this fragment carries no -* new data. Reassembly is tolerant of duplicates (RFC 791), so drop -* only this mbuf and keep the reassembly entry intact rather than -* treating it as an error. Fragments overlapping an existing one with -* different bounds are not handled here. +* Scan the fragments already collected for this datagram before +* storing the new one. The stored set is kept free of duplicates and +* overlaps, so a single pass is sufficient. */ for (i =0 ; i != fp->last_idx; i++) { -if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && - fp->frags[i].len == len) { +if (fp->frags[i].mb ==NULL ) +continue ; + +/* +* Exact duplicate: carries no new data. Reassembly tolerates +* duplicates (RFC 791), so drop only this mbuf and keep the +* entry. +*/ +if (fp->frags[i].ofs == ofs && fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + +/* +* Overlap with an existing fragment. Per RFC 8200 section 4.5 +* (and RFC 5722) the datagram must be discarded; the same is +* applied to IPv4. Free all collected fragments, drop this one, +* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && + fp->frags[i].ofs < ofs + len) { +ip_frag_free (fp, dr); +ip_frag_key_invalidate (&fp->key);IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
Signature · 1 line
2.53.0
RE: [PATCH 2/6] ip_frag: discard datagrams with overlapping fragments
Quoted 72 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 16 June 2026 23.06Existing code does not handle overlapping fragments.
RFC 8200 (IPv6) requires that on overlap all reassembly is abandoned andall received fragments are dropped. RFC 791 (IPv4) originally called fortrimming and rewriting, but Linux discards for IPv4 as well, since overlap has no legitimate use and is a known attack vector.
Depends on the duplicate-tolerance change so that an exact duplicate is dropped on its own rather than discarding the whole datagram.
Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/ip_frag_internal.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)lib/ip_frag/ip_frag_internal.c +0
-1@@ -92,16 +92,34 @@ ip_frag_process(struct ip_frag_pkt *fp, structrte_ip_frag_death_row *dr, uint32_t i, idx;/* -* Discard an exact duplicate fragment. If a previously stored fragment
lib/ip_frag/ip_frag_internal.c +0
-1-* already covers the same offset and length, this fragment carries no
lib/ip_frag/ip_frag_internal.c +0
-1-* new data. Reassembly is tolerant of duplicates (RFC 791), so drop
lib/ip_frag/ip_frag_internal.c +0
-1-* only this mbuf and keep the reassembly entry intact rather than
lib/ip_frag/ip_frag_internal.c +0
-1-* treating it as an error. Fragments overlapping an existing one with
lib/ip_frag/ip_frag_internal.c +2
-1-* different bounds are not handled here. +* Scan the fragments already collected for this datagram before +* storing the new one. The stored set is kept free of duplicates and
lib/ip_frag/ip_frag_internal.c +6
-2+* overlaps, so a single pass is sufficient. */ for (i =0 ; i != fp->last_idx; i++) { -if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && - fp->frags[i].len == len) { +if (fp->frags[i].mb ==NULL ) +continue ; + +/* +* Exact duplicate: carries no new data. Reassembly tolerates
lib/ip_frag/ip_frag_internal.c +1
-0+* duplicates (RFC 791), so drop only this mbuf and keep the
lib/ip_frag/ip_frag_internal.c +9
-0+* entry. +*/ +if (fp->frags[i].ofs == ofs && fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + +/* +* Overlap with an existing fragment. Per RFC 8200 section 4.5
lib/ip_frag/ip_frag_internal.c +1
-0+* (and RFC 5722) the datagram must be discarded; the same is
lib/ip_frag/ip_frag_internal.c +1
-0+* applied to IPv4. Free all collected fragments, drop this one,
lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 120
Quoted 4 lines
lib/ip_frag/ip_frag_internal.c +4
-0+* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && + fp->frags[i].ofs < ofs + len) {
This only catches fragments that are smaller than existing fragments, i.e. fit within one of the existing fragments. It should be:
if ((ofs >= fp->frags[i].ofs &&
ofs < fp->frags[i].ofs + fp->frags[i].len) ||
(ofs + len >= fp->frags[i].ofs &&
ofs + len < fp->frags[i].ofs + fp->frags[i].len)) {Quoted 7 lines
lib/ip_frag/ip_frag_internal.c +2
-1+ip_frag_free (fp, dr); +ip_frag_key_invalidate (&fp->key);IP_FRAG_MBUF2DR (dr, mb);return NULL ; } --2.53.0
Re: [PATCH 2/6] ip_frag: discard datagrams with overlapping fragments
Quoted 15 lines · On Fri, 19 Jun 2026 15:12:21 +0200 Morten Brørup <[email protected]>…
lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 120
Quoted 11 lines
(quoted diff) +2
-0+ /* + * Overlap with an existing fragment. Per RFC 8200 section4.5
(quoted diff) +1
-0+ * (and RFC 5722) the datagram must be discarded; the sameis
(quoted diff) +1
-0+ * applied to IPv4. Free all collected fragments, drop thisone,
lib/ip_frag/ip_frag_internal.c +4
-0+* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && + fp->frags[i].ofs < ofs + len) {This only catches fragments that are smaller than existing fragments, i.e. fit within one of the existing fragments. It should be:
if ((ofs >= fp->frags[i].ofs &&
Quoted 5 lines
ofs < fp->frags[i].ofs + fp->frags[i].len) || (ofs + len >= fp->frags[i].ofs && ofs + len < fp->frags[i].ofs + fp->frags[i].len)) {lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 121
Quoted 1 line
lib/ip_frag/ip_frag_internal.c +1
-0+ip_frag_free (fp, dr);
The code here is comparing an incoming fragment N against existing fragment E, using half-open ranges [start, end).
The test in the patch is symmetric in N and E.
ofs < e.ofs + e.len && e.ofs < ofs + len
The one you propose tests that either endpoint of N lands inside E.
Take a fixed stored fragment E = [200, 400) and run several incoming fragments through both.
N0 = ofs, N1 = ofs+len.
N inside E: N = [250, 300)
E: |=========| (200..400) N: |===| (250..300)
Patch: 250 < 400 && 200 < 300 → T && T → overlap.
Proposed: (250≥200 && 250<400) → T → overlap.
Both agree.
N encloses E: N = [100, 500)
E: |=========| (200..400) N: |=============| (100..500)
Patch: 100 < 400 && 200 < 500 → T && T → overlap.
Proposed: (100≥200 && …) → F, (500≥200 && 500<400) → T && F → F, so F || F → no overlap, MISSED.
This is the case the new version version drops. Neither endpoint of N (100 or 500) sits inside [200,400), because N straddles E completely, so new version endpoint-in-E check fails even though the ranges clearly overlap. Patch version catches it because the interval test doesn't care which range is larger.
N partial on the left: N = [100, 300)
E: |=========| (200..400) N: |======| (100..300)
Patch: 100 < 400 && 200 < 300 → T → overlap.
Proposed: (300≥200 && 300<400) → T → overlap.
Agree.
N partial on the right: N = [300, 500) — symmetric to the above, both catch it.
So on the four genuine-overlap geometries, your suggestion catches all four and his misses the enclosing one. That is not right since the enclosing overlap is a legitimate attack shape (a big fragment overwriting a smaller stored one).
There is another issue.
The >= on the exclusive end produces a false positive on fragments that merely abut, which is the normal case.
Take E already stored as [1400, 2800) and an in-order-but-late fragment N = [0, 1400) arriving after it (ordinary out-of-order delivery):
N: |======| (0..1400) E: |======| (1400..2800)
These share no bytes; byte 1400 belongs only to E.
Patch: 0 < 2800 && 1400 < 1400 → T && F → no overlap, correct.
Proposed: (1400≥1400 && 1400<2800) → T && T → overlap, wrong.
This test would discard a perfectly valid datagram whenever a left-abutting fragment arrives after its neighbor. Adjacent fragments abutting is what fragmentation produces by design, so this would fire constantly under reordering.
Bottom line: the patch was correct as far as I can tell.
RE: [PATCH 2/6] ip_frag: discard datagrams with overlapping fragments
Quoted 100 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 19 June 2026 19.01Quoted 5 lines · On Fri, 19 Jun 2026 15:12:21 +0200 Morten Brørup <[email protected]>…
Quoted 5 lines
(quoted diff) +2
-0+ /* + * Overlap with an existing fragment. Per RFC 8200 section4.5
(quoted diff) +1
-0+ * (and RFC 5722) the datagram must be discarded; the sameis
Quoted 8 lines
lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 120
Quoted 6 lines
(quoted diff) +1
-0+ * applied to IPv4. Free all collected fragments, drop thisone,
lib/ip_frag/ip_frag_internal.c +4
-0+* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && + fp->frags[i].ofs < ofs + len) {This only catches fragments that are smaller than existing fragments,
i.e. fit within one of the existing fragments.
Quoted 7 lines
It should be:
if ((ofs >= fp->frags[i].ofs &&ofs < fp->frags[i].ofs + fp->frags[i].len) || (ofs + len >= fp->frags[i].ofs && ofs + len < fp->frags[i].ofs + fp->frags[i].len)) {lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 121
Quoted 1 line
lib/ip_frag/ip_frag_internal.c +1
-0+ip_frag_free (fp, dr);The code here is comparing an incoming fragment N against existing fragment E,
using half-open ranges [start, end).The test in the patch is symmetric in N and E.
ofs < e.ofs + e.len && e.ofs < ofs + lenThe one you propose tests that either endpoint of N lands inside E.
Take a fixed stored fragment E = [200, 400) and run several incoming fragments through both.
N0 = ofs, N1 = ofs+len.N inside E: N = [250, 300)
E: |=========| (200..400) N: |===| (250..300)Patch: 250 < 400 && 200 < 300 → T && T → overlap.
Proposed: (250≥200 && 250<400) → T → overlap.
Both agree.N encloses E: N = [100, 500)
E: |=========| (200..400) N: |=============| (100..500)Patch: 100 < 400 && 200 < 500 → T && T → overlap.
Proposed: (100≥200 && …) → F, (500≥200 && 500<400) → T && F → F, so F || F → no overlap, MISSED.This is the case the new version version drops. Neither endpoint of N (100 or 500) sits inside [200,400),
because N straddles E completely, so new version endpoint-in-E check fails even though the ranges clearly overlap.
Patch version catches it because the interval test doesn't care which range is larger.N partial on the left: N = [100, 300)
E: |=========| (200..400) N: |======| (100..300)Patch: 100 < 400 && 200 < 300 → T → overlap.
Proposed: (300≥200 && 300<400) → T → overlap.
Agree.N partial on the right: N = [300, 500) — symmetric to the above, both catch it.
So on the four genuine-overlap geometries, your suggestion catches all four and his misses the enclosing one.
That is not right since the enclosing overlap is a legitimate attack shape (a big fragment overwriting a smaller stored one).There is another issue.
The >= on the exclusive end produces a false positive on fragments that merely abut, which is the normal case.
Take E already stored as [1400, 2800) and an in-order-but-late fragment N = [0, 1400) arriving after it (ordinary out-of-order delivery):N: |======| (0..1400) E: |======| (1400..2800)These share no bytes; byte 1400 belongs only to E.
Patch: 0 < 2800 && 1400 < 1400 → T && F → no overlap, correct.
Proposed: (1400≥1400 && 1400<2800) → T && T → overlap, wrong. This test would discard a perfectly valid datagram whenever a left- abutting fragment arrives after its neighbor.
Adjacent fragments abutting is what fragmentation produces by design, so this would fire constantly under reordering.
Quoted 1 line
Bottom line: the patch was correct as far as I can tell.
Thank you for the detailed explanation, Stephen.
Agreed, and sorry about the noise. :-)
Re: [PATCH 2/6] ip_frag: discard datagrams with overlapping fragments
Quoted 100 lines · On Mon, 22 Jun 2026 17:01:18 +0200 Morten Brørup <[email protected]>…
Quoted 100 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 19 June 2026 19.01Quoted 5 lines · On Fri, 19 Jun 2026 15:12:21 +0200 Morten Brørup <[email protected]>…
Quoted 5 lines
(quoted diff) +2
-0+ /* + * Overlap with an existing fragment. Per RFC 8200 section4.5
(quoted diff) +1
-0+ * (and RFC 5722) the datagram must be discarded; the sameis
Quoted 8 lines
lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 120
Quoted 6 lines
(quoted diff) +1
-0+ * applied to IPv4. Free all collected fragments, drop thisone,
lib/ip_frag/ip_frag_internal.c +4
-0+* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && + fp->frags[i].ofs < ofs + len) {This only catches fragments that are smaller than existing fragments,
i.e. fit within one of the existing fragments.
Quoted 7 lines
It should be:
if ((ofs >= fp->frags[i].ofs &&ofs < fp->frags[i].ofs + fp->frags[i].len) || (ofs + len >= fp->frags[i].ofs && ofs + len < fp->frags[i].ofs + fp->frags[i].len)) {lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, · line 121
Quoted 1 line
lib/ip_frag/ip_frag_internal.c +1
-0+ip_frag_free (fp, dr);The code here is comparing an incoming fragment N against existing fragment E,
using half-open ranges [start, end).The test in the patch is symmetric in N and E.
ofs < e.ofs + e.len && e.ofs < ofs + lenThe one you propose tests that either endpoint of N lands inside E.
Take a fixed stored fragment E = [200, 400) and run several incoming fragments through both.
N0 = ofs, N1 = ofs+len.N inside E: N = [250, 300)
E: |=========| (200..400) N: |===| (250..300)Patch: 250 < 400 && 200 < 300 → T && T → overlap.
Proposed: (250≥200 && 250<400) → T → overlap.
Both agree.N encloses E: N = [100, 500)
E: |=========| (200..400) N: |=============| (100..500)Patch: 100 < 400 && 200 < 500 → T && T → overlap.
Proposed: (100≥200 && …) → F, (500≥200 && 500<400) → T && F → F, so F || F → no overlap, MISSED.This is the case the new version version drops. Neither endpoint of N (100 or 500) sits inside [200,400),
because N straddles E completely, so new version endpoint-in-E check fails even though the ranges clearly overlap.
Patch version catches it because the interval test doesn't care which range is larger.N partial on the left: N = [100, 300)
E: |=========| (200..400) N: |======| (100..300)Patch: 100 < 400 && 200 < 300 → T → overlap.
Proposed: (300≥200 && 300<400) → T → overlap.
Agree.N partial on the right: N = [300, 500) — symmetric to the above, both catch it.
So on the four genuine-overlap geometries, your suggestion catches all four and his misses the enclosing one.
That is not right since the enclosing overlap is a legitimate attack shape (a big fragment overwriting a smaller stored one).There is another issue.
The >= on the exclusive end produces a false positive on fragments that merely abut, which is the normal case.
Take E already stored as [1400, 2800) and an in-order-but-late fragment N = [0, 1400) arriving after it (ordinary out-of-order delivery):N: |======| (0..1400) E: |======| (1400..2800)These share no bytes; byte 1400 belongs only to E.
Patch: 0 < 2800 && 1400 < 1400 → T && F → no overlap, correct.
Proposed: (1400≥1400 && 1400<2800) → T && T → overlap, wrong. This test would discard a perfectly valid datagram whenever a left- abutting fragment arrives after its neighbor.
Adjacent fragments abutting is what fragmentation produces by design, so this would fire constantly under reordering.
Quoted 5 lines
Quoted 1 line
Bottom line: the patch was correct as far as I can tell.
Thank you for the detailed explanation, Stephen.
Agreed, and sorry about the noise. :-)
I will give credit to Claude for the detail. I reviewed the general code here; but had to prod it into giving a more detailed explaination because it was confusing..
RE: [PATCH 2/6] ip_frag: discard datagrams with overlapping fragments
In reply to Stephen HemmingerQuoted 8 lines
Existing code does not handle overlapping fragments.
RFC 8200 (IPv6) requires that on overlap all reassembly is abandoned andall received fragments are dropped. RFC 791 (IPv4) originally called fortrimming and rewriting, but Linux discards for IPv4 as well, since overlap has no legitimate use and is a known attack vector.
Spaces are missing in a few places in the sentence above:
'andall' . "fortrimming'.
Quoted 49 lines
Depends on the duplicate-tolerance change so that an exact duplicate is dropped on its own rather than discarding the whole datagram.
Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/ip_frag_internal.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)lib/ip_frag/ip_frag_internal.c +18
-8@@ -92,16 +92,34 @@ ip_frag_process(struct ip_frag_pkt *fp, structrte_ip_frag_death_row *dr, uint32_t i, idx;/* -* Discard an exact duplicate fragment. If a previously stored fragment -* already covers the same offset and length, this fragment carries no -* new data. Reassembly is tolerant of duplicates (RFC 791), so drop -* only this mbuf and keep the reassembly entry intact rather than -* treating it as an error. Fragments overlapping an existing one with -* different bounds are not handled here. +* Scan the fragments already collected for this datagram before +* storing the new one. The stored set is kept free of duplicates and +* overlaps, so a single pass is sufficient. */ for (i =0 ; i != fp->last_idx; i++) { -if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && - fp->frags[i].len == len) { +if (fp->frags[i].mb ==NULL ) +continue ; + +/* +* Exact duplicate: carries no new data. Reassembly tolerates +* duplicates (RFC 791), so drop only this mbuf and keep the +* entry. +*/ +if (fp->frags[i].ofs == ofs && fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + +/* +* Overlap with an existing fragment. Per RFC 8200 section 4.5
lib/ip_frag/ip_frag_internal.c ip_frag_process(struct ip_frag_pkt *fp, struct · line 125
Quoted 10 lines
lib/ip_frag/ip_frag_internal.c +8
-0+* (and RFC 5722) the datagram must be discarded; the same is +* applied to IPv4. Free all collected fragments, drop this one, +* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && + fp->frags[i].ofs < ofs + len) { +ip_frag_free (fp, dr); +ip_frag_key_invalidate (&fp->key);IP_FRAG_MBUF2DR (dr, mb);return NULL ;
Usually that function does some logging IP_FRAG_LOG(...) in case invalid fragments were detected (see function body below these changes). Probably worth to keep same here:
Might be a new helper function that will report an error and free table entry, that can be used across all places in that function.
Apart from that:
Quoted 3 lines
}
--
2.53.0
PATCH 3/6 ip_frag: include protocol in IPv4 reassembly key
In reply to Stephen HemmingerDPDK IPv4 reassembly code was not following RFC 791 section 3.2 which says:
The internet identification field (ID) is used together with the source and destination address, and the protocol fields, to identify datagram fragments for reassembly.
Omitting the protocol means two datagrams between the
same pair of hosts that share an IP id but carry different protocols (for example UDP and ICMP) are merged into a single reassembly context, producing a corrupted datagram.
Fold the protocol into the unused upper bits of the 32-bit id field of the key. The IPv4 identification is 16 bits and occupies the low half, so the protocol can be carried in the upper bits without changing the key layout, the key comparison or the hash.
--- lib/ip_frag/rte_ipv4_reassembly.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/ip_frag/rte_ipv4_reassembly.c +7 -1
@@ -111,9 +111,15 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, ip_ofs = (uint16_t )(flag_offset &RTE_IPV4_HDR_OFFSET_MASK ); ip_flag = (uint16_t )(flag_offset &RTE_IPV4_HDR_MF_FLAG ); +/* +* RFC 791 requires using: source, destination, identifier field and protocol +*/ +/* use first 8 bytes only */ memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,8 ); - key.id = ip_hdr->packet_id; + +/* packet_id is 16 bits and proto id is 8 bits */ + key.id = ((uint32_t ) ip_hdr->next_proto_id <<16 ) | ip_hdr->packet_id; key.key_len =IPV4_KEYLEN ; ip_ofs *=RTE_IPV4_HDR_OFFSET_UNITS ;
Signature · 1 line
2.53.0
RE: [PATCH 3/6] ip_frag: include protocol in IPv4 reassembly key
Quoted 40 lines
DPDK IPv4 reassembly code was not following RFC 791 section 3.2 which says:
The internet identification field (ID) is used together with the source and destination address, and the protocol fields, to identify datagram fragments for reassembly.Omitting the protocol means two datagrams between the
same pair of hosts that share an IP id but carry different protocols (for example UDP and ICMP) are merged into a single reassembly context, producing a corrupted datagram.Fold the protocol into the unused upper bits of the 32-bit id field of the key. The IPv4 identification is 16 bits and occupies the low half, so the protocol can be carried in the upper bits without changing the key layout, the key comparison or the hash.
Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/rte_ipv4_reassembly.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)lib/ip_frag/rte_ipv4_reassembly.c +2
-0@@ -111,9 +111,15 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, ip_ofs = (uint16_t )(flag_offset &RTE_IPV4_HDR_OFFSET_MASK ); ip_flag = (uint16_t )(flag_offset &RTE_IPV4_HDR_MF_FLAG ); +/* +* RFC 791 requires using: source, destination, identifier field and protocol
lib/ip_frag/rte_ipv4_reassembly.c +2
-0+*/ +
lib/ip_frag/rte_ipv4_reassembly.c rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
Quoted 10 lines
lib/ip_frag/rte_ipv4_reassembly.c +3
-2/* use first 8 bytes only */ memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,8 ); - key.id = ip_hdr->packet_id; + +/* packet_id is 16 bits and proto id is 8 bits */ + key.id = ((uint32_t ) ip_hdr->next_proto_id <<16 ) | ip_hdr->packet_id; key.key_len =IPV4_KEYLEN ; ip_ofs *=RTE_IPV4_HDR_OFFSET_UNITS ; --
Quoted 1 line
2.53.0
PATCH 4/6 ip_frag: drop IPv6 fragments with unexpected headers
In reply to Stephen HemmingerDPDK version of IPv6 reassembly only handles a fragment header placed directly after the IPv6 header. With other extension headers in the unfragmentable part, ipv6_frag_reassemble() patches the wrong next-header field, miscomputes the payload length, and shifts the wrong bytes, corrupting the result.
Drop the fragment when l3_len covers more than the IPv6 and fragment headers. RFC 8200 allows a receiver to discard packets whose extension headers are not in the recommended order, and RFC 9099 recommends dropping non-conforming fragmented IPv6 packets, so dropping here is permitted rather than a deviation.
--- lib/ip_frag/rte_ipv6_reassembly.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/ip_frag/rte_ipv6_reassembly.c +13 -0
@@ -180,6 +180,19 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,return NULL ; } +/* +* Only a fragment header directly following the IPv6 header is +* supported. Other extension headers in the unfragmentable part are +* not handled: ipv6_frag_reassemble() assumes l3_len covers exactly +* the IPv6 and fragment headers when it patches the next-header field +* and removes the fragment header. Drop the fragment rather than +* produce a corrupt datagram. +*/ +if (mb->l3_len !=sizeof (struct rte_ipv6_hdr ) +sizeof (*frag_hdr)) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } +if (unlikely (trim >0 ))rte_pktmbuf_trim (mb, trim);
Signature · 1 line
2.53.0
RE: [PATCH 4/6] ip_frag: drop IPv6 fragments with unexpected headers
Quoted 34 lines
DPDK version of IPv6 reassembly only handles a fragment header placed directly after the IPv6 header. With other extension headers in the unfragmentable part,
ipv6_frag_reassemble()patches the wrong next-header field, miscomputes the payload length, and shifts the wrong bytes, corrupting the result.Drop the fragment when
l3_lencovers more than the IPv6 and fragment headers. RFC 8200 allows a receiver to discard packets whose extension headers are not in the recommended order, and RFC 9099 recommends dropping non-conforming fragmented IPv6 packets, so dropping here is permitted rather than a deviation.Fixes 4f1a8f633862 ("ip_frag: add IPv6 reassembly")Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/rte_ipv6_reassembly.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)lib/ip_frag/rte_ipv6_reassembly.c +3
-0@@ -180,6 +180,19 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, return NULL; } +/* +* Only a fragment header directly following the IPv6 header is +* supported. Other extension headers in the unfragmentable part are
lib/ip_frag/rte_ipv6_reassembly.c rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl · line 196
Quoted 10 lines
lib/ip_frag/rte_ipv6_reassembly.c +10
-0+* not handled: ipv6_frag_reassemble() assumes l3_len covers exactly +* the IPv6 and fragment headers when it patches the next-header field +* and removes the fragment header. Drop the fragment rather than +* produce a corrupt datagram. +*/ +if (mb->l3_len !=sizeof (struct rte_ipv6_hdr ) +sizeof (*frag_hdr)) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } +
Hmm, not sure this is a right thing.
Yes, we don't support properly ipv6 options that are *before* fragment hreader (so called Per-Fragment Headers), but AFAIR we do support ipv6 options that come *after* fragment header (Extension headers).
Quoted 5 lines
lib/ip_frag/rte_ipv6_reassembly.c +0
-1if (unlikely (trim >0 ))rte_pktmbuf_trim (mb, trim); --2.53.0
PATCH 5/6 ip_frag: reject oversized reassembled datagrams
In reply to Stephen HemmingerThe reassembled total length of a packet must not exceed 65535. A fragment with a high offset could drive the sum past that, causing silent truncation since IP payload_len/total_length is 16 bits.
When reassembling a packet the total length should not be allowed to exceed 65535. A fragment with high offset could drive the sum past that, causing silent truncation.
A valid datagram never exceeds 65535 bytes, so reject any fragment whose resulting length would exceed that.
Fold the test into the existing zero-length check.
--- lib/ip_frag/rte_ipv4_reassembly.c | 9 +++++++-- lib/ip_frag/rte_ipv6_reassembly.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
lib/ip_frag/rte_ipv4_reassembly.c +7 -2
@@ -136,8 +136,13 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled datagram exceed the maximum IPv4 size. The +* total_length field is 16 bits, so otherwise it is silently +* truncated while the mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len + mb->l3_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
lib/ip_frag/rte_ipv6_reassembly.c +7 -2
@@ -174,8 +174,13 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled payload exceed 65535 bytes. The payload_len +* field is 16 bits, so otherwise it is silently truncated while the +* mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
Signature · 1 line
2.53.0
RE: [PATCH 5/6] ip_frag: reject oversized reassembled datagrams
Quoted 63 lines
The reassembled total length of a packet must not exceed 65535. A fragment with a high offset could drive the sum past that, causing silent truncation since IP payload_len/total_length is 16 bits.
When reassembling a packet the total length should not be allowed to exceed 65535. A fragment with high offset could drive the sum past that, causing silent truncation.
A valid datagram never exceeds 65535 bytes, so reject any fragment whose resulting length would exceed that.
Fold the test into the existing zero-length check.Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/rte_ipv4_reassembly.c | 9 +++++++-- lib/ip_frag/rte_ipv6_reassembly.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)lib/ip_frag/rte_ipv4_reassembly.c +7
-2@@ -136,8 +136,13 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled datagram exceed the maximum IPv4 size. The +* total_length field is 16 bits, so otherwise it is silently +* truncated while the mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len + mb->l3_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ;lib/ip_frag/rte_ipv4_reassembly.c +0
-0}lib/ip_frag/rte_ipv6_reassembly.c +7
-2@@ -174,8 +174,13 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled payload exceed 65535 bytes. The payload_len +* field is 16 bits, so otherwise it is silently truncated while the +* mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ;
Quoted 2 lines
}
--
Quoted 1 line
2.53.0
PATCH 6/6 app/test: add test for IP reassembly
In reply to Stephen HemmingerThere was no functional test for IPv4/IPv6 reassembly, only a performance test. Add a new test modeled on the Linux kernel selftest tools/testing/selftests/net/ip_defrag.c. This is new code so no license conflict.
Test covers:
size and fragment-size sweep across in-order, reverse, odd/even and block delivery orders with byte-exact payload validation; minimum 8-byte fragments; the fragment-count limit;
timeout of incomplete datagrams;
and the duplicate, overlap, extension-header and oversized-fragment cases fixed earlier in this series.
The reassembled packet is checked with rte_mbuf_check() to catch malformed segment chains in addition to wrong content.
--- app/test/meson.build | 1 + app/test/test_reassembly.c | 644 +++++++++++++++++++++++++++++++++++++ 2 files changed, 645 insertions(+) create mode 100644 app/test/test_reassembly.c
app/test/meson.build +1 -0
@@ -160,6 +160,7 @@ source_file_deps = { 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'], 'test_rcu_qsbr_perf.c': ['rcu', 'hash'], + 'test_reassembly.c': ['net', 'ip_frag'], 'test_reassembly_perf.c': ['net', 'ip_frag'], 'test_reciprocal_division.c': [], 'test_reciprocal_division_perf.c': [],
app/test/test_reassembly.c new file +644 -0
644 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 16 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 16 June 2026 23.06The IP reassembly library tracks only a running byte total and reserved slots for the first and last fragments, with no coverage map. As a result
it mishandles duplicate, overlapping, oversized, and misheadered fragments, and the IPv4 key is missing a field RFC 791 requires. There was also no functional test to catch any of it.These came out of reviewing a duplicate-fragment report on the list.
Patches 1 and 2 are interdependent: the overlap discard relies on the duplicate handling so an exact duplicate is dropped on its own rather than discarding the whole datagram. The rest are independent.
Quoted 5 lines
Patch 6 adds a functional test modeled on the Linux selftest
ip_defrag.c.
It passes on this series; with any single fix reverted the matching case
fails.
With patch 2/6 fixed,
Quoted 2 lines
With patch 2/6 fixed,
Series-acked-by Morten Brørup <[email protected]>
No bug in patch 2/6, so no fix required.
v2 cover ip_frag: fix reassembly defects and add test
In reply to Stephen HemmingerThe IP reassembly library tracks only a running byte total and reserved slots for the first and last fragments, with no coverage map. As a result it mishandles duplicate, overlapping, oversized, and misheadered fragments, and the IPv4 key is missing a field RFC 791 requires. There was also no functional test to catch any of it.
These came out of reviewing a duplicate-fragment report on the list.
Patches 1 and 2 are interdependent: the overlap discard relies on the duplicate handling so an exact duplicate is dropped on its own rather than discarding the whole datagram. The rest are independent.
Patch 6 adds a functional test modeled on the Linux selftest ip_defrag.c. It passes on this series; with any single fix reverted the matching case fails.
Stephen Hemminger (8):
ip_frag: tolerate duplicate fragments
ip_frag: discard datagrams with overlapping fragments
ip_frag: include protocol in IPv4 reassembly key
ip_frag: drop IPv6 fragments with per-fragment headers
ip_frag: reject oversized reassembled datagrams app/test: add test for IP reassembly
ip_frag: remove use of rte_memcpy
doc: add release note about ip_frag changes
app/test/meson.build | 1 + app/test/test_reassembly.c | 675 +++++++++++++++++++++++++ doc/guides/rel_notes/release_26_07.rst | 6 + lib/ip_frag/ip_frag_internal.c | 40 +- lib/ip_frag/rte_ipv4_reassembly.c | 17 +- lib/ip_frag/rte_ipv6_fragmentation.c | 3 +- lib/ip_frag/rte_ipv6_reassembly.c | 36 +- 7 files changed, 767 insertions(+), 11 deletions(-) create mode 100644 app/test/test_reassembly.c
Signature · 1 line
2.53.0
PATCH v2 1/8 ip_frag: tolerate duplicate fragments
The reassembly code tracked only a running byte total and reserved slots for the first and last fragments, with no check for a fragment duplicating data already received. A single duplicate could destroy a recoverable datagram:
- a duplicate first or last fragment collided with the reserved slot and sent the whole entry down the error path, freeing every collected fragment;
- a duplicate intermediate fragment was appended to a new slot, inflating frag_size past total_size so reassembly never completed.
RFC 791 reassembly tolerates duplicates: a fragment covering bytes already present carries no new information. Check for an exact duplicate (stored fragment with the same offset and length) and drop only that mbuf, before frag_size is updated, leaving the entry's accounting unchanged.
Overlapping fragments with differing bounds are a separate issue addressed in the next patch.
--- lib/ip_frag/ip_frag_internal.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
lib/ip_frag/ip_frag_internal.c +17 -1
@@ -89,7 +89,23 @@ struct rte_mbuf * ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb, uint16_t ofs, uint16_t len, uint16_t more_frags) { - uint32_t idx; + uint32_t i, idx; + +/* +* Discard an exact duplicate fragment. If a previously stored fragment +* already covers the same offset and length, this fragment carries no +* new data. Reassembly is tolerant of duplicates (RFC 791), so drop +* only this mbuf and keep the reassembly entry intact rather than +* treating it as an error. Fragments overlapping an existing one with +* different bounds are not handled here. +*/ +for (i =0 ; i != fp->last_idx; i++) { +if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && + fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + } fp->frag_size += len;
Signature · 1 line
2.53.0
PATCH v2 2/8 ip_frag: discard datagrams with overlapping fragments
In reply to Stephen HemmingerExisting code does not handle overlapping fragments.
RFC 8200 (IPv6) requires that on overlap all reassembly is abandoned and all received fragments are dropped. RFC 791 (IPv4) originally called for trimming and rewriting, but Linux discards for IPv4 as well, since overlap has no legitimate use and is a known attack vector.
Depends on the duplicate-tolerance change so that an exact duplicate is dropped on its own rather than discarding the whole datagram.
--- lib/ip_frag/ip_frag_internal.c | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-)
lib/ip_frag/ip_frag_internal.c +30 -8
@@ -92,16 +92,38 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,uint32_t i, idx;/* -* Discard an exact duplicate fragment. If a previously stored fragment -* already covers the same offset and length, this fragment carries no -* new data. Reassembly is tolerant of duplicates (RFC 791), so drop -* only this mbuf and keep the reassembly entry intact rather than -* treating it as an error. Fragments overlapping an existing one with -* different bounds are not handled here. +* Scan the fragments already collected for this datagram before +* storing the new one. The stored set is kept free of duplicates and +* overlaps, so a single pass is sufficient. */ for (i =0 ; i != fp->last_idx; i++) { -if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && - fp->frags[i].len == len) { +if (fp->frags[i].mb ==NULL ) +continue ; + +/* +* Exact duplicate: carries no new data. Reassembly tolerates +* duplicates (RFC 791), so drop only this mbuf and keep the +* entry. +*/ +if (fp->frags[i].ofs == ofs && fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + +/* +* Overlap with an existing fragment. Per RFC 8200 section 4.5 +* (and RFC 5722) the datagram must be discarded; the same is +* applied to IPv4. Free all collected fragments, drop this one, +* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && fp->frags[i].ofs < ofs + len) { +IP_FRAG_LOG (DEBUG , +"%s:%d overlap ofs: %u len: %u\n" +"fragment: %p ofs: %u len %u\n\n" , + __func__, __LINE__, ofs, len, + fp, fp->frags[i].ofs, fp->frags[i].len); +ip_frag_free (fp, dr); +ip_frag_key_invalidate (&fp->key);IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
Signature · 1 line
2.53.0
RE: [PATCH v2 2/8] ip_frag: discard datagrams with overlapping fragments
Quoted 9 lines
Existing code does not handle overlapping fragments.
RFC 8200 (IPv6) requires that on overlap all reassembly is abandoned and all received fragments are dropped. RFC 791 (IPv4) originally called for trimming and rewriting, but Linux discards for IPv4 as well, since overlap has no legitimate use and is a known attack vector.
Quoted 5 lines
Depends on the duplicate-tolerance change so that an exact duplicate is dropped on its own rather than discarding the whole datagram.
Fixes cc8f4d020c0b ("examples/ip_reassembly: initial import")
I think you forgot to remove cc; stable.
Quoted 62 lines
Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/ip_frag_internal.c | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-)lib/ip_frag/ip_frag_internal.c +30
-8@@ -92,16 +92,38 @@ ip_frag_process(struct ip_frag_pkt *fp, structrte_ip_frag_death_row *dr, uint32_t i, idx;/* -* Discard an exact duplicate fragment. If a previously stored fragment -* already covers the same offset and length, this fragment carries no -* new data. Reassembly is tolerant of duplicates (RFC 791), so drop -* only this mbuf and keep the reassembly entry intact rather than -* treating it as an error. Fragments overlapping an existing one with -* different bounds are not handled here. +* Scan the fragments already collected for this datagram before +* storing the new one. The stored set is kept free of duplicates and +* overlaps, so a single pass is sufficient. */ for (i =0 ; i != fp->last_idx; i++) { -if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && - fp->frags[i].len == len) { +if (fp->frags[i].mb ==NULL ) +continue ; + +/* +* Exact duplicate: carries no new data. Reassembly tolerates +* duplicates (RFC 791), so drop only this mbuf and keep the +* entry. +*/ +if (fp->frags[i].ofs == ofs && fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + +/* +* Overlap with an existing fragment. Per RFC 8200 section 4.5 +* (and RFC 5722) the datagram must be discarded; the same is +* applied to IPv4. Free all collected fragments, drop this one, +* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && fp->frags[i].ofs < ofs + len) { +IP_FRAG_LOG (DEBUG , +"%s:%d overlap ofs: %u len: %u\n" +"fragment: %p ofs: %u len %u\n\n" , + __func__, __LINE__, ofs, len, + fp, fp->frags[i].ofs, fp->frags[i].len); +ip_frag_free (fp, dr); +ip_frag_key_invalidate (&fp->key);IP_FRAG_MBUF2DR (dr, mb);lib/ip_frag/ip_frag_internal.c +0
-1return NULL ; } --2.53.0
PATCH v2 3/8 ip_frag: include protocol in IPv4 reassembly key
In reply to Stephen HemmingerDPDK IPv4 reassembly code was not following RFC 791 section 3.2 which says:
The internet identification field (ID) is used together with the source and destination address, and the protocol fields, to identify datagram fragments for reassembly.
Omitting the protocol means two datagrams between the
same pair of hosts that share an IP id but carry different protocols (for example UDP and ICMP) are merged into a single reassembly context, producing a corrupted datagram.
Fold the protocol into the unused upper bits of the 32-bit id field of the key. The IPv4 identification is 16 bits and occupies the low half, so the protocol can be carried in the upper bits without changing the key layout, the key comparison or the hash.
--- lib/ip_frag/rte_ipv4_reassembly.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/ip_frag/rte_ipv4_reassembly.c +7 -1
@@ -111,9 +111,15 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, ip_ofs = (uint16_t )(flag_offset &RTE_IPV4_HDR_OFFSET_MASK ); ip_flag = (uint16_t )(flag_offset &RTE_IPV4_HDR_MF_FLAG ); +/* +* RFC 791 requires using: source, destination, identifier field and protocol +*/ +/* use first 8 bytes only */ memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,8 ); - key.id = ip_hdr->packet_id; + +/* packet_id is 16 bits and proto id is 8 bits */ + key.id = ((uint32_t ) ip_hdr->next_proto_id <<16 ) | ip_hdr->packet_id; key.key_len =IPV4_KEYLEN ; ip_ofs *=RTE_IPV4_HDR_OFFSET_UNITS ;
Signature · 1 line
2.53.0
PATCH v2 4/8 ip_frag: drop IPv6 fragments with per-fragment headers
In reply to Stephen HemmingerIPv6 reassembly assumes the fragment header directly follows the IPv6 header. ipv6_frag_reassemble() patches the next-header field and removes the fragment header at a fixed offset, so a fragment with per-fragment extension headers before the fragment header reassembles to a corrupt datagram.
Drop the fragment when its fragment header does not directly follow the IPv6 header. Headers after the fragment header are payload and are unaffected.
RFC 8200 permits discarding packets with extension headers out of the recommended order, and RFC 9099 recommends dropping non-conforming fragmented packets.
--- lib/ip_frag/rte_ipv6_reassembly.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
lib/ip_frag/rte_ipv6_reassembly.c +22 -0
@@ -180,6 +180,28 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,return NULL ; } +/* +* Only a fragment header directly following the IPv6 header is supported. +* Per-fragment (unfragmentable) extension headers placed +* before the fragment header are not handled: ipv6_frag_reassemble() +* patches the IPv6 header's next-header field and removes the fragment +* header assuming it sits immediately after the IPv6 header, so such a +* fragment would be reassembled into a corrupt datagram. Drop it. +* +* Extension headers after the fragment header (destination options, +* AH, ESP, upper-layer) are part of the fragmentable payload and are +* reassembled as opaque bytes, so they are not affected. The test uses +* the fragment header's position rather than l3_len so that callers +* which include later headers in l3_len are not rejected. +*/ +if ((uintptr_t )frag_hdr != (uintptr_t )(ip_hdr +1 )) { +IP_FRAG_LOG (DEBUG , +"%s:%d: drop fragment with header before frag header, offset %zu\n" , + __func__, __LINE__, (uintptr_t )frag_hdr - (uintptr_t )ip_hdr); +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } +if (unlikely (trim >0 ))rte_pktmbuf_trim (mb, trim);
Signature · 1 line
2.53.0
PATCH v2 5/8 ip_frag: reject oversized reassembled datagrams
In reply to Stephen HemmingerThe reassembled total length of a packet must not exceed 65535. A fragment with a high offset could drive the sum past that, causing silent truncation since IP payload_len/total_length is 16 bits.
When reassembling a packet the total length should not be allowed to exceed 65535. A fragment with high offset could drive the sum past that, causing silent truncation.
A valid datagram never exceeds 65535 bytes, so reject any fragment whose resulting length would exceed that.
Fold the test into the existing zero-length check.
--- lib/ip_frag/rte_ipv4_reassembly.c | 9 +++++++-- lib/ip_frag/rte_ipv6_reassembly.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
lib/ip_frag/rte_ipv4_reassembly.c +7 -2
@@ -136,8 +136,13 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled datagram exceed the maximum IPv4 size. The +* total_length field is 16 bits, so otherwise it is silently +* truncated while the mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len + mb->l3_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
lib/ip_frag/rte_ipv6_reassembly.c +7 -2
@@ -174,8 +174,13 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled payload exceed 65535 bytes. The payload_len +* field is 16 bits, so otherwise it is silently truncated while the +* mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
Signature · 1 line
2.53.0
PATCH v2 6/8 app/test: add test for IP reassembly
In reply to Stephen HemmingerThere was no functional test for IPv4/IPv6 reassembly, only a performance test. Add a new test modeled on the Linux kernel selftest tools/testing/selftests/net/ip_defrag.c. This is new code so no license conflict.
Test covers:
size and fragment-size sweep across in-order, reverse, odd/even and block delivery orders with byte-exact payload validation; minimum 8-byte fragments; the fragment-count limit;
timeout of incomplete datagrams;
and the duplicate, overlap, extension-header and oversized-fragment cases fixed earlier in this series.
The reassembled packet is checked with rte_mbuf_check() to catch malformed segment chains in addition to wrong content.
--- app/test/meson.build | 1 + app/test/test_reassembly.c | 675 +++++++++++++++++++++++++++++++++++++ 2 files changed, 676 insertions(+) create mode 100644 app/test/test_reassembly.c
app/test/meson.build +1 -0
@@ -160,6 +160,7 @@ source_file_deps = { 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'], 'test_rcu_qsbr_perf.c': ['rcu', 'hash'], + 'test_reassembly.c': ['net', 'ip_frag'], 'test_reassembly_perf.c': ['net', 'ip_frag'], 'test_reciprocal_division.c': [], 'test_reciprocal_division_perf.c': [],
app/test/test_reassembly.c new file +675 -0
675 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 7/8 ip_frag: remove use of rte_memcpy
In reply to Stephen HemmingerReplace rte_memcpy with assignment or plain memcpy to get more static checking.
--- lib/ip_frag/rte_ipv6_fragmentation.c | 3 +-- lib/ip_frag/rte_ipv6_reassembly.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-)
lib/ip_frag/rte_ipv6_fragmentation.c +1 -2
@@ -6,7 +6,6 @@#include <errno.h> #include <eal_export.h> -#include <rte_memcpy.h> #include "ip_frag_common.h"
@@ -24,7 +23,7 @@ __fill_ipv6hdr_frag(struct rte_ipv6_hdr *dst, {struct rte_ipv6_fragment_ext *fh; -rte_memcpy (dst, src,sizeof (*dst)); + *dst = *src; dst->payload_len =rte_cpu_to_be_16 (len); dst->proto =IPPROTO_FRAGMENT ;
lib/ip_frag/rte_ipv6_reassembly.c +2 -3
@@ -5,7 +5,6 @@#include <stddef.h> #include <eal_export.h> -#include <rte_memcpy.h> #include "ip_frag_common.h"
@@ -145,8 +144,8 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,int32_t ip_len;int32_t trim; -rte_memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,16 ); -rte_memcpy (&key.src_dst[2 ], &ip_hdr->dst_addr,16 ); +memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,16 ); +memcpy (&key.src_dst[2 ], &ip_hdr->dst_addr,16 ); key.id = frag_hdr->id; key.key_len =IPV6_KEYLEN ;
Signature · 1 line
2.53.0
PATCH v2 8/8 doc: add release note about ip_frag changes
In reply to Stephen HemmingerThe changes to ip_frag might impact some conformance or performance tests.
--- doc/guides/rel_notes/release_26_07.rst | 6 ++++++ 1 file changed, 6 insertions(+)
doc/guides/rel_notes/release_26_07.rst +6 -0
@@ -241,6 +241,12 @@ API Changes - ``rte_pmd_mlx5_enable_steering`` - ``rte_pmd_mlx5_disable_steering`` +* **ip_frag: hardened IP reassembly against malformed fragments.** + + Duplicate, overlapping, oversized, and (for IPv6) per-fragment-header + fragments are now rejected rather than mis-reassembled. This changes which + fragment streams reassemble and may affect throughput. + ABI Changes -----------
Signature · 1 line
2.53.0
Re: [PATCH v2 8/8] doc: add release note about ip_frag changes
Quoted 5 lines · On Tue, 30 Jun 2026 08:36:20 -0700 Stephen Hemminger…
The changes to
ip_fragmight impact some conformance or performance tests.Signed-off-by Stephen Hemminger <[email protected]>---
Recheck-request: github-robot: build
RE: [PATCH v2 8/8] doc: add release note about ip_frag changes
In reply to Stephen HemmingerQuoted 16 lines
The changes to
ip_fragmight impact some conformance or performance tests.Signed-off-by Stephen Hemminger <[email protected]>--- doc/guides/rel_notes/release_26_07.rst | 6 ++++++ 1 file changed, 6 insertions(+)doc/guides/rel_notes/release_26_07.rst +0
-0
doc/guides/rel_notes/release_26_07.rst API Changes · line 248
Quoted 8 lines
doc/guides/rel_notes/release_26_07.rst +5
-0@@ -241,6 +241,12 @@ API Changes - ``rte_pmd_mlx5_enable_steering`` - ``rte_pmd_mlx5_disable_steering`` +* **ip_frag: hardened IP reassembly against malformed fragments.** + + Duplicate, overlapping, oversized, and (for IPv6) per-fragment-header + fragments are now rejected rather than mis-reassembled. This changes which + fragment streams reassemble and may affect throughput.
That doesn't look entirely correct:
Current implementation doesn't allow both duplicate or overlapping fragments either, though it postpones it's detection till reassembly stage.
Might be something like that:
**ip_frag: hardened IP reassembly against malformed fragments.**
* Tolerate packets with duplicate fragments,
* Determine duplicate overlapping and oversized fragments at arrival. That change can cause multiple extra scans over already received fragments and might affect overall system throughput.
?
Quoted 6 lines
doc/guides/rel_notes/release_26_07.rst +1
-1+ ABI Changes ----------- --2.53.0
v3 cover ip_frag: fix reassembly defects and add test
In reply to Stephen HemmingerThe IP reassembly library tracks only a running byte total and reserved slots for the first and last fragments, with no coverage map. As a result it mishandles duplicate, overlapping, oversized, and misheadered fragments, and the IPv4 key is missing a field RFC 791 requires. There was also no functional test to catch any of it.
These came out of reviewing a duplicate-fragment report on the list.
Patches 1 and 2 are interdependent: the overlap discard relies on the duplicate handling so an exact duplicate is dropped on its own rather than discarding the whole datagram. The rest are independent.
Patch 6 adds a functional test modeled on the Linux selftest ip_defrag.c. It passes on this series; with any single fix reverted the matching case fails.
v3 - drop stable from one patch and reword release note
Stephen Hemminger (8):
ip_frag: tolerate duplicate fragments
ip_frag: discard datagrams with overlapping fragments
ip_frag: include protocol in IPv4 reassembly key
ip_frag: drop IPv6 fragments with per-fragment headers
ip_frag: reject oversized reassembled datagrams app/test: add test for IP reassembly
ip_frag: remove use of rte_memcpy
doc: add release note about ip_frag changes
app/test/meson.build | 1 + app/test/test_reassembly.c | 675 +++++++++++++++++++++++++ doc/guides/rel_notes/release_26_07.rst | 10 + lib/ip_frag/ip_frag_internal.c | 40 +- lib/ip_frag/rte_ipv4_reassembly.c | 17 +- lib/ip_frag/rte_ipv6_fragmentation.c | 3 +- lib/ip_frag/rte_ipv6_reassembly.c | 36 +- 7 files changed, 771 insertions(+), 11 deletions(-) create mode 100644 app/test/test_reassembly.c
Signature · 1 line
2.53.0
PATCH v3 1/8 ip_frag: tolerate duplicate fragments
The reassembly code tracked only a running byte total and reserved slots for the first and last fragments, with no check for a fragment duplicating data already received. A single duplicate could destroy a recoverable datagram:
- a duplicate first or last fragment collided with the reserved slot and sent the whole entry down the error path, freeing every collected fragment;
- a duplicate intermediate fragment was appended to a new slot, inflating frag_size past total_size so reassembly never completed.
RFC 791 reassembly tolerates duplicates: a fragment covering bytes already present carries no new information. Check for an exact duplicate (stored fragment with the same offset and length) and drop only that mbuf, before frag_size is updated, leaving the entry's accounting unchanged.
Overlapping fragments with differing bounds are a separate issue addressed in the next patch.
--- lib/ip_frag/ip_frag_internal.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
lib/ip_frag/ip_frag_internal.c +17 -1
@@ -89,7 +89,23 @@ struct rte_mbuf * ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr, struct rte_mbuf *mb, uint16_t ofs, uint16_t len, uint16_t more_frags) { - uint32_t idx; + uint32_t i, idx; + +/* +* Discard an exact duplicate fragment. If a previously stored fragment +* already covers the same offset and length, this fragment carries no +* new data. Reassembly is tolerant of duplicates (RFC 791), so drop +* only this mbuf and keep the reassembly entry intact rather than +* treating it as an error. Fragments overlapping an existing one with +* different bounds are not handled here. +*/ +for (i =0 ; i != fp->last_idx; i++) { +if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && + fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + } fp->frag_size += len;
Signature · 1 line
2.53.0
PATCH v3 2/8 ip_frag: discard datagrams with overlapping fragments
In reply to Stephen HemmingerExisting code does not handle overlapping fragments.
RFC 8200 (IPv6) requires that on overlap all reassembly is abandoned and all received fragments are dropped. RFC 791 (IPv4) originally called for trimming and rewriting, but Linux discards for IPv4 as well, since overlap has no legitimate use and is a known attack vector.
Depends on the duplicate-tolerance change so that an exact duplicate is dropped on its own rather than discarding the whole datagram.
--- lib/ip_frag/ip_frag_internal.c | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-)
lib/ip_frag/ip_frag_internal.c +30 -8
@@ -92,16 +92,38 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,uint32_t i, idx;/* -* Discard an exact duplicate fragment. If a previously stored fragment -* already covers the same offset and length, this fragment carries no -* new data. Reassembly is tolerant of duplicates (RFC 791), so drop -* only this mbuf and keep the reassembly entry intact rather than -* treating it as an error. Fragments overlapping an existing one with -* different bounds are not handled here. +* Scan the fragments already collected for this datagram before +* storing the new one. The stored set is kept free of duplicates and +* overlaps, so a single pass is sufficient. */ for (i =0 ; i != fp->last_idx; i++) { -if (fp->frags[i].mb !=NULL && fp->frags[i].ofs == ofs && - fp->frags[i].len == len) { +if (fp->frags[i].mb ==NULL ) +continue ; + +/* +* Exact duplicate: carries no new data. Reassembly tolerates +* duplicates (RFC 791), so drop only this mbuf and keep the +* entry. +*/ +if (fp->frags[i].ofs == ofs && fp->frags[i].len == len) { +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } + +/* +* Overlap with an existing fragment. Per RFC 8200 section 4.5 +* (and RFC 5722) the datagram must be discarded; the same is +* applied to IPv4. Free all collected fragments, drop this one, +* and invalidate the entry. +*/ +if (ofs < fp->frags[i].ofs + fp->frags[i].len && fp->frags[i].ofs < ofs + len) { +IP_FRAG_LOG (DEBUG , +"%s:%d overlap ofs: %u len: %u\n" +"fragment: %p ofs: %u len %u\n\n" , + __func__, __LINE__, ofs, len, + fp, fp->frags[i].ofs, fp->frags[i].len); +ip_frag_free (fp, dr); +ip_frag_key_invalidate (&fp->key);IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
Signature · 1 line
2.53.0
PATCH v3 3/8 ip_frag: include protocol in IPv4 reassembly key
In reply to Stephen HemmingerDPDK IPv4 reassembly code was not following RFC 791 section 3.2 which says:
The internet identification field (ID) is used together with the source and destination address, and the protocol fields, to identify datagram fragments for reassembly.
Omitting the protocol means two datagrams between the
same pair of hosts that share an IP id but carry different protocols (for example UDP and ICMP) are merged into a single reassembly context, producing a corrupted datagram.
Fold the protocol into the unused upper bits of the 32-bit id field of the key. The IPv4 identification is 16 bits and occupies the low half, so the protocol can be carried in the upper bits without changing the key layout, the key comparison or the hash.
--- lib/ip_frag/rte_ipv4_reassembly.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/ip_frag/rte_ipv4_reassembly.c +7 -1
@@ -111,9 +111,15 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, ip_ofs = (uint16_t )(flag_offset &RTE_IPV4_HDR_OFFSET_MASK ); ip_flag = (uint16_t )(flag_offset &RTE_IPV4_HDR_MF_FLAG ); +/* +* RFC 791 requires using: source, destination, identifier field and protocol +*/ +/* use first 8 bytes only */ memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,8 ); - key.id = ip_hdr->packet_id; + +/* packet_id is 16 bits and proto id is 8 bits */ + key.id = ((uint32_t ) ip_hdr->next_proto_id <<16 ) | ip_hdr->packet_id; key.key_len =IPV4_KEYLEN ; ip_ofs *=RTE_IPV4_HDR_OFFSET_UNITS ;
Signature · 1 line
2.53.0
PATCH v3 4/8 ip_frag: drop IPv6 fragments with per-fragment headers
In reply to Stephen HemmingerIPv6 reassembly assumes the fragment header directly follows the IPv6 header. ipv6_frag_reassemble() patches the next-header field and removes the fragment header at a fixed offset, so a fragment with per-fragment extension headers before the fragment header reassembles to a corrupt datagram.
Drop the fragment when its fragment header does not directly follow the IPv6 header. Headers after the fragment header are payload and are unaffected.
RFC 8200 permits discarding packets with extension headers out of the recommended order, and RFC 9099 recommends dropping non-conforming fragmented packets.
--- lib/ip_frag/rte_ipv6_reassembly.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
lib/ip_frag/rte_ipv6_reassembly.c +22 -0
@@ -180,6 +180,28 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,return NULL ; } +/* +* Only a fragment header directly following the IPv6 header is supported. +* Per-fragment (unfragmentable) extension headers placed +* before the fragment header are not handled: ipv6_frag_reassemble() +* patches the IPv6 header's next-header field and removes the fragment +* header assuming it sits immediately after the IPv6 header, so such a +* fragment would be reassembled into a corrupt datagram. Drop it. +* +* Extension headers after the fragment header (destination options, +* AH, ESP, upper-layer) are part of the fragmentable payload and are +* reassembled as opaque bytes, so they are not affected. The test uses +* the fragment header's position rather than l3_len so that callers +* which include later headers in l3_len are not rejected. +*/ +if ((uintptr_t )frag_hdr != (uintptr_t )(ip_hdr +1 )) { +IP_FRAG_LOG (DEBUG , +"%s:%d: drop fragment with header before frag header, offset %zu\n" , + __func__, __LINE__, (uintptr_t )frag_hdr - (uintptr_t )ip_hdr); +IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } +if (unlikely (trim >0 ))rte_pktmbuf_trim (mb, trim);
Signature · 1 line
2.53.0
RE: [PATCH v3 4/8] ip_frag: drop IPv6 fragments with per-fragment headers
Quoted 53 lines
IPv6 reassembly assumes the fragment header directly follows the IPv6 header.
ipv6_frag_reassemble()patches the next-header field and removes the fragment header at a fixed offset, so a fragment with per-fragment extension headers before the fragment header reassembles to a corrupt datagram.Drop the fragment when its fragment header does not directly follow the IPv6 header. Headers after the fragment header are payload and are unaffected.
RFC 8200 permits discarding packets with extension headers out of the recommended order, and RFC 9099 recommends dropping non-conforming fragmented packets.
Fixes 4f1a8f633862 ("ip_frag: add IPv6 reassembly")Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/rte_ipv6_reassembly.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)lib/ip_frag/rte_ipv6_reassembly.c +2
-0@@ -180,6 +180,28 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, return NULL; } +/* +* Only a fragment header directly following the IPv6 header is supported.
lib/ip_frag/rte_ipv6_reassembly.c +15
-0+* Per-fragment (unfragmentable) extension headers placed +* before the fragment header are not handled: ipv6_frag_reassemble() +* patches the IPv6 header's next-header field and removes the fragment +* header assuming it sits immediately after the IPv6 header, so such a +* fragment would be reassembled into a corrupt datagram. Drop it. +* +* Extension headers after the fragment header (destination options, +* AH, ESP, upper-layer) are part of the fragmentable payload and are +* reassembled as opaque bytes, so they are not affected. The test uses +* the fragment header's position rather than l3_len so that callers +* which include later headers in l3_len are not rejected. +*/ +if ((uintptr_t )frag_hdr != (uintptr_t )(ip_hdr +1 )) { + IP_FRAG_LOG(DEBUG, + "%s:%d: drop fragment with header before frag header,offset %zu\n",
lib/ip_frag/rte_ipv6_reassembly.c +1
-0+ __func__, __LINE__, (uintptr_t)frag_hdr -(uintptr_t)ip_hdr);
lib/ip_frag/rte_ipv6_reassembly.c rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
Quoted 8 lines
lib/ip_frag/rte_ipv6_reassembly.c +4
-1+IP_FRAG_MBUF2DR (dr, mb); +return NULL ; + } +if (unlikely (trim >0 ))rte_pktmbuf_trim (mb, trim); --
Quoted 1 line
2.53.0
PATCH v3 5/8 ip_frag: reject oversized reassembled datagrams
In reply to Stephen HemmingerThe reassembled total length of a packet must not exceed 65535. A fragment with a high offset could drive the sum past that, causing silent truncation since IP payload_len/total_length is 16 bits.
When reassembling a packet the total length should not be allowed to exceed 65535. A fragment with high offset could drive the sum past that, causing silent truncation.
A valid datagram never exceeds 65535 bytes, so reject any fragment whose resulting length would exceed that.
Fold the test into the existing zero-length check.
--- lib/ip_frag/rte_ipv4_reassembly.c | 9 +++++++-- lib/ip_frag/rte_ipv6_reassembly.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
lib/ip_frag/rte_ipv4_reassembly.c +7 -2
@@ -136,8 +136,13 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled datagram exceed the maximum IPv4 size. The +* total_length field is 16 bits, so otherwise it is silently +* truncated while the mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len + mb->l3_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
lib/ip_frag/rte_ipv6_reassembly.c +7 -2
@@ -174,8 +174,13 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); -/* check that fragment length is greater then zero. */ -if (ip_len <=0 ) { +/* +* Drop fragments with no payload, and any fragment whose end would +* make the reassembled payload exceed 65535 bytes. The payload_len +* field is 16 bits, so otherwise it is silently truncated while the +* mbuf still holds the full length. +*/ +if (ip_len <=0 || ip_ofs + ip_len >UINT16_MAX ) {IP_FRAG_MBUF2DR (dr, mb);return NULL ; }
Signature · 1 line
2.53.0
PATCH v3 6/8 app/test: add test for IP reassembly
In reply to Stephen HemmingerThere was no functional test for IPv4/IPv6 reassembly, only a performance test. Add a new test modeled on the Linux kernel selftest tools/testing/selftests/net/ip_defrag.c. This is new code so no license conflict.
Test covers:
size and fragment-size sweep across in-order, reverse, odd/even and block delivery orders with byte-exact payload validation; minimum 8-byte fragments; the fragment-count limit;
timeout of incomplete datagrams;
and the duplicate, overlap, extension-header and oversized-fragment cases fixed earlier in this series.
The reassembled packet is checked with rte_mbuf_check() to catch malformed segment chains in addition to wrong content.
--- app/test/meson.build | 1 + app/test/test_reassembly.c | 675 +++++++++++++++++++++++++++++++++++++ 2 files changed, 676 insertions(+) create mode 100644 app/test/test_reassembly.c
app/test/meson.build +1 -0
@@ -160,6 +160,7 @@ source_file_deps = { 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'], 'test_rcu_qsbr_perf.c': ['rcu', 'hash'], + 'test_reassembly.c': ['net', 'ip_frag'], 'test_reassembly_perf.c': ['net', 'ip_frag'], 'test_reciprocal_division.c': [], 'test_reciprocal_division_perf.c': [],
app/test/test_reassembly.c new file +675 -0
675 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v3 7/8 ip_frag: remove use of rte_memcpy
In reply to Stephen HemmingerReplace rte_memcpy with assignment or plain memcpy to get more static checking.
--- lib/ip_frag/rte_ipv6_fragmentation.c | 3 +-- lib/ip_frag/rte_ipv6_reassembly.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-)
lib/ip_frag/rte_ipv6_fragmentation.c +1 -2
@@ -6,7 +6,6 @@#include <errno.h> #include <eal_export.h> -#include <rte_memcpy.h> #include "ip_frag_common.h"
@@ -24,7 +23,7 @@ __fill_ipv6hdr_frag(struct rte_ipv6_hdr *dst, {struct rte_ipv6_fragment_ext *fh; -rte_memcpy (dst, src,sizeof (*dst)); + *dst = *src; dst->payload_len =rte_cpu_to_be_16 (len); dst->proto =IPPROTO_FRAGMENT ;
lib/ip_frag/rte_ipv6_reassembly.c +2 -3
@@ -5,7 +5,6 @@#include <stddef.h> #include <eal_export.h> -#include <rte_memcpy.h> #include "ip_frag_common.h"
@@ -145,8 +144,8 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,int32_t ip_len;int32_t trim; -rte_memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,16 ); -rte_memcpy (&key.src_dst[2 ], &ip_hdr->dst_addr,16 ); +memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,16 ); +memcpy (&key.src_dst[2 ], &ip_hdr->dst_addr,16 ); key.id = frag_hdr->id; key.key_len =IPV6_KEYLEN ;
Signature · 1 line
2.53.0
RE: [PATCH v3 7/8] ip_frag: remove use of rte_memcpy
Quoted 56 lines
Replace
rte_memcpywith assignment or plain memcpy to get more static checking.Signed-off-by Stephen Hemminger <[email protected]>--- lib/ip_frag/rte_ipv6_fragmentation.c | 3 +-- lib/ip_frag/rte_ipv6_reassembly.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-)lib/ip_frag/rte_ipv6_fragmentation.c +1
-2@@ -6,7 +6,6 @@#include <errno.h> #include <eal_export.h> -#include <rte_memcpy.h> #include "ip_frag_common.h" @@ -24,7 +23,7 @@ __fill_ipv6hdr_frag(struct rte_ipv6_hdr *dst, {struct rte_ipv6_fragment_ext *fh; -rte_memcpy (dst, src,sizeof (*dst)); + *dst = *src; dst->payload_len =rte_cpu_to_be_16 (len); dst->proto =IPPROTO_FRAGMENT ;lib/ip_frag/rte_ipv6_reassembly.c +2
-3@@ -5,7 +5,6 @@#include <stddef.h> #include <eal_export.h> -#include <rte_memcpy.h> #include "ip_frag_common.h" @@ -145,8 +144,8 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, int32_t ip_len;int32_t trim; -rte_memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,16 ); -rte_memcpy (&key.src_dst[2 ], &ip_hdr->dst_addr,16 ); +memcpy (&key.src_dst[0 ], &ip_hdr->src_addr,16 ); +memcpy (&key.src_dst[2 ], &ip_hdr->dst_addr,16 ); key.id = frag_hdr->id;
Quoted 2 lines
key.key_len =
IPV6_KEYLEN;
--
Quoted 1 line
2.53.0
PATCH v3 8/8 doc: add release note about ip_frag changes
In reply to Stephen HemmingerThese changes maybe surprising and need some documentation.
--- doc/guides/rel_notes/release_26_07.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
doc/guides/rel_notes/release_26_07.rst +10 -0
@@ -241,6 +241,16 @@ API Changes - ``rte_pmd_mlx5_enable_steering`` - ``rte_pmd_mlx5_disable_steering`` +* **ip_frag: changed handling of malformed fragments.** + + - Duplicate fragments are tolerated instead of failing reassembly. + - Overlapping fragments are rejected on arrival rather than during reassembly. + - Oversized fragments (reassembled length over 65535) are rejected. + - For IPv6, fragments with per-fragment extension headers are rejected. + + Overlap and oversize are now detected on arrival, which adds a scan of the + already received fragments per fragment and may affect throughput. + ABI Changes -----------
Signature · 1 line
2.53.0
RE: [PATCH v3 8/8] doc: add release note about ip_frag changes
Quoted 22 lines
These changes maybe surprising and need some documentation.
Signed-off-by Stephen Hemminger <[email protected]>--- doc/guides/rel_notes/release_26_07.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)doc/guides/rel_notes/release_26_07.rst +4
-0@@ -241,6 +241,16 @@ API Changes - ``rte_pmd_mlx5_enable_steering`` - ``rte_pmd_mlx5_disable_steering`` +* **ip_frag: changed handling of malformed fragments.** + + - Duplicate fragments are tolerated instead of failing reassembly. + - Overlapping fragments are rejected on arrival rather than during reassembly.
doc/guides/rel_notes/release_26_07.rst API Changes
Quoted 10 lines
doc/guides/rel_notes/release_26_07.rst +6
-1+ - Oversized fragments (reassembled length over 65535) are rejected. + - For IPv6, fragments with per-fragment extension headers are rejected. + + Overlap and oversize are now detected on arrival, which adds a scan of the + already received fragments per fragment and may affect throughput. + ABI Changes ----------- --
Quoted 1 line
2.53.0
01/07/2026 18:20, Stephen Hemminger:
Quoted 18 lines
The IP reassembly library tracks only a running byte total and reserved slots for the first and last fragments, with no coverage map. As a result it mishandles duplicate, overlapping, oversized, and misheadered fragments, and the IPv4 key is missing a field RFC 791 requires. There was also no functional test to catch any of it.
These came out of reviewing a duplicate-fragment report on the list.
Patches 1 and 2 are interdependent: the overlap discard relies on the duplicate handling so an exact duplicate is dropped on its own rather than discarding the whole datagram. The rest are independent.
Patch 6 adds a functional test modeled on the Linux selftest
ip_defrag.c. It passes on this series; with any single fix reverted the matching case fails.v3 - drop stable from one patch and reword release note
Quoted 9 lines
Stephen Hemminger (8):
ip_frag: tolerate duplicate fragments
ip_frag: discard datagrams with overlapping fragments
ip_frag: include protocol in IPv4 reassembly key
ip_frag: drop IPv6 fragments with per-fragment headers
ip_frag: reject oversized reassembled datagrams app/test: add test for IP reassembly
ip_frag: remove use ofrte_memcpy
doc: add release note aboutip_fragchanges
doc squashed in relevant commits atomically,
applied, thanks.