Skip to content

Commit 573ef49

Browse files
stefano-garzarellamehmetb0
authored andcommitted
vsock/virtio: discard packets if the transport changes
BugLink: https://bugs.launchpad.net/bugs/2097298 commit 2cb7c756f605ec02ffe562fb26828e4bcc5fdfc1 upstream. 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: 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> [SG: fixed context conflict since this tree is missing commit 71dc9ec ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")] Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
1 parent dc275f0 commit 573ef49

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
@@ -1317,8 +1317,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
13171317

13181318
lock_sock(sk);
13191319

1320-
/* Check if sk has been closed before lock_sock */
1321-
if (sock_flag(sk, SOCK_DONE)) {
1320+
/* Check if sk has been closed or assigned to another transport before
1321+
* lock_sock (note: listener sockets are not assigned to any transport)
1322+
*/
1323+
if (sock_flag(sk, SOCK_DONE) ||
1324+
(sk->sk_state != TCP_LISTEN && vsk->transport != &t->transport)) {
13221325
(void)virtio_transport_reset_no_sock(t, pkt);
13231326
release_sock(sk);
13241327
sock_put(sk);

0 commit comments

Comments
 (0)