Skip to content

Commit 0b93aed

Browse files
mkjdavem330
authored andcommitted
mctp: Avoid leak of mctp_sk_key
mctp_key_alloc() returns a key already referenced. The mctp_route_input() path receives a packet for a bind socket and allocates a key. It passes the key to mctp_key_add() which takes a refcount and adds the key to lists. mctp_route_input() should then release its own refcount when setting the key pointer to NULL. In the mctp_alloc_local_tag() path (for mctp_local_output()) we similarly need to unref the key before returning (mctp_reserve_tag() takes a refcount and adds the key to lists). Fixes: 73c6184 ("mctp: locking, lifetime and validity changes for sk_keys") Signed-off-by: Matt Johnston <[email protected]> Reviewed-by: Jeremy Kerr <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bf13667 commit 0b93aed

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/mctp/route.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)
372372
trace_mctp_key_acquire(key);
373373

374374
/* we don't need to release key->lock on exit */
375+
mctp_key_unref(key);
375376
key = NULL;
376377

377378
} else {
@@ -584,6 +585,9 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk,
584585
trace_mctp_key_acquire(key);
585586

586587
*tagp = key->tag;
588+
/* done with the key in this scope */
589+
mctp_key_unref(key);
590+
key = NULL;
587591
rc = 0;
588592
}
589593

0 commit comments

Comments
 (0)