[Qemu-devel] [PATCH] virtio-serial-bus: Unset hotplug handler when unrealize

Ladi Prosek posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170530085943.18141-1-lprosek@redhat.com
Test checkpatch passed
Test docker passed
Test s390x passed
hw/char/virtio-serial-bus.c | 3 +++
1 file changed, 3 insertions(+)
[Qemu-devel] [PATCH] virtio-serial-bus: Unset hotplug handler when unrealize
Posted by Ladi Prosek 6 years, 10 months ago
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.

Cc: qemu-stable@nongnu.org
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
---
 hw/char/virtio-serial-bus.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index d797a67..aa9c11a 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -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);
 }
 
-- 
2.9.3


Re: [Qemu-devel] [PATCH] virtio-serial-bus: Unset hotplug handler when unrealize
Posted by Paolo Bonzini 6 years, 10 months ago

On 30/05/2017 10:59, Ladi Prosek wrote:
> 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.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Ladi Prosek <lprosek@redhat.com>
> ---
>  hw/char/virtio-serial-bus.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index d797a67..aa9c11a 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -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: Paolo Bonzini <pbonzini@redhat.com>

Re: [Qemu-devel] [PATCH] virtio-serial-bus: Unset hotplug handler when unrealize
Posted by Fam Zheng 6 years, 10 months ago
On Tue, 05/30 10:59, Ladi Prosek wrote:
> 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.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Ladi Prosek <lprosek@redhat.com>
> ---
>  hw/char/virtio-serial-bus.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index d797a67..aa9c11a 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -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);
>  }
>  
> -- 
> 2.9.3
> 
> 

Reviewed-by: Fam Zheng <famz@redhat.com>