]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: mctp: Treat MCTP_NET_ANY specially in bind()
authorMatt Johnston <matt@codeconstruct.com.au>
Thu, 10 Jul 2025 08:55:56 +0000 (16:55 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 15 Jul 2025 10:08:39 +0000 (12:08 +0200)
When a specific EID is passed as a bind address, it only makes sense to
interpret with an actual network ID, so resolve that to the default
network at bind time.

For bind address of MCTP_ADDR_ANY, we want to be able to capture traffic
to any network and address, so keep the current behaviour of matching
traffic from any network interface (don't interpret MCTP_NET_ANY as
the default network ID).

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Link: https://patch.msgid.link/20250710-mctp-bind-v4-3-8ec2f6460c56@codeconstruct.com.au
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/mctp/af_mctp.c

index 0d073bc32ec17905ac0118d1aa653a46d829b150..20edaf840a607700c04b740708763fbd02a2df47 100644 (file)
@@ -53,6 +53,7 @@ static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen)
 {
        struct sock *sk = sock->sk;
        struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk);
+       struct net *net = sock_net(&msk->sk);
        struct sockaddr_mctp *smctp;
        int rc;
 
@@ -77,8 +78,21 @@ static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen)
                rc = -EADDRINUSE;
                goto out_release;
        }
-       msk->bind_net = smctp->smctp_network;
+
        msk->bind_addr = smctp->smctp_addr.s_addr;
+
+       /* MCTP_NET_ANY with a specific EID is resolved to the default net
+        * at bind() time.
+        * For bind_addr=MCTP_ADDR_ANY it is handled specially at route
+        * lookup time.
+        */
+       if (smctp->smctp_network == MCTP_NET_ANY &&
+           msk->bind_addr != MCTP_ADDR_ANY) {
+               msk->bind_net = mctp_default_net(net);
+       } else {
+               msk->bind_net = smctp->smctp_network;
+       }
+
        msk->bind_type = smctp->smctp_type & 0x7f; /* ignore the IC bit */
 
        rc = sk->sk_prot->hash(sk);