Skip to content

Commit 1de9770

Browse files
Wen Gudavem330
authored andcommitted
net/smc: Avoid overwriting the copies of clcsock callback functions
The callback functions of clcsock will be saved and replaced during the fallback. But if the fallback happens more than once, then the copies of these callback functions will be overwritten incorrectly, resulting in a loop call issue: clcsk->sk_error_report |- smc_fback_error_report() <------------------------------| |- smc_fback_forward_wakeup() | (loop) |- clcsock_callback() (incorrectly overwritten) | |- smc->clcsk_error_report() ------------------| So this patch fixes the issue by saving these function pointers only once in the fallback and avoiding overwriting. Reported-by: [email protected] Fixes: 341adee ("net/smc: Forward wakeup to smc socket waitqueue after fallback") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wen Gu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f1baf68 commit 1de9770

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

net/smc/af_smc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,17 @@ static void smc_fback_error_report(struct sock *clcsk)
667667
static int smc_switch_to_fallback(struct smc_sock *smc, int reason_code)
668668
{
669669
struct sock *clcsk;
670+
int rc = 0;
670671

671672
mutex_lock(&smc->clcsock_release_lock);
672673
if (!smc->clcsock) {
673-
mutex_unlock(&smc->clcsock_release_lock);
674-
return -EBADF;
674+
rc = -EBADF;
675+
goto out;
675676
}
676677
clcsk = smc->clcsock->sk;
677678

679+
if (smc->use_fallback)
680+
goto out;
678681
smc->use_fallback = true;
679682
smc->fallback_rsn = reason_code;
680683
smc_stat_fallback(smc);
@@ -702,8 +705,9 @@ static int smc_switch_to_fallback(struct smc_sock *smc, int reason_code)
702705
smc->clcsock->sk->sk_user_data =
703706
(void *)((uintptr_t)smc | SK_USER_DATA_NOCOPY);
704707
}
708+
out:
705709
mutex_unlock(&smc->clcsock_release_lock);
706-
return 0;
710+
return rc;
707711
}
708712

709713
/* fall back during connect */

0 commit comments

Comments
 (0)