Patch "net/smc: Don't call clcsock shutdown twice when smc shutdown" has been added to the 4.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net/smc: Don't call clcsock shutdown twice when smc shutdown

to the 4.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-smc-don-t-call-clcsock-shutdown-twice-when-smc-s.patch
and it can be found in the queue-4.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 2eeee34f576dfd61b076adc4c95fa610848f16cf
Author: Tony Lu <tonylu@xxxxxxxxxxxxxxxxx>
Date:   Fri Nov 26 10:41:35 2021 +0800

    net/smc: Don't call clcsock shutdown twice when smc shutdown
    
    [ Upstream commit bacb6c1e47691cda4a95056c21b5487fb7199fcc ]
    
    When applications call shutdown() with SHUT_RDWR in userspace,
    smc_close_active() calls kernel_sock_shutdown(), and it is called
    twice in smc_shutdown().
    
    This fixes this by checking sk_state before do clcsock shutdown, and
    avoids missing the application's call of smc_shutdown().
    
    Link: https://lore.kernel.org/linux-s390/1f67548e-cbf6-0dce-82b5-10288a4583bd@xxxxxxxxxxxxx/
    Fixes: 606a63c9783a ("net/smc: Ensure the active closing peer first closes clcsock")
    Signed-off-by: Tony Lu <tonylu@xxxxxxxxxxxxxxxxx>
    Reviewed-by: Wen Gu <guwen@xxxxxxxxxxxxxxxxx>
    Acked-by: Karsten Graul <kgraul@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20211126024134.45693-1-tonylu@xxxxxxxxxxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 9aab4ab8161bd..4c904ab29e0e6 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -1589,8 +1589,10 @@ static __poll_t smc_poll(struct file *file, struct socket *sock,
 static int smc_shutdown(struct socket *sock, int how)
 {
 	struct sock *sk = sock->sk;
+	bool do_shutdown = true;
 	struct smc_sock *smc;
 	int rc = -EINVAL;
+	int old_state;
 	int rc1 = 0;
 
 	smc = smc_sk(sk);
@@ -1617,7 +1619,11 @@ static int smc_shutdown(struct socket *sock, int how)
 	}
 	switch (how) {
 	case SHUT_RDWR:		/* shutdown in both directions */
+		old_state = sk->sk_state;
 		rc = smc_close_active(smc);
+		if (old_state == SMC_ACTIVE &&
+		    sk->sk_state == SMC_PEERCLOSEWAIT1)
+			do_shutdown = false;
 		break;
 	case SHUT_WR:
 		rc = smc_close_shutdown_write(smc);
@@ -1627,7 +1633,7 @@ static int smc_shutdown(struct socket *sock, int how)
 		/* nothing more to do because peer is not involved */
 		break;
 	}
-	if (smc->clcsock)
+	if (do_shutdown && smc->clcsock)
 		rc1 = kernel_sock_shutdown(smc->clcsock, how);
 	/* map sock_shutdown_cmd constants to sk_shutdown value range */
 	sk->sk_shutdown |= how + 1;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux