Skip to content

Commit 53b08c4

Browse files
alex-mateikuba-moo
authored andcommitted
vsock/virtio: initialize the_virtio_vsock before using VQs
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 <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1711435 commit 53b08c4

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
@@ -555,6 +555,11 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
555555

556556
virtio_device_ready(vdev);
557557

558+
return 0;
559+
}
560+
561+
static void virtio_vsock_vqs_start(struct virtio_vsock *vsock)
562+
{
558563
mutex_lock(&vsock->tx_lock);
559564
vsock->tx_run = true;
560565
mutex_unlock(&vsock->tx_lock);
@@ -569,7 +574,16 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
569574
vsock->event_run = true;
570575
mutex_unlock(&vsock->event_lock);
571576

572-
return 0;
577+
/* virtio_transport_send_pkt() can queue packets once
578+
* the_virtio_vsock is set, but they won't be processed until
579+
* vsock->tx_run is set to true. We queue vsock->send_pkt_work
580+
* when initialization finishes to send those packets queued
581+
* earlier.
582+
* We don't need to queue the other workers (rx, event) because
583+
* as long as we don't fill the queues with empty buffers, the
584+
* host can't send us any notification.
585+
*/
586+
queue_work(virtio_vsock_workqueue, &vsock->send_pkt_work);
573587
}
574588

575589
static void virtio_vsock_vqs_del(struct virtio_vsock *vsock)
@@ -664,6 +678,7 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
664678
goto out;
665679

666680
rcu_assign_pointer(the_virtio_vsock, vsock);
681+
virtio_vsock_vqs_start(vsock);
667682

668683
mutex_unlock(&the_virtio_vsock_mutex);
669684

@@ -736,6 +751,7 @@ static int virtio_vsock_restore(struct virtio_device *vdev)
736751
goto out;
737752

738753
rcu_assign_pointer(the_virtio_vsock, vsock);
754+
virtio_vsock_vqs_start(vsock);
739755

740756
out:
741757
mutex_unlock(&the_virtio_vsock_mutex);

0 commit comments

Comments
 (0)