vdpa: fix use-after-free of vqs in vhost_vdpa_device_unrealize
PATCH 1/1 vdpa: fix use-after-free of vqs in vhost_vdpa_device_unrealize
From: lizhaoxin04 <[email protected]>
vhost_vdpa_device_unrealize() frees s->dev.vqs before vhost_dev_cleanup(), but vhost_dev_cleanup() still accesses hdev->vqs while tearing down virtqueues. This leads to a use-after-free and may crash QEMU with SIGSEGV during vDPA hot-unplug.
Save the vqs pointer in a local variable, call vhost_dev_cleanup(), and free it afterward. This matches the cleanup pattern used by vhost-scsi.
Fixes b430a2bd23 ("vdpa: add vdpa-dev support")
Co-developed-by Miao Kezhan <[email protected]>
Signed-off-by Li Zhaoxin <[email protected]>
--- hw/virtio/vdpa-dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/vdpa-dev.c +2 -1
@@ -172,6 +172,7 @@ static void vhost_vdpa_device_unrealize(DeviceState *dev) {VirtIODevice *vdev =VIRTIO_DEVICE (dev);VhostVdpaDevice *s =VHOST_VDPA_DEVICE (vdev); +struct vhost_virtqueue *vqs = s->dev.vqs;int i;virtio_set_status (vdev,0 );
@@ -183,8 +184,8 @@ static void vhost_vdpa_device_unrealize(DeviceState *dev)virtio_cleanup (vdev);g_free (s->config); -g_free (s->dev.vqs);vhost_dev_cleanup (&s->dev); +g_free (vqs);g_free (s->vdpa.shared);qemu_close (s->vhostfd); s->vhostfd =-1 ;
Signature · 1 line
2.17.1