Skip to contentSkip to conversation

virtio: guard vring access when setting notification

PATCH New Cornelia Huck 1 participant 1 message Mar 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 virtio: guard vring access when setting notification

Switching to vring caches exposed an existing bug in virtio_queue_set_notification(): We can't access vring structures if they have not been set up yet. This may happen, for example, for virtio-blk devices with multiple queues: The code will try to switch notifiers for every queue, but the guest may have only set up a subset of them.

Fix this by guarding access to the vring memory by checking for vring.desc. The first aio poll will iron out any remaining inconsistencies for later-configured queues (buggy legacy drivers).

---
v2->v3:
- Switch to a very simple check for !desc, which should be fine for the existing users.

We might want to assert that callers don't start aio before DRIVER_OK resp. first kick, but that can wait until after we've fixed this bug.

---
 hw/virtio/virtio.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/virtio/virtio.c +4 -0
index e487e36..bf8a644 100644
@@ -288,6 +288,10 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
 
+    if (!vq->vring.desc) {
+        return;
+    }
+
     rcu_read_lock();
     if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vring_avail_idx(vq));
Signature · 1 line
2.8.4