Skip to contentSkip to conversation

virtio-scsi: Fix hotcpu_notifier use-after-free with virtscsi_freeze

PATCH Applied Jason Wang 2 participants 2 messages Dec 17, 2013 – Jan 14, 2014

Subsystems (5)
Stable branch SCSI KVM virtio core +1 more subsystems
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH v2 1/1 virtio-scsi: Fix hotcpu_notifier use-after-free with virtscsi_freeze

From: Asias He <[email protected]>

vqs are freed in virtscsi_freeze but the hotcpu_notifier is not unregistered. We will have a use-after-free usage when the notifier callback is called after virtscsi_freeze.

Fixes 285e71ea6f3583a85e27cb2b9a7d8c35d4c0d558

("virtio-scsi: reset virtqueue affinity when doing cpu hotplug")

---
Changes from V1:
- Add "Fixes" line
- CC stable

---
 drivers/scsi/virtio_scsi.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/scsi/virtio_scsi.c +14 -1
index c3173dc..16bfd50 100644
@@ -956,6 +956,10 @@ static void virtscsi_remove(struct virtio_device *vdev)
 #ifdef CONFIG_PM_SLEEP
 static int virtscsi_freeze(struct virtio_device *vdev)
 {
+	struct Scsi_Host *sh = virtio_scsi_host(vdev);
+	struct virtio_scsi *vscsi = shost_priv(sh);
+
+	unregister_hotcpu_notifier(&vscsi->nb);
 	virtscsi_remove_vqs(vdev);
 	return 0;
 }
@@ -964,8 +968,17 @@ static int virtscsi_restore(struct virtio_device *vdev)
 {
 	struct Scsi_Host *sh = virtio_scsi_host(vdev);
 	struct virtio_scsi *vscsi = shost_priv(sh);
+	int err;
+
+	err = virtscsi_init(vdev, vscsi);
+	if (err)
+		return err;
+
+	err = register_hotcpu_notifier(&vscsi->nb);
+	if (err)
+		vdev->config->del_vqs(vdev);
 
-	return virtscsi_init(vdev, vscsi);
+	return err;
 }
 #endif
 
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 8 lines · Jason Wang

From: Asias He <[email protected]>

vqs are freed in virtscsi_freeze but the hotcpu_notifier is not unregistered. We will have a use-after-free usage when the notifier callback is called after virtscsi_freeze.

Fixes 285e71ea6f3583a85e27cb2b9a7d8c35d4c0d558

("virtio-scsi: reset virtqueue affinity when doing cpu hotplug")

Sorry, I missed this in my earlier sweep (I was only skimming emails during the break).

Applied,
Rusty.

Quoted 48 lines

---
Changes from V1:
- Add "Fixes" line
- CC stable

---
 drivers/scsi/virtio_scsi.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/scsi/virtio_scsi.c +14 -1
index c3173dc..16bfd50 100644
@@ -956,6 +956,10 @@ static void virtscsi_remove(struct virtio_device *vdev)
 #ifdef CONFIG_PM_SLEEP
 static int virtscsi_freeze(struct virtio_device *vdev)
 {
+	struct Scsi_Host *sh = virtio_scsi_host(vdev);
+	struct virtio_scsi *vscsi = shost_priv(sh);
+
+	unregister_hotcpu_notifier(&vscsi->nb);
 	virtscsi_remove_vqs(vdev);
 	return 0;
 }
@@ -964,8 +968,17 @@ static int virtscsi_restore(struct virtio_device *vdev)
 {
 	struct Scsi_Host *sh = virtio_scsi_host(vdev);
 	struct virtio_scsi *vscsi = shost_priv(sh);
+	int err;
+
+	err = virtscsi_init(vdev, vscsi);
+	if (err)
+		return err;
+
+	err = register_hotcpu_notifier(&vscsi->nb);
+	if (err)
+		vdev->config->del_vqs(vdev);
 
-	return virtscsi_init(vdev, vscsi);
+	return err;
 }
 #endif
 
Signature · 1 line
1.8.3.2