net: mctp: Set SOCK_RCU_FREE
authorMatt Johnston <matt@codeconstruct.com.au>
Thu, 10 Apr 2025 03:53:19 +0000 (11:53 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:41 +0000 (10:45 +0200)
[ Upstream commit 52024cd6ec71a6ca934d0cc12452bd8d49850679 ]

Bind lookup runs under RCU, so ensure that a socket doesn't go away in
the middle of a lookup.

Fixes: 833ef3b91de6 ("mctp: Populate socket implementation")
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Link: https://patch.msgid.link/20250410-mctp-rcu-sock-v1-1-872de9fdc877@codeconstruct.com.au
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/mctp/af_mctp.c

index 28be85d055330b554538d018378360ae9f14fae4..8032cfba22d1c5c04b8334189c95a36c252e43df 100644 (file)
@@ -550,6 +550,9 @@ static int mctp_sk_hash(struct sock *sk)
 {
        struct net *net = sock_net(sk);
 
+       /* Bind lookup runs under RCU, remain live during that. */
+       sock_set_flag(sk, SOCK_RCU_FREE);
+
        mutex_lock(&net->mctp.bind_lock);
        sk_add_node_rcu(sk, &net->mctp.binds);
        mutex_unlock(&net->mctp.bind_lock);