[PATCH net v2 1/2] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc()
From: Andrew Stellman
Date: Fri Dec 04 2026 - 13:43:15 EST
From: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
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.
The issue was found by Claude Opus 5.5 and Claude Fable 5.2
running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix and this changelog were drafted with OpenAI GPT-6 (Codex)
and reviewed by me.
Fixes: de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
Reviewed-by: Jeremy Kerr <jk@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
---
v2: no code change; add Jeremy Kerr's Reviewed-by.
v1: https://lore.kernel.org/netdev/20261202164958.49945-1-bugs@xxxxxxxxxxxxxxxxxxx/
Tested on net 3c8881ee9806 (7.4.0-rc5) in arm64 QEMU with KASAN, using
the KUnit case in 2/2, which sets a zero sk_refcnt on a bound socket
(the close race itself wasn't reproduced): it hit the "addition on 0"
and "underflow" refcount warnings without this fix and passed with it.
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 96fd75ea7..5bc3a8e09 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