Patch "vsock/virtio: remove socket from connected/bound list on shutdown" has been added to the 6.1-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

    vsock/virtio: remove socket from connected/bound list on shutdown

to the 6.1-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:
     vsock-virtio-remove-socket-from-connected-bound-list.patch
and it can be found in the queue-6.1 subdirectory.

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



commit 1ee503bd1f558d4497498a5f553aa2e0961bfa18
Author: Filippo Storniolo <f.storniolo95@xxxxxxxxx>
Date:   Fri Nov 3 18:55:48 2023 +0100

    vsock/virtio: remove socket from connected/bound list on shutdown
    
    [ Upstream commit 3a5cc90a4d1756072619fe511d07621bdef7f120 ]
    
    If the same remote peer, using the same port, tries to connect
    to a server on a listening port more than once, the server will
    reject the connection, causing a "connection reset by peer"
    error on the remote peer. This is due to the presence of a
    dangling socket from a previous connection in both the connected
    and bound socket lists.
    The inconsistency of the above lists only occurs when the remote
    peer disconnects and the server remains active.
    
    This bug does not occur when the server socket is closed:
    virtio_transport_release() will eventually schedule a call to
    virtio_transport_do_close() and the latter will remove the socket
    from the bound and connected socket lists and clear the sk_buff.
    
    However, virtio_transport_do_close() will only perform the above
    actions if it has been scheduled, and this will not happen
    if the server is processing the shutdown message from a remote peer.
    
    To fix this, introduce a call to vsock_remove_sock()
    when the server is handling a client disconnect.
    This is to remove the socket from the bound and connected socket
    lists without clearing the sk_buff.
    
    Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
    Reported-by: Daan De Meyer <daan.j.demeyer@xxxxxxxxx>
    Tested-by: Daan De Meyer <daan.j.demeyer@xxxxxxxxx>
    Co-developed-by: Luigi Leonardi <luigi.leonardi@xxxxxxxxxxx>
    Signed-off-by: Luigi Leonardi <luigi.leonardi@xxxxxxxxxxx>
    Signed-off-by: Filippo Storniolo <f.storniolo95@xxxxxxxxx>
    Reviewed-by: Stefano Garzarella <sgarzare@xxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index a1581c77cf84a..73e5093928325 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1108,11 +1108,17 @@ virtio_transport_recv_connected(struct sock *sk,
 			vsk->peer_shutdown |= RCV_SHUTDOWN;
 		if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SHUTDOWN_SEND)
 			vsk->peer_shutdown |= SEND_SHUTDOWN;
-		if (vsk->peer_shutdown == SHUTDOWN_MASK &&
-		    vsock_stream_has_data(vsk) <= 0 &&
-		    !sock_flag(sk, SOCK_DONE)) {
-			(void)virtio_transport_reset(vsk, NULL);
-			virtio_transport_do_close(vsk, true);
+		if (vsk->peer_shutdown == SHUTDOWN_MASK) {
+			if (vsock_stream_has_data(vsk) <= 0 && !sock_flag(sk, SOCK_DONE)) {
+				(void)virtio_transport_reset(vsk, NULL);
+				virtio_transport_do_close(vsk, true);
+			}
+			/* Remove this socket anyway because the remote peer sent
+			 * the shutdown. This way a new connection will succeed
+			 * if the remote peer uses the same source port,
+			 * even if the old socket is still unreleased, but now disconnected.
+			 */
+			vsock_remove_sock(vsk);
 		}
 		if (le32_to_cpu(virtio_vsock_hdr(skb)->flags))
 			sk->sk_state_change(sk);



[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