diff mbox series

net/smc: loop in smc_listen

Message ID 20211120075451.16764-1-guodaxing@huawei.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series net/smc: loop in smc_listen | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 3 maintainers not CCed: davem@davemloft.net kgraul@linux.ibm.com kuba@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Daxing Guo Nov. 20, 2021, 7:54 a.m. UTC
From: Guo DaXing <guodaxing@huawei.com>

The kernel_listen function in smc_listen will fail when all the available
ports are occupied.  At this point smc->clcsock->sk->sk_data_ready has 
been changed to smc_clcsock_data_ready.  When we call smc_listen again, 
now both smc->clcsock->sk->sk_data_ready and smc->clcsk_data_ready point 
to the smc_clcsock_data_ready function.

The smc_clcsock_data_ready() function calls lsmc->clcsk_data_ready which 
now points to itself resulting in an infinite loop.

This patch restores smc->clcsock->sk->sk_data_ready with the old value.

Signed-off-by: Guo DaXing <guodaxing@huawei.com>
---
 net/smc/af_smc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tony Lu Nov. 22, 2021, 3:19 a.m. UTC | #1
On Sat, Nov 20, 2021 at 03:54:51PM +0800, Daxing Guo wrote:
> From: Guo DaXing <guodaxing@huawei.com>
> 
> The kernel_listen function in smc_listen will fail when all the available
> ports are occupied.  At this point smc->clcsock->sk->sk_data_ready has 
> been changed to smc_clcsock_data_ready.  When we call smc_listen again, 
> now both smc->clcsock->sk->sk_data_ready and smc->clcsk_data_ready point 
> to the smc_clcsock_data_ready function.
> 
> The smc_clcsock_data_ready() function calls lsmc->clcsk_data_ready which 
> now points to itself resulting in an infinite loop.
> 
> This patch restores smc->clcsock->sk->sk_data_ready with the old value.

Hi Guo,

This indeed seems to be an issue. When listen fails, the original
clcsock's sk_data_ready overwrites by smc_clcsock_data_ready and can't
be recovered. I will also test it in my environment, thanks.

Cheers,
Tony Lu

> 
> Signed-off-by: Guo DaXing <guodaxing@huawei.com>
> ---
>  net/smc/af_smc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index 59284da9116d..078f5edf6d4d 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -2120,8 +2120,10 @@ static int smc_listen(struct socket *sock, int backlog)
>  	smc->clcsock->sk->sk_user_data =
>  		(void *)((uintptr_t)smc | SK_USER_DATA_NOCOPY);
>  	rc = kernel_listen(smc->clcsock, backlog);
> -	if (rc)
> +	if (rc) {
> +		smc->clcsock->sk->sk_data_ready = smc->clcsk_data_ready;
>  		goto out;
> +	}
>  	sk->sk_max_ack_backlog = backlog;
>  	sk->sk_ack_backlog = 0;
>  	sk->sk_state = SMC_LISTEN;
> -- 
> 2.20.1
Karsten Graul Nov. 22, 2021, 7:28 a.m. UTC | #2
On 20/11/2021 08:54, Daxing Guo wrote:
> From: Guo DaXing <guodaxing@huawei.com>
> 
> The kernel_listen function in smc_listen will fail when all the available
> ports are occupied.  At this point smc->clcsock->sk->sk_data_ready has 
> been changed to smc_clcsock_data_ready.  When we call smc_listen again, 
> now both smc->clcsock->sk->sk_data_ready and smc->clcsk_data_ready point 
> to the smc_clcsock_data_ready function.
> 
> The smc_clcsock_data_ready() function calls lsmc->clcsk_data_ready which 
> now points to itself resulting in an infinite loop.
> 
> This patch restores smc->clcsock->sk->sk_data_ready with the old value.
> 
> Signed-off-by: Guo DaXing <guodaxing@huawei.com>
> ---

Thanks for your patch, I will pick it up and submit it to the net tree.
Tony Lu Nov. 22, 2021, 8:37 a.m. UTC | #3
On Sat, Nov 20, 2021 at 03:54:51PM +0800, Daxing Guo wrote:
> From: Guo DaXing <guodaxing@huawei.com>
> 
> The kernel_listen function in smc_listen will fail when all the available
> ports are occupied.  At this point smc->clcsock->sk->sk_data_ready has 
> been changed to smc_clcsock_data_ready.  When we call smc_listen again, 
> now both smc->clcsock->sk->sk_data_ready and smc->clcsk_data_ready point 
> to the smc_clcsock_data_ready function.
> 
> The smc_clcsock_data_ready() function calls lsmc->clcsk_data_ready which 
> now points to itself resulting in an infinite loop.
> 
> This patch restores smc->clcsock->sk->sk_data_ready with the old value.
> 
> Signed-off-by: Guo DaXing <guodaxing@huawei.com>

It works in my testing environment, thanks.

Acked-by: Tony Lu <tonylu@linux.alibaba.com>
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 59284da9116d..078f5edf6d4d 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -2120,8 +2120,10 @@  static int smc_listen(struct socket *sock, int backlog)
 	smc->clcsock->sk->sk_user_data =
 		(void *)((uintptr_t)smc | SK_USER_DATA_NOCOPY);
 	rc = kernel_listen(smc->clcsock, backlog);
-	if (rc)
+	if (rc) {
+		smc->clcsock->sk->sk_data_ready = smc->clcsk_data_ready;
 		goto out;
+	}
 	sk->sk_max_ack_backlog = backlog;
 	sk->sk_ack_backlog = 0;
 	sk->sk_state = SMC_LISTEN;