QEMU hotplug: check device name in drive_add
PATCH 1/1 QEMU hotplug: check device name in drive_add
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.
Signature · 23 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 [email protected] diffstat output: device-hotplug.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletion(-) Signed-off-by: Ryan Harper <[email protected]> --- 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 <[email protected]>
qemu/hw/device-hotplug.c +13 -1
@@ -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/