From: Andrew Stellman <bugs@stellman-greene.com>
To: Jeremy Kerr <jk@codeconstruct.com.au>,
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>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc()
Date: Wed, 2 Dec 2026 11:49:58 -0500 [thread overview]
Message-ID: <20261202164958.49945-1-bugs@stellman-greene.com> (raw)
From: Andrew Stellman <astellman@stellman-greene.com>
mctp_dst_input() finds the bound socket with mctp_lookup_bind() under
RCU only, without holding a reference. If a concurrent close drops
the last reference after that lookup, mctp_key_alloc() calls
sock_hold() on a zero refcount, which saturates it and warns, and
mctp_key_unref() later underflows it.
Take the reference with refcount_inc_not_zero() and fail the key
allocation if the socket is already at zero.
Fixes: de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
Tested on net-next 19c484e12ed2 (7.4.0-rc4) in arm64 QEMU with a private
KUnit case that set a zero sk_refcnt on a bound socket (I didn't
reproduce the close race itself): without the fix it hit the "addition
on 0" and "underflow" refcount warnings, and with the fix it passed with
no warning.
Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook) running Claude Opus
5.5 and Claude Fable 5.2; the fix was drafted with OpenAI GPT-6 (Codex).
A reproducer is available on request.
net/mctp/route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/mctp/route.c b/net/mctp/route.c
index 96fd75ea791b..5bc3a8e091d8 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -239,7 +239,10 @@ static struct mctp_sk_key *mctp_key_alloc(struct mctp_sock *msk,
key->valid = true;
spin_lock_init(&key->lock);
refcount_set(&key->refs, 1);
- sock_hold(key->sk);
+ if (!refcount_inc_not_zero(&msk->sk.sk_refcnt)) {
+ kfree(key);
+ return NULL;
+ }
return key;
}
--
2.53.0
reply other threads:[~2026-12-02 16:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261202164958.49945-1-bugs@stellman-greene.com \
--to=bugs@stellman-greene.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jk@codeconstruct.com.au \
--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