Skip to contentSkip to conversation

net/smc: Fix sock leak when release after smc_shutdown()

PATCH Applied Tony Lu 3 participants 3 messages Apr 14, 2022 – Apr 15, 2022

Subsystems (4)
lore
Share & tools
lore

Tony Lu

author reviewer
#0 lore raw

PATCH 1/1 net/smc: Fix sock leak when release after smc_shutdown()

Since commit e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback"), for a fallback connection, __smc_release() does not call sock_put() if its state is already SMC_CLOSED.

When calling smc_shutdown() after falling back, its state is set to SMC_CLOSED but does not call sock_put(), so this patch calls it.

Reported-and-tested-by [email protected]
Fixes e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback")
---
 net/smc/af_smc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -1
index f0d118e9f155..f842425da6ec 100644
@@ -2664,8 +2664,10 @@ static int smc_shutdown(struct socket *sock, int how)
 	if (smc->use_fallback) {
 		rc = kernel_sock_shutdown(smc->clcsock, how);
 		sk->sk_shutdown = smc->clcsock->sk->sk_shutdown;
-		if (sk->sk_shutdown == SHUTDOWN_MASK)
+		if (sk->sk_shutdown == SHUTDOWN_MASK) {
 			sk->sk_state = SMC_CLOSED;
+			sock_put(sk);
+		}
 		goto out;
 	}
 	switch (how) {
Signature · 1 line
2.32.0.3.g01195cf9f
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Tony Lu

Since commit e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback"), for a fallback connection, __smc_release() does not call sock_put() if its state is already SMC_CLOSED.

When calling smc_shutdown() after falling back, its state is set to SMC_CLOSED but does not call sock_put(), so this patch calls it.

Reported-and-tested-by [email protected]
Fixes e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback")

---

Thank you.

#2 lore raw
In reply to Tony Lu
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

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

Quoted 8 lines · On Thu, 14 Apr 2022 15:51:03 +0800 you wrote:

Since commit e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback"), for a fallback connection, __smc_release() does not call sock_put() if its state is already SMC_CLOSED.

When calling smc_shutdown() after falling back, its state is set to SMC_CLOSED but does not call sock_put(), so this patch calls it.

[...]

Here is the summary with links:
- [net] net/smc: Fix sock leak when release after smc_shutdown()

    https://git.kernel.org/netdev/net/c/1a74e9932374

You are awesome, thank you!

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