Skip to content

Commit e69c3a0

Browse files
jk-ozlabsgregkh
authored andcommitted
net: mctp: mark socks as dead on unhash, prevent re-add
[ Upstream commit b98e1a0 ] 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 <jk@codeconstruct.com.au> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 954cc21 commit e69c3a0

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

net/mctp/af_mctp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ static void mctp_sk_unhash(struct sock *sk)
288288

289289
kfree_rcu(key, rcu);
290290
}
291+
sock_set_flag(sk, SOCK_DEAD);
291292
spin_unlock_irqrestore(&net->mctp.keys_lock, flags);
292293

293294
synchronize_rcu();

net/mctp/route.c

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

136136
spin_lock_irqsave(&net->mctp.keys_lock, flags);
137137

138+
if (sock_flag(&msk->sk, SOCK_DEAD)) {
139+
rc = -EINVAL;
140+
goto out_unlock;
141+
}
142+
138143
hlist_for_each_entry(tmp, &net->mctp.keys, hlist) {
139144
if (mctp_key_match(tmp, key->local_addr, key->peer_addr,
140145
key->tag)) {
@@ -148,6 +153,7 @@ static int mctp_key_add(struct mctp_sk_key *key, struct mctp_sock *msk)
148153
hlist_add_head(&key->sklist, &msk->keys);
149154
}
150155

156+
out_unlock:
151157
spin_unlock_irqrestore(&net->mctp.keys_lock, flags);
152158

153159
return rc;

0 commit comments

Comments
 (0)