Skip to content

Commit d6407d9

Browse files
alex-mateismb49
authored andcommitted
vsock/virtio: initialize the_virtio_vsock before using VQs
BugLink: https://bugs.launchpad.net/bugs/2049417 [ Upstream commit 53b08c4 ] Once VQs are filled with empty buffers and we kick the host, it can send connection requests. If the_virtio_vsock is not initialized before, replies are silently dropped and do not reach the host. virtio_transport_send_pkt() can queue packets once the_virtio_vsock is set, but they won't be processed until vsock->tx_run is set to true. We queue vsock->send_pkt_work when initialization finishes to send those packets queued earlier. Fixes: 0deab08 ("vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock") Signed-off-by: Alexandru Matei <alexandru.matei@uipath.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://lore.kernel.org/r/20231024191742.14259-1-alexandru.matei@uipath.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 38b4326 commit d6407d9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

net/vmw_vsock/virtio_transport.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,11 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
590590

591591
virtio_device_ready(vdev);
592592

593+
return 0;
594+
}
595+
596+
static void virtio_vsock_vqs_start(struct virtio_vsock *vsock)
597+
{
593598
mutex_lock(&vsock->tx_lock);
594599
vsock->tx_run = true;
595600
mutex_unlock(&vsock->tx_lock);
@@ -604,7 +609,16 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
604609
vsock->event_run = true;
605610
mutex_unlock(&vsock->event_lock);
606611

607-
return 0;
612+
/* virtio_transport_send_pkt() can queue packets once
613+
* the_virtio_vsock is set, but they won't be processed until
614+
* vsock->tx_run is set to true. We queue vsock->send_pkt_work
615+
* when initialization finishes to send those packets queued
616+
* earlier.
617+
* We don't need to queue the other workers (rx, event) because
618+
* as long as we don't fill the queues with empty buffers, the
619+
* host can't send us any notification.
620+
*/
621+
queue_work(virtio_vsock_workqueue, &vsock->send_pkt_work);
608622
}
609623

610624
static void virtio_vsock_vqs_del(struct virtio_vsock *vsock)
@@ -707,6 +721,7 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
707721
goto out;
708722

709723
rcu_assign_pointer(the_virtio_vsock, vsock);
724+
virtio_vsock_vqs_start(vsock);
710725

711726
mutex_unlock(&the_virtio_vsock_mutex);
712727

@@ -779,6 +794,7 @@ static int virtio_vsock_restore(struct virtio_device *vdev)
779794
goto out;
780795

781796
rcu_assign_pointer(the_virtio_vsock, vsock);
797+
virtio_vsock_vqs_start(vsock);
782798

783799
out:
784800
mutex_unlock(&the_virtio_vsock_mutex);

0 commit comments

Comments
 (0)