Skip to contentSkip to conversation

mctp: Avoid leak of mctp_sk_key

PATCH Applied Matt Johnston 2 participants 2 messages Oct 14, 2021 – Oct 15, 2021

Subsystems (3)
lore
Share & tools
lore

Matt Johnston

author maintainer
#0 lore raw

PATCH v2 1/1 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 73c618456dc5 ("mctp: locking, lifetime and validity changes for sk_keys")

---
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(+)
net/mctp/route.c +4 -0
index 04781459b2be..82fb5ae524f6 100644
@@ -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;
 	}
 
Signature · 1 line
2.30.2
#1 lore raw
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Thu, 14 Oct 2021 16:10:50 +0800 you wrote:

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.

[...]

Here is the summary with links:
- [net-next,v2] mctp: Avoid leak of mctp_sk_key

    https://git.kernel.org/netdev/net-next/c/0b93aed2842d

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html