summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Antonio dos Santos <joasantonio108@gmail.com>2026-10-24 19:04:28 -0300
committerPaolo Abeni <pabeni@redhat.com>2026-10-29 10:48:51 +0100
commitd2bfe74a8fe219a86b86c1f126e1d722a5001790 (patch)
treedeba0478f43aba21c90624b068ca3bd1e6ace175
parentfa503935c2d6603856dafff0a0852631ab6e9503 (diff)
net: mctp: free reassembly head skb when key_add fails on SOM
When a start-of-message fragment creates a new reassembly key on the broadcast/bind path, mctp_frag_queue() stores the skb as key->reasm_head before the key is made observable with mctp_key_add(). If mctp_key_add() fails (a race with another SOM packet for the same source/dest/tag, or the receiving socket going away), the error path only drops the key reference via mctp_key_unref(). The final key destructor frees the key itself but not key->reasm_head, and since the key was never added to any list, neither the expiry worker nor socket teardown can reach it to release the queued fragment. The skb is leaked. Free key->reasm_head on the key_add failure path before releasing the key. Other teardown paths (__mctp_key_done_in(), EOM delivery) already clear reasm_head before the final unref, so this only affects the failure path. Fixes: 4a992bbd3650 ("mctp: Implement message fragmentation & reassembly") Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com> Reported-by: Guikun Yang <yangguikun19@qq.com> Closes: https://lore.kernel.org/all/tencent_43A65D51143E18518EA968DF9323694EFD08@qq.com/ Acked-by: Jeremy Kerr <jk@codeconstruct.com.au> Link: https://patch.msgid.link/179287946888.17431.11219154409333681184@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-rw-r--r--net/mctp/route.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/net/mctp/route.c b/net/mctp/route.c
index d18ed9d0db1d..96fd75ea791b 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -552,8 +552,16 @@ static int mctp_dst_input(struct mctp_dst *dst, struct sk_buff *skb)
* can do is drop.
*/
rc = mctp_key_add(key, msk);
- if (!rc)
+ if (!rc) {
trace_mctp_key_acquire(key);
+ } else {
+ /* key_add failed: the key is not observable by
+ * any cleanup path, so free the fragment we
+ * just queued on it to avoid leaking the skb.
+ */
+ kfree_skb(key->reasm_head);
+ key->reasm_head = NULL;
+ }
/* we don't need to release key->lock on exit, so
* clean up here and suppress the unlock via