From: Jeremy Kerr <jk@codeconstruct.com.au>
To: Andrew Stellman <bugs@stellman-greene.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>, Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] net: mctp: Reject duplicate wildcard-peer binds
Date: Fri, 04 Dec 2026 19:00:50 +0800 [thread overview]
Message-ID: <0a30ef2b2f3058175f7ae8300af91d6a773bed26.camel@codeconstruct.com.au> (raw)
In-Reply-To: <20261202165000.49967-1-bugs@stellman-greene.com>
Hi Andrew,
> 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.
OK, good find. connect(MCTP_ADDR_ANY) is a bit odd, perhaps we should
disallow that entirely...
> diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c
> index aa22c0860712..39e966996c54 100644
> --- a/net/mctp/af_mctp.c
> +++ b/net/mctp/af_mctp.c
> @@ -729,9 +729,8 @@ static int mctp_sk_hash(struct sock *sk)
> 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);
> + bool same_peer = (mex->bind_peer_set ? mex->bind_peer_addr :
> + MCTP_ADDR_ANY) == remote;
I think the logic of the change is sound, but might benefit from
breaking it up so that we're not hiding the semantics of setting `remote`.
How about something like:
mctp_eid_t ex_remote = mex->bind_peer_set ? mex->bind_peer_addr :
MCTP_ADDR_ANY;
bool same_peer = ex_remote == remote;
Which then might make more sense to drop same_peer entirely:
diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c
index 209a963112e3..145b8fb66f68 100644
--- a/net/mctp/af_mctp.c
+++ b/net/mctp/af_mctp.c
@@ -728,13 +728,13 @@ 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);
+ mctp_eid_t ex_remote = mex->bind_peer_set ?
+ mex->bind_peer_addr : MCTP_ADDR_ANY;
- 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);
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;
If that makes it any more clear?
Cheers,
Jeremy
prev parent reply other threads:[~2026-12-04 11:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 16:50 [PATCH net] net: mctp: Reject duplicate wildcard-peer binds Andrew Stellman
2026-12-04 11:00 ` Jeremy Kerr [this message]
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=0a30ef2b2f3058175f7ae8300af91d6a773bed26.camel@codeconstruct.com.au \
--to=jk@codeconstruct.com.au \
--cc=bugs@stellman-greene.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--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