From: Jeremy Kerr <jk@codeconstruct.com.au>
To: Joas Antonio dos Santos <joasantonio108@gmail.com>,
Matt Johnston <matt@codeconstruct.com.au>
Cc: "David S.Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] net: mctp: free reassembly head skb when key_add fails on SOM
Date: Mon, 26 Oct 2026 15:12:38 +0800 [thread overview]
Message-ID: <426ef7428413b8d05b6cc3ac22e24b1927ab5aca.camel@codeconstruct.com.au> (raw)
In-Reply-To: <179287946888.17431.11219154409333681184@gmail.com>
Hi Joas & Guikin,
[merging two threads here; Guikin reported the same issue, around 12
hours earlier]
> 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.
OK, good catch.
> diff --git a/net/mctp/route.c b/net/mctp/route.c
> index e7c95eeac..3d79c2031 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 could just defer setting skb to NULL until the mctp_key_add() has
succeeded; there's already the common error path that cleans up any
remaining skb.
Alternatively, we could change the semantics mctp_key_unref() to also
free any pending reassembly, but I'm okay with the current approach of
being explicit about the state handling.
Cheers,
Jeremy
next prev parent reply other threads:[~2026-10-26 7:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 22:04 Joas Antonio dos Santos
2026-10-26 7:12 ` Jeremy Kerr [this message]
2026-10-26 12:22 ` Joas Antonio dos Santos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=426ef7428413b8d05b6cc3ac22e24b1927ab5aca.camel@codeconstruct.com.au \
--to=jk@codeconstruct.com.au \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=joasantonio108@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@codeconstruct.com.au \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®