diff options
author | Matt Johnston <matt@codeconstruct.com.au> | 2021-10-14 11:10:50 +0300 |
---|---|---|
committer | Joel Stanley <joel@jms.id.au> | 2022-03-18 03:37:13 +0300 |
commit | b11452c34c3487e456cff70c051787a7d70dcf12 (patch) | |
tree | a638120a7b99786b83797d6640cb08c0af54a8e6 /net/mctp | |
parent | a2485cd016698a060b5582efb1b3d634e90b6f36 (diff) | |
download | linux-b11452c34c3487e456cff70c051787a7d70dcf12.tar.xz |
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).
OpenBMC-Staging-Count: 1
Fixes: 73c618456dc5 ("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>
(cherry picked from commit 0b93aed2842d950e8d2625e975e5a57febeff33d)
Signed-off-by: Joel Stanley <joel@jms.id.au>
Diffstat (limited to 'net/mctp')
-rw-r--r-- | net/mctp/route.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/net/mctp/route.c b/net/mctp/route.c index 47fe02bf12af..580a78b15626 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -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 { @@ -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; } |