public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] QEMU hotplug: check device name in drive_add
@ 2008-03-20 21:21 Ryan Harper
  0 siblings, 0 replies; only message in thread
From: Ryan Harper @ 2008-03-20 21:21 UTC (permalink / raw)
  To: kvm-devel

Using drive_add with bogus devfn values would segfault QEMU when
attempting to add scsi devices.  Attached patch checks in hotplug code
for appropriate devices that drive_add() will work with (looking before
leaping) and bails if you don't specify a proper device with your
bus,devfn.

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
ryanh@us.ibm.com


diffstat output:
 device-hotplug.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletion(-)

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
---
When using drive_add in the QEMU monitor, if one specifies a bogus devfn to the
command while specifying a scsi disk (if=scsi), then QEMU segfaults due to
issues with getting a valid return from find_pci_dev, and vl.c setting unit_id=0
avoiding lsi_scsi_attach's check for a controller.  Rather than muck through the
unit_id calculation (which does make sense for the case that users don't specify
a unit_id), in drive_add() we know that we only support the SCSI
controller and virtio_blk, so ignore any devfn that doesn't point to either type
of device.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>

diff --git a/qemu/hw/device-hotplug.c b/qemu/hw/device-hotplug.c
index 98a467c..a717d9b 100644
--- a/qemu/hw/device-hotplug.c
+++ b/qemu/hw/device-hotplug.c
@@ -55,7 +55,7 @@ void drive_hot_add(int pcibus, const char *devfn_string, const char *opts)
 {
     int drive_idx, type, bus;
     int devfn;
-    int success = 0;
+    int success = 0, valid_dev = 0;
     PCIDevice *dev;
 
     devfn = strtoul(devfn_string, NULL, 0);
@@ -67,6 +67,18 @@ void drive_hot_add(int pcibus, const char *devfn_string, const char *opts)
         return;
     }
 
+    if (!strcmp(dev->name, "LSI53C895A SCSI HBA")) {
+        valid_dev = 1;
+    } else if (!strcmp(dev->name, "virtio-blk")) {
+        valid_dev = 1;
+    }
+
+    if (!valid_dev) {
+        term_printf("Invalid PCI Device specified by bus:%d devfn:%d\n",
+                    pcibus, devfn);
+        return;
+    }
+
     drive_idx = add_init_drive(opts);
     if (drive_idx < 0)
         return;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-20 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-20 21:21 [PATCH] QEMU hotplug: check device name in drive_add Ryan Harper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox