net: clear IP defragmentation state after returning a complete packet
v2 cover net: clear IP defragmentation state after returning a complete packet
This series fixes incomplete clearing of the IP reassembly state (CONFIG_IP_DEFRAG): the static counters and hole list are not reset after a reassembled datagram is handed back to the caller. A duplicated final fragment is then processed against stale state, mis-parsing the delivered payload as the hole list, which can lead to re-delivery or out-of-bounds accesses.
Patch 1 contains the fix and the full rationale; patch 2 adds a unit test (run via "ut dm") that reproduces the duplicate-final-fragment case and guards against regressions.
---
Changes in v2:
- correct spelling in commit msg "mistakingly" -> "mistakenly"
- net.c: fix block comment formatting
- add regression test (net_defrag.c)
- Link to v1: https://lore.kernel.org/all/[email protected]
To: Ben Warren <[email protected]>
To: Alessandro Rubini <[email protected]>
To: [email protected]
Cc: Jerome Forissier <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Max Merchel <[email protected]>
Cc: Yuya Hamamachi <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mateusz Furdyna <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Alessandro Rubini <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Dinesh Maniyam <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Svyatoslav Ryhel <[email protected]>
Cc: Heiko Schocher <[email protected]>
Cc: "Lucien.Jheng" <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
---
Mateusz Furdyna (2):
net: clear IP defragmentation state after returning a complete packet
test: net: add IP defragmentation duplicate-fragment regression test
net/net.c | 9 ++++++ test/dm/Makefile | 1 + test/dm/net_defrag.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+)
---
base-commit: 30b77f6aa146c96b831cb4ece038130b655b6a41
change-id: 20260530-ip_defrag-130c345dd9db
Best regards,
Signature · 1 line
Mateusz Furdyna <[email protected]>
PATCH v2 1/2 net: clear IP defragmentation state after returning a complete packet
During the IP defragmentation process, after the reassembly is finished with the last packet arriving with MF=0, the reassembly state wrt. static counters is not cleared. In case this last arriving packet with MF=0 gets duplicated, payload bytes are mistakenly treated as hole data.
A malicious actor who can deliver fragmented IP traffic to a U-Boot instance with CONFIG_IP_DEFRAG=y can corrupt memory via out-of-bound writes and redirect control flow into attacker-supplied payload bytes that already sit in pkt_buff[].
Publicly available AI models are able to generate a reproducer based on the provided information.
Fix: once the assembled packet has been handed back to the caller, mark the reassembly state empty so that any further fragment (duplicate, replay, or a brand-new datagram that happens to reuse the ip_id) goes through the normal re-init path and rebuilds a clean hole list instead of dereferencing payload bytes as struct hole.
--- net/net.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/net.c +9 -0
@@ -1103,6 +1103,15 @@ static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp) *lenp = total_len +IP_HDR_SIZE ; localip->ip_len =htons (*lenp); + +/* +* Mark the reassembly state empty so that any further +* fragment goes through the normal re-init path and +* rebuilds a clean hole list +*/ + total_len =0 ; + first_hole =0 ; +return localip; }
Signature · 1 line
2.53.0
PATCH v2 2/2 test: net: add IP defragmentation duplicate-fragment regression test
In reply to Mateusz FurdynaAdd a unit test for the IP datagram reassembler (CONFIG_IP_DEFRAG) that covers the duplicate-last-fragment scenario.
Without the fix the last fragment will re-trigger datagram delivery, increasing udp_rx_count to 2 and effectively failing the test; with it applied the test passes with udp_rx_count == 1.
--- test/dm/Makefile | 1 + test/dm/net_defrag.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)
test/dm/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_MULTIPLEXER) += mux-emul.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.o obj-y += fdtdec.o obj-$(CONFIG_MTD_RAW_NAND) += nand.o +obj-$(CONFIG_IP_DEFRAG) += net_defrag.o obj-$(CONFIG_UT_DM) += nop.o obj-y += ofnode.o obj-y += ofread.o
test/dm/net_defrag.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 2/2] test: net: add IP defragmentation duplicate-fragment regression test
Hi Mateusz,
Quoted 9 lines · Mateusz Furdyna
test: net: add IP defragmentation duplicate-fragment regression test
Add a unit test for the IP datagram reassembler (
CONFIG_IP_DEFRAG) that covers the duplicate-last-fragment scenario.Without the fix the last fragment will re-trigger datagram delivery, increasing
udp_rx_countto 2 and effectively failing the test; with it applied the test passes withudp_rx_count== 1.
Quoted 5 lines
Signed-off-by Mateusz Furdyna <[email protected]>test/dm/Makefile | 1 +
test/dm/net_defrag.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)
test/dm/net_defrag.c line 1
Quoted 3 lines
test/dm/net_defrag.c +1
-0@@ -0,0 +1,82 @@ +DM_TEST (dm_test_net_ip_defrag_dup_last,0 );
Just to check, does this test actually use driver model?
Regards,
Simon
Re: [PATCH v2 2/2] test: net: add IP defragmentation duplicate-fragment regression test
Quoted 18 lines · Simon Glass
Hi Mateusz,
Quoted 9 lines · Mateusz Furdyna
test: net: add IP defragmentation duplicate-fragment regression test
Add a unit test for the IP datagram reassembler (
CONFIG_IP_DEFRAG) that covers the duplicate-last-fragment scenario.Without the fix the last fragment will re-trigger datagram delivery, increasing
udp_rx_countto 2 and effectively failing the test; with it applied the test passes withudp_rx_count== 1.Quoted 5 lines
Signed-off-by Mateusz Furdyna <[email protected]>test/dm/Makefile | 1 +
test/dm/net_defrag.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)
Quoted 7 lines
Reviewed-by Simon Glass <[email protected]>test/dm/net_defrag.c line 1
Quoted 3 lines
test/dm/net_defrag.c +1
-0@@ -0,0 +1,82 @@ +DM_TEST (dm_test_net_ip_defrag_dup_last,0 );Just to check, does this test actually use driver model?
No, it doesn't. It drives net_process_received_packet() directly, nothing is actually using DM in the test path.
I'd followed the existing precedent in test/dm/eth.c (dm_test_string_to_ip6(), which similarly doesn't exercise DM), which is what prompted my earlier question about whether "ut dm" was the right home for this (and stopped me for looking further, my bad).
I'm happy to move it to the lib suite, for instance. Since Jerome has already queued this v2 for net/master: should I create v3, a follow-up on top of what's queued or just leave it as-is in DM?
Quoted 3 lines
Regards,
Simon
Best Regards,
Mateusz
Re: [PATCH v2 2/2] test: net: add IP defragmentation duplicate-fragment regression test
Hi Mateusz,
Quoted 32 lines · Mateusz Furdyna (Nokia)
Quoted 18 lines · Simon Glass
Hi Mateusz,
Quoted 9 lines · Mateusz Furdyna
test: net: add IP defragmentation duplicate-fragment regression test
Add a unit test for the IP datagram reassembler (
CONFIG_IP_DEFRAG) that covers the duplicate-last-fragment scenario.Without the fix the last fragment will re-trigger datagram delivery, increasing
udp_rx_countto 2 and effectively failing the test; with it applied the test passes withudp_rx_count== 1.Quoted 5 lines
Signed-off-by Mateusz Furdyna <[email protected]>test/dm/Makefile | 1 +
test/dm/net_defrag.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)Quoted 7 lines
Reviewed-by Simon Glass <[email protected]>test/dm/net_defrag.c line 1
Quoted 3 lines
test/dm/net_defrag.c +1
-0@@ -0,0 +1,82 @@ +DM_TEST (dm_test_net_ip_defrag_dup_last,0 );Just to check, does this test actually use driver model?
No, it doesn't. It drives
net_process_received_packet()directly, nothing is actually using DM in the test path.
Quoted 8 lines
I'd followed the existing precedent in
test/dm/eth.c(dm_test_string_to_ip6(), which similarly doesn't exercise DM), which is what prompted my earlier question about whether "ut dm" was the right home for this (and stopped me for looking further, my bad).I'm happy to move it to the lib suite, for instance. Since Jerome has already queued this v2 for net/master: should I create v3, a follow-up on top of what's queued or just leave it as-is in DM?
Since it works, this is fine. We can always adjust it later if problems come up.
Regards,
Simon
Quoted 48 lines · Mateusz Furdyna
This series fixes incomplete clearing of the IP reassembly state (
CONFIG_IP_DEFRAG): the static counters and hole list are not reset after a reassembled datagram is handed back to the caller. A duplicated final fragment is then processed against stale state, mis-parsing the delivered payload as the hole list, which can lead to re-delivery or out-of-bounds accesses.Patch 1 contains the fix and the full rationale; patch 2 adds a unit test (run via "ut dm") that reproduces the duplicate-final-fragment case and guards against regressions.
Signed-off-by Mateusz Furdyna <[email protected]>---
Changes in v2:
- correct spelling in commit msg "mistakingly" -> "mistakenly"
-net.c: fix block comment formatting
- add regression test (net_defrag.c)
- Link to v1: https://lore.kernel.org/all/[email protected]To: Ben Warren <[email protected]>
To: Alessandro Rubini <[email protected]>
To: [email protected]
Cc: Jerome Forissier <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Max Merchel <[email protected]>
Cc: Yuya Hamamachi <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mateusz Furdyna <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Alessandro Rubini <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Dinesh Maniyam <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Svyatoslav Ryhel <[email protected]>
Cc: Heiko Schocher <[email protected]>
Cc: "Lucien.Jheng" <[email protected]>
Cc: Rasmus Villemoes <[email protected]>---
Mateusz Furdyna (2):
net: clear IP defragmentation state after returning a complete packet
test: net: add IP defragmentation duplicate-fragment regression testnet/net.c | 9 ++++++ test/dm/Makefile | 1 + test/dm/net_defrag.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+)
Quoted 8 lines
---
base-commit:30b77f6aa146c96b831cb4ece038130b655b6a41
change-id: 20260530-ip_defrag-130c345dd9dbBest regards,
Signature · 1 line
Mateusz Furdyna <[email protected]>
Series added to my net queue for master, thanks!
Signature · 1 line
Jerome