Skip to content

Commit 6e54ea3

Browse files
Paolo Abenidavem330
authored andcommitted
net: mctp: hold key reference when looking up a general key
Currently, we have a race where we look up a sock through a "general" (ie, not directly associated with the (src,dest,tag) tuple) key, then drop the key reference while still holding the key's sock. This change expands the key reference until we've finished using the sock, and hence the sock reference too. Commit message changes from Jeremy Kerr <[email protected]>. Reported-by: Noam Rathaus <[email protected]> Fixes: 73c6184 ("mctp: locking, lifetime and validity changes for sk_keys") Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5f41ae6 commit 6e54ea3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

net/mctp/route.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ static int mctp_frag_queue(struct mctp_sk_key *key, struct sk_buff *skb)
317317

318318
static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)
319319
{
320+
struct mctp_sk_key *key, *any_key = NULL;
320321
struct net *net = dev_net(skb->dev);
321-
struct mctp_sk_key *key;
322322
struct mctp_sock *msk;
323323
struct mctp_hdr *mh;
324324
unsigned long f;
@@ -363,13 +363,11 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)
363363
* key for reassembly - we'll create a more specific
364364
* one for future packets if required (ie, !EOM).
365365
*/
366-
key = mctp_lookup_key(net, skb, MCTP_ADDR_ANY, &f);
367-
if (key) {
368-
msk = container_of(key->sk,
366+
any_key = mctp_lookup_key(net, skb, MCTP_ADDR_ANY, &f);
367+
if (any_key) {
368+
msk = container_of(any_key->sk,
369369
struct mctp_sock, sk);
370-
spin_unlock_irqrestore(&key->lock, f);
371-
mctp_key_unref(key);
372-
key = NULL;
370+
spin_unlock_irqrestore(&any_key->lock, f);
373371
}
374372
}
375373

@@ -475,6 +473,8 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)
475473
spin_unlock_irqrestore(&key->lock, f);
476474
mctp_key_unref(key);
477475
}
476+
if (any_key)
477+
mctp_key_unref(any_key);
478478
out:
479479
if (rc)
480480
kfree_skb(skb);

0 commit comments

Comments
 (0)