tipc: limit the memory pinned by incomplete fragment chains
Subsystems (2)
Quoted 7 lines
Subject: [PATCH] tipc: limit the memory pinned by incomplete fragment chains
Fragment chains are reassembled per link and kept in memory until the last fragment arrives. There is no limit on how much memory one in-flight chain may pin: a peer can send first and middle fragments without ever sending the last one, and every received packet resets the link silence counter, so the link never times out and the chains are never freed.
This statement is wrong. The sender always sends first, middle and last fragments to the receiver. TIPC guarantees that. The receiver is guaranteed to receive all fragments and if not (due to losses), the link will be reset. As a result, 'reasm_skb' is freed.
Quoted 23 lines
The path is: fragments arriving on a bearer are delivered by
tipc_rcv()to the link,tipc_link_input()recognizesMSG_FRAGMENTERmessages and appends them to the per-link reassembly queue throughtipc_buf_append(), which charges the accumulated size against the head buffer. The only symptom is kernel memory growing until the system runs out of it.A legitimate reassembled message can never exceed
MAX_MSG_SIZE, so drop a chain once its accumulated size exceeds twice that value.Fixes 13e9b9972fa0 ("tipc: make tipc_buf_append() more robust")Reported-by Abaci <[email protected]>Assisted-by abaci:qwen3.8-maxSigned-off-by Chuyf26 <[email protected]>---
net/tipc/link.c| 17 ++++++++++++++++-1 file changed, 16 insertions(+), 1 deletion(-)net/tipc/link.c index 6c6d8546c578..adbfdc5058cb renamed from net/tipc/link.c +0
-0100644
net/tipc/link.c static int tipc_link_input(struct tipc_link *l, struct · line 1344
Quoted 6 lines
net/tipc/link.c +1
-1@@ -1340,7 +1340,22 @@ static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb, if (tipc_buf_append(reasm_skb, &skb)) { l->stats.recv_fragmented++;tipc_data_input (l, skb, inputq); - } else if (!*reasm_skb && !link_is_bc_rcvlink(l)) { + } else if (*reasm_skb) {
This breaks existing condition. See sashiko's findings:
https://sashiko.dev/#/patchset/20260818162631.BkZArZv-Xe3-m6YWgH4d-yyQty3HogfTBj93Zh1Q9Wo%40z
Quoted 22 lines
net/tipc/link.c +15
-0+/* A legitimate reassembled message can never exceed +* MAX_MSG_SIZE. Limit the memory one incomplete +* fragment chain can pin, otherwise a peer can grow +* kernel memory unboundedly by streaming fragment +* chains that never complete: received traffic also +* resets the link silence counter, so the link never +* times out and the chains are never freed. +*/ +if ((*reasm_skb)->truesize >2 *MAX_MSG_SIZE ) { + pr_warn_ratelimited("Fragment chain larger than %u bytes, dropping\n", + 2 * MAX_MSG_SIZE); +kfree_skb (*reasm_skb); + *reasm_skb =NULL ; + } + }else if (!link_is_bc_rcvlink (l)) { pr_warn_ratelimited("Unable to build fragmentlist\n"); return tipc_link_fsm_evt(l, LINK_FAILURE_EVT); }--
2.43.5