Skip to content

Commit

Permalink
mctp: Avoid leak of mctp_sk_key
Browse files Browse the repository at this point in the history
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 <matt@codeconstruct.com.au>
Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Matt Johnston authored and David S. Miller committed Oct 15, 2021
1 parent bf13667 commit 0b93aed
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/mctp/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)
trace_mctp_key_acquire(key);

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

} else {
Expand Down Expand Up @@ -584,6 +585,9 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk,
trace_mctp_key_acquire(key);

*tagp = key->tag;
/* done with the key in this scope */
mctp_key_unref(key);
key = NULL;
rc = 0;
}

Expand Down

0 comments on commit 0b93aed

Please sign in to comment.