Skip to content

Commit 2cb7c75

Browse files
stefano-garzarellaPaolo Abeni
authored andcommitted
vsock/virtio: discard packets if the transport changes
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: c0cfa2d ("vsock: add multi-transports support") Cc: [email protected] Reported-by: Hyunwoo Kim <[email protected]> Reported-by: Wongi Lee <[email protected]> Closes: https://lore.kernel.org/netdev/Z2LvdTTQR7dBmPb5@v4bel-B760M-AORUS-ELITE-AX/ Signed-off-by: Stefano Garzarella <[email protected]> Reviewed-by: Hyunwoo Kim <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 0865b9f commit 2cb7c75

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

net/vmw_vsock/virtio_transport_common.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,8 +1628,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
16281628

16291629
lock_sock(sk);
16301630

1631-
/* Check if sk has been closed before lock_sock */
1632-
if (sock_flag(sk, SOCK_DONE)) {
1631+
/* Check if sk has been closed or assigned to another transport before
1632+
* lock_sock (note: listener sockets are not assigned to any transport)
1633+
*/
1634+
if (sock_flag(sk, SOCK_DONE) ||
1635+
(sk->sk_state != TCP_LISTEN && vsk->transport != &t->transport)) {
16331636
(void)virtio_transport_reset_no_sock(t, skb);
16341637
release_sock(sk);
16351638
sock_put(sk);

0 commit comments

Comments
 (0)