Skip to contentSkip to conversation

scsi/virio_scsi.c: do not call virtscsi_remove_vqs() in virtscsi_init() to avoid crash bug

PATCH In review piaojun 2 participants 2 messages Aug 23, 2018 – Oct 12, 2018

Subsystems (3)
lore
Share & tools
lore

piaojun

author
#0 lore raw

PATCH 1/1 scsi/virio_scsi.c: do not call virtscsi_remove_vqs() in virtscsi_init() to avoid crash bug

If some error happened before find_vqs, error branch will goto virtscsi_remove_vqs to free vqs. Actually the vqs have not been allocated successfully, so this will cause wild-pointer-free problem. So virtscsi_remove_vqs could be deleted as no error will happen after find_vqs.

---
 drivers/scsi/virtio_scsi.c | 2 --
 1 file changed, 2 deletions(-)
drivers/scsi/virtio_scsi.c +0 -2
index 1c72db9..da0fd74 100644
@@ -833,8 +833,6 @@ static int virtscsi_init(struct virtio_device *vdev,
 	kfree(names);
 	kfree(callbacks);
 	kfree(vqs);
-	if (err)
-		virtscsi_remove_vqs(vdev);
 	return err;
 }
 
#1 lore raw
Quoted 16 lines · piaojun

If some error happened before find_vqs, error branch will goto virtscsi_remove_vqs to free vqs. Actually the vqs have not been allocated successfully, so this will cause wild-pointer-free problem. So virtscsi_remove_vqs could be deleted as no error will happen after find_vqs.

---
 drivers/scsi/virtio_scsi.c | 2 --
 1 file changed, 2 deletions(-)
drivers/scsi/virtio_scsi.c +0 -0
index 1c72db9..da0fd74 100644

drivers/scsi/virtio_scsi.c static int virtscsi_init(struct virtio_device *vdev, · line 837

Quoted 5 lines
drivers/scsi/virtio_scsi.c +0 -2
@@ -833,8 +833,6 @@ static int virtscsi_init(struct virtio_device *vdev,
 	kfree(names);
 	kfree(callbacks);
 	kfree(vqs);
-	if (err)
-		virtscsi_remove_vqs(vdev);

Can you provide more details about the problem?

drivers/virtio/virtio_pci_common.c:vp_del_vqs() looks fine to me, it iterates over vdev->vqs. The vdev->vqs list has been initialized in drivers/virtio/virtio.c:register_virtio_device() and it's empty.

Stefan