From: Matt Johnston <matt@codeconstruct.com.au>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jeremy Kerr <jk@codeconstruct.com.au>
Subject: [PATCH net-next v2] mctp: Avoid leak of mctp_sk_key
Date: Thu, 14 Oct 2021 16:10:50 +0800 [thread overview]
Message-ID: <20211014081050.3041204-1-matt@codeconstruct.com.au> (raw)
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: 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>
---
v2:
- "Fixes:" revid was short
- Send with correct [net-next] subject
- No changes to patch.
---
net/mctp/route.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/mctp/route.c b/net/mctp/route.c
index 04781459b2be..82fb5ae524f6 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;
}
--
2.30.2
next reply other threads:[~2021-10-14 8:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 8:10 Matt Johnston [this message]
2021-10-15 10:30 ` [PATCH net-next v2] mctp: Avoid leak of mctp_sk_key patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211014081050.3041204-1-matt@codeconstruct.com.au \
--to=matt@codeconstruct.com.au \
--cc=davem@davemloft.net \
--cc=jk@codeconstruct.com.au \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).