]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
vsock/virtio: discard packets if the transport changes
authorStefano Garzarella <sgarzare@redhat.com>
Fri, 10 Jan 2025 08:35:07 +0000 (09:35 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 14 Jan 2025 11:29:36 +0000 (12:29 +0100)
If the socket has been de-assigned or assigned to another transport,
we must discard any packets received because they are not expected
and would cause issues when we access vsk->transport.

A possible scenario is described by Hyunwoo Kim in the attached link,
where after a first connect() interrupted by a signal, and a second
connect() failed, we can find `vsk->transport` at NULL, leading to a
NULL pointer dereference.

Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
Cc: stable@vger.kernel.org
Reported-by: Hyunwoo Kim <v4bel@theori.io>
Reported-by: Wongi Lee <qwerty@theori.io>
Closes: https://lore.kernel.org/netdev/Z2LvdTTQR7dBmPb5@v4bel-B760M-AORUS-ELITE-AX/
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Hyunwoo Kim <v4bel@theori.io>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/vmw_vsock/virtio_transport_common.c

index 9acc13ab3f822d2b1800392e77402aa3b06db853..51a494b69be8475d66d5c2e5b921b1b0d56cc572 100644 (file)
@@ -1628,8 +1628,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 
        lock_sock(sk);
 
-       /* Check if sk has been closed before lock_sock */
-       if (sock_flag(sk, SOCK_DONE)) {
+       /* Check if sk has been closed or assigned to another transport before
+        * lock_sock (note: listener sockets are not assigned to any transport)
+        */
+       if (sock_flag(sk, SOCK_DONE) ||
+           (sk->sk_state != TCP_LISTEN && vsk->transport != &t->transport)) {
                (void)virtio_transport_reset_no_sock(t, skb);
                release_sock(sk);
                sock_put(sk);