From: Andrew Stellman <aste…@stellman-greene.com> mctp_sk_hash() hashes an unconnected socket and one connected to MCTP_ADDR_ANY into the same bucket, and mctp_lookup_bind_details() matches both against any source EID. The duplicate check treats them as different peers, so a second bind() with the same net, local EID and type succeeds when only one socket is connected to ANY. Compare effective peers (MCTP_ADDR_ANY if bind_peer_set is clear). A duplicate bind() now fails with -EADDRINUSE when only one of the two sockets is connected to ANY; it previously succeeded. 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: 3549eb08e550 ("net: mctp: Allow limiting binds to a peer address") Suggested-by: Jeremy Kerr <j…@codeconstruct.com.au> Signed-off-by: Andrew Stellman <aste…@stellman-greene.com> --- v2: Restructure the check as Jeremy Kerr suggested. v1: https://lore.kernel.org/netdev/2026…@stellman-greene.com/ Tested on net 3c8881ee9806 (7.4.0-rc5) in arm64 QEMU with KASAN: a duplicate bind() succeeded in both orders before the fix and returned EADDRINUSE with it. A reproducer is available on request. net/mctp/af_mctp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c index aa22c0860712..ff4adcc12967 100644 --- a/net/mctp/af_mctp.c +++ b/net/mctp/af_mctp.c @@ -728,13 +728,12 @@ static int mctp_sk_hash(struct sock *sk) sk_for_each(existing, &net->mctp.binds[hash]) { struct mctp_sock *mex = container_of(existing, struct mctp_sock, sk); - - bool same_peer = (mex->bind_peer_set && msk->bind_peer_set && - mex->bind_peer_addr == msk->bind_peer_addr) || - (!mex->bind_peer_set && !msk->bind_peer_set); + mctp_eid_t ex_remote = mex->bind_peer_set ? + mex->bind_peer_addr : MCTP_ADDR_ANY; if (mex->bind_type == msk->bind_type && - mex->bind_local_addr == msk->bind_local_addr && same_peer && + mex->bind_local_addr == msk->bind_local_addr && + remote == ex_remote && mex->bind_net == msk->bind_net) { rc = -EADDRINUSE; goto out;
-- 2.53.0