Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit b98e1a0

Browse files
jk-ozlabsdavem330
authored andcommitted
net: mctp: mark socks as dead on unhash, prevent re-add
Once a socket has been unhashed, we want to prevent it from being re-used in a sk_key entry as part of a routing operation. This change marks the sk as SOCK_DEAD on unhash, which prevents addition into the net's key list. We need to do this during the key add path, rather than key lookup, as we release the net keys_lock between those operations. Fixes: 4a992bb ("mctp: Implement message fragmentation & reassembly") Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6e54ea3 commit b98e1a0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

net/mctp/af_mctp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ static void mctp_sk_unhash(struct sock *sk)
577577
spin_lock_irqsave(&key->lock, fl2);
578578
__mctp_key_remove(key, net, fl2, MCTP_TRACE_KEY_CLOSED);
579579
}
580+
sock_set_flag(sk, SOCK_DEAD);
580581
spin_unlock_irqrestore(&net->mctp.keys_lock, flags);
581582

582583
/* Since there are no more tag allocations (we have removed all of the

net/mctp/route.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ static int mctp_key_add(struct mctp_sk_key *key, struct mctp_sock *msk)
179179

180180
spin_lock_irqsave(&net->mctp.keys_lock, flags);
181181

182+
if (sock_flag(&msk->sk, SOCK_DEAD)) {
183+
rc = -EINVAL;
184+
goto out_unlock;
185+
}
186+
182187
hlist_for_each_entry(tmp, &net->mctp.keys, hlist) {
183188
if (mctp_key_match(tmp, key->local_addr, key->peer_addr,
184189
key->tag)) {
@@ -200,6 +205,7 @@ static int mctp_key_add(struct mctp_sk_key *key, struct mctp_sock *msk)
200205
hlist_add_head(&key->sklist, &msk->keys);
201206
}
202207

208+
out_unlock:
203209
spin_unlock_irqrestore(&net->mctp.keys_lock, flags);
204210

205211
return rc;

0 commit comments

Comments
 (0)