f375e62
From 7c0aea40a3318d914d791f23a85d0c488cae60fe Mon Sep 17 00:00:00 2001
f375e62
From: Paolo Bonzini <pbonzini@redhat.com>
f375e62
Date: Fri, 23 Nov 2012 16:56:18 +0100
f375e62
Subject: [PATCH] hmp: do not crash on invalid SCSI hotplug
f375e62
f375e62
Commit 0d93692 (qdev: Convert busses to QEMU Object Model, 2012-05-02)
f375e62
removed a check on the type of the bus where a SCSI disk is hotplugged.
f375e62
However, hot-plugging to the wrong kind of device now causes a crash
f375e62
due to either a NULL pointer dereference (avoided by the previous patch)
f375e62
or a failed QOM cast.
f375e62
f375e62
Instead, in this case we need to use object_dynamic_cast and check for
f375e62
the result, similar to what was done before that commit.
f375e62
f375e62
Reported-by: Markus Armbruster <armbru@redhat.com>
f375e62
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
f375e62
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
f375e62
(cherry picked from commit b5007bcc9729acd995518c52eb1038c4d8416b5d)
f375e62
f375e62
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
f375e62
---
f375e62
 hw/pci-hotplug.c | 8 +++++++-
f375e62
 1 file changed, 7 insertions(+), 1 deletion(-)
f375e62
f375e62
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
f375e62
index e7fb780..0ca5546 100644
f375e62
--- a/hw/pci-hotplug.c
f375e62
+++ b/hw/pci-hotplug.c
f375e62
@@ -80,7 +80,13 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
f375e62
     SCSIBus *scsibus;
f375e62
     SCSIDevice *scsidev;
f375e62
 
f375e62
-    scsibus = SCSI_BUS(QLIST_FIRST(&adapter->child_bus));
f375e62
+    scsibus = (SCSIBus *)
f375e62
+        object_dynamic_cast(OBJECT(QLIST_FIRST(&adapter->child_bus)),
f375e62
+                            TYPE_SCSI_BUS);
f375e62
+    if (!scsibus) {
f375e62
+	error_report("Device is not a SCSI adapter");
f375e62
+	return -1;
f375e62
+    }
f375e62
 
f375e62
     /*
f375e62
      * drive_init() tries to find a default for dinfo->unit.  Doesn't