Skip to contentSkip to conversation

net: mctp: put sock on tag allocation failure

PATCH Applied Jeremy Kerr 4 participants 5 messages Feb 15, 2024 – Feb 22, 2024

Subsystems (3)
lore
Share & tools
lore

Jeremy Kerr

author maintainer
#0 lore raw

PATCH 1/1 net: mctp: put sock on tag allocation failure

We may hold an extra reference on a socket if a tag allocation fails: we optimistically allocate the sk_key, and take a ref there, but do not drop if we end up not using the allocated key.

Ensure we're dropping the sock on this failure by doing a proper unref rather than directly kfree()ing.

Fixes de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
---
 net/mctp/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mctp/route.c +1 -1
index a64788bc40a8..8594bf256e7d 100644
@@ -663,7 +663,7 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
 	spin_unlock_irqrestore(&mns->keys_lock, flags);
 
 	if (!tagbits) {
-		kfree(key);
+		mctp_key_unref(key);
 		return ERR_PTR(-EBUSY);
 	}
 
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jeremy Kerr

We may hold an extra reference on a socket if a tag allocation fails: we optimistically allocate the sk_key, and take a ref there, but do not drop if we end up not using the allocated key.

Ensure we're dropping the sock on this failure by doing a proper unref rather than directly kfree()ing.

Fixes de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
maintainer
#2 lore raw
In reply to Jeremy Kerr
Quoted 9 lines · On Thu, 15 Feb 2024 15:53:08 +0800 Jeremy Kerr wrote:

We may hold an extra reference on a socket if a tag allocation fails: we optimistically allocate the sk_key, and take a ref there, but do not drop if we end up not using the allocated key.

Ensure we're dropping the sock on this failure by doing a proper unref rather than directly kfree()ing.

Fixes de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")

Hi Jeremy!

This patch is good to be applied, right?
It got marked Not Applicable in patchwork, not sure why.

author maintainer
#3 lore raw

Hi Jakub,

Quoted 1 line

This patch is good to be applied, right?

Yep, all good on my side!

Quoted 1 line

It got marked Not Applicable in patchwork, not sure why.

Also not sure what happened there - I hadn't set that myself, at least!

Cheers,

Jeremy

#4 lore raw
In reply to Jeremy Kerr
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 15 Feb 2024 15:53:08 +0800 you wrote:

We may hold an extra reference on a socket if a tag allocation fails: we optimistically allocate the sk_key, and take a ref there, but do not drop if we end up not using the allocated key.

Ensure we're dropping the sock on this failure by doing a proper unref rather than directly kfree()ing.

[...]

Here is the summary with links:
- [net] net: mctp: put sock on tag allocation failure

    https://git.kernel.org/netdev/net/c/9990889be142

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html