Skip to contentSkip to conversation

virtio-serial-bus: Unset hotplug handler when unrealize

PATCH In review Ladi Prosek 3 participants 3 messages May 30, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-serial-bus: Unset hotplug handler when unrealize

Virtio serial device controls the lifetime of virtio-serial-bus and virtio-serial-bus links back to the device via its hotplug-handler property. This extra ref-count prevents the device from getting finalized, leaving the VirtIODevice memory listener registered and leading to use-after-free later on.

This patch addresses the same issue as Fam Zheng's "virtio-scsi: Unset hotplug handler when unrealize" only for a different virtio device.

---
 hw/char/virtio-serial-bus.c | 3 +++
 1 file changed, 3 insertions(+)
hw/char/virtio-serial-bus.c +3 -0
index d797a67..aa9c11a 100644
@@ -1121,6 +1121,9 @@ static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp)
         timer_free(vser->post_load->timer);
         g_free(vser->post_load);
     }
+
+    qbus_set_hotplug_handler(BUS(&vser->bus), NULL, errp);
+
     virtio_cleanup(vdev);
 }
 
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Ladi Prosek

Virtio serial device controls the lifetime of virtio-serial-bus and virtio-serial-bus links back to the device via its hotplug-handler property. This extra ref-count prevents the device from getting finalized, leaving the VirtIODevice memory listener registered and leading to use-after-free later on.

This patch addresses the same issue as Fam Zheng's "virtio-scsi: Unset hotplug handler when unrealize" only for a different virtio device.

---
 hw/char/virtio-serial-bus.c | 3 +++
 1 file changed, 3 insertions(+)
hw/char/virtio-serial-bus.c +0 -0
index d797a67..aa9c11a 100644

hw/char/virtio-serial-bus.c static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp) · line 1129

Quoted 9 lines
hw/char/virtio-serial-bus.c +3 -0
@@ -1121,6 +1121,9 @@ static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp)
         timer_free(vser->post_load->timer);
         g_free(vser->post_load);
     }
+
+    qbus_set_hotplug_handler(BUS(&vser->bus), NULL, errp);
+
     virtio_cleanup(vdev);
 }
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ladi Prosek
Quoted 34 lines · Ladi Prosek

Virtio serial device controls the lifetime of virtio-serial-bus and virtio-serial-bus links back to the device via its hotplug-handler property. This extra ref-count prevents the device from getting finalized, leaving the VirtIODevice memory listener registered and leading to use-after-free later on.

This patch addresses the same issue as Fam Zheng's "virtio-scsi: Unset hotplug handler when unrealize" only for a different virtio device.

---
 hw/char/virtio-serial-bus.c | 3 +++
 1 file changed, 3 insertions(+)
hw/char/virtio-serial-bus.c +3 -0
index d797a67..aa9c11a 100644
@@ -1121,6 +1121,9 @@ static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp)
         timer_free(vser->post_load->timer);
         g_free(vser->post_load);
     }
+
+    qbus_set_hotplug_handler(BUS(&vser->bus), NULL, errp);
+
     virtio_cleanup(vdev);
 }
 
Signature · 1 line
2.9.3