thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
Blob Blame History Raw
From f9f07bb61d34fb0f05a4072a201f879bc7b97ac3 Mon Sep 17 00:00:00 2001
From: Fam Zheng <famz@redhat.com>
Date: Tue, 13 Jun 2017 06:08:30 +0200
Subject: [PATCH 13/13] virtio-scsi: Unset hotplug handler when unrealize

RH-Author: Fam Zheng <famz@redhat.com>
Message-id: <20170613060830.4729-1-famz@redhat.com>
Patchwork-id: 75595
O-Subject: [RHV-7.4 qemu-kvm-rhev PATCH] virtio-scsi: Unset hotplug handler when unrealize
Bugzilla: 1449031
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Ladi Prosek <lprosek@redhat.com>
RH-Acked-by: Thomas Huth <thuth@redhat.com>

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1449031
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=13409468

This matches the qbus_set_hotplug_handler in realize, and it releases
the final reference to the embedded VirtIODevice so that it is
properly finalized.

A use-after-free is fixed with this patch, indirectly:
virtio_device_instance_finalize wasn't called at hot-unplug, and the
vdev->listener would be a dangling pointer in the global and the per
address space listener list. See also RHBZ 1449031.

Cc: qemu-stable@nongnu.org
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170518102808.30046-1-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 2cbe2de5454cf9af44b620b2b40d56361a12a45f)
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 hw/scsi/virtio-scsi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index bd62d08..cb1c123 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -915,6 +915,9 @@ void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
 
 static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
 {
+    VirtIOSCSI *s = VIRTIO_SCSI(dev);
+
+    qbus_set_hotplug_handler(BUS(&s->bus), NULL, &error_abort);
     virtio_scsi_common_unrealize(dev, errp);
 }
 
-- 
1.8.3.1