net/smc: loop in smc_listen
PATCH 1/1 net/smc: loop in smc_listen
From: Guo DaXing <[email protected]>
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.
--- net/smc/af_smc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -1
@@ -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 ;
Signature · 1 line
2.20.1
Tony Lu
reviewerQuoted 8 lines · Daxing Guo
From: Guo DaXing <[email protected]>
The
kernel_listenfunction insmc_listenwill fail when all the available ports are occupied. At this pointsmc->clcsock->sk->sk_data_readyhas been changed tosmc_clcsock_data_ready. When we callsmc_listenagain, now bothsmc->clcsock->sk->sk_data_readyandsmc->clcsk_data_readypoint to thesmc_clcsock_data_readyfunction.
Quoted 4 lines
The
smc_clcsock_data_ready()function callslsmc->clcsk_data_readywhich now points to itself resulting in an infinite loop.This patch restores
smc->clcsock->sk->sk_data_readywith 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
Quoted 24 lines
Signed-off-by Guo DaXing <[email protected]>--- net/smc/af_smc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/smc/af_smc.c +3
-1@@ -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 ;Signature · 1 line
2.20.1
Quoted 8 lines · Daxing Guo
From: Guo DaXing <[email protected]>
The
kernel_listenfunction insmc_listenwill fail when all the available ports are occupied. At this pointsmc->clcsock->sk->sk_data_readyhas been changed tosmc_clcsock_data_ready. When we callsmc_listenagain, now bothsmc->clcsock->sk->sk_data_readyandsmc->clcsk_data_readypoint to thesmc_clcsock_data_readyfunction.
Quoted 7 lines
The
smc_clcsock_data_ready()function callslsmc->clcsk_data_readywhich now points to itself resulting in an infinite loop.This patch restores
smc->clcsock->sk->sk_data_readywith the old value.Signed-off-by Guo DaXing <[email protected]>---
Thanks for your patch, I will pick it up and submit it to the net tree.
Quoted 8 lines · Daxing Guo
From: Guo DaXing <[email protected]>
The
kernel_listenfunction insmc_listenwill fail when all the available ports are occupied. At this pointsmc->clcsock->sk->sk_data_readyhas been changed tosmc_clcsock_data_ready. When we callsmc_listenagain, now bothsmc->clcsock->sk->sk_data_readyandsmc->clcsk_data_readypoint to thesmc_clcsock_data_readyfunction.
Quoted 6 lines
The
smc_clcsock_data_ready()function callslsmc->clcsk_data_readywhich now points to itself resulting in an infinite loop.This patch restores
smc->clcsock->sk->sk_data_readywith the old value.Signed-off-by Guo DaXing <[email protected]>
It works in my testing environment, thanks.