viommu_probe() marks the device DRIVER_OK before populating the event
virtqueue and registering the IOMMU device in sysfs. If either operation
fails, the error path deletes the virtqueues while the device is still
live. The device may therefore continue accessing queue memory after it
has been freed.

Reset the device on error paths after DRIVER_OK before deleting the
virtqueues, matching viommu_remove().

Fixes: edcd69ab9a32 ("iommu: Add virtio-iommu driver")
Signed-off-by: Yuho Choi <[email protected]>
---
 drivers/iommu/virtio-iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 587fc13197f12..fa72ae23b8afa 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1227,12 +1227,12 @@ static int viommu_probe(struct virtio_device *vdev)
        /* Populate the event queue with buffers */
        ret = viommu_fill_evtq(viommu);
        if (ret)
-               goto err_free_vqs;
+               goto err_reset_vdev;
 
        ret = iommu_device_sysfs_add(&viommu->iommu, dev, NULL, "%s",
                                     virtio_bus_name(vdev));
        if (ret)
-               goto err_free_vqs;
+               goto err_reset_vdev;
 
        vdev->priv = viommu;
 
@@ -1244,6 +1244,8 @@ static int viommu_probe(struct virtio_device *vdev)
 
        return 0;
 
+err_reset_vdev:
+       virtio_reset_device(vdev);
 err_free_vqs:
        vdev->config->del_vqs(vdev);
 
-- 
2.43.0


Reply via email to