qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, armbru@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH 1.3 2/2] hmp: do not crash on invalid SCSI hotplug
Date: Fri, 23 Nov 2012 16:56:18 +0100	[thread overview]
Message-ID: <1353686178-27520-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1353686178-27520-1-git-send-email-pbonzini@redhat.com>

Commit 0d93692 (qdev: Convert busses to QEMU Object Model, 2012-05-02)
removed a check on the type of the bus where a SCSI disk is hotplugged.
However, hot-plugging to the wrong kind of device now causes a crash
due to either a NULL pointer dereference (avoided by the previous patch)
or a failed QOM cast.

Instead, in this case we need to use object_dynamic_cast and check for
the result, similar to what was done before that commit.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/pci-hotplug.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index e7fb780..0ca5546 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -80,7 +80,13 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
     SCSIBus *scsibus;
     SCSIDevice *scsidev;
 
-    scsibus = SCSI_BUS(QLIST_FIRST(&adapter->child_bus));
+    scsibus = (SCSIBus *)
+        object_dynamic_cast(OBJECT(QLIST_FIRST(&adapter->child_bus)),
+                            TYPE_SCSI_BUS);
+    if (!scsibus) {
+	error_report("Device is not a SCSI adapter");
+	return -1;
+    }
 
     /*
      * drive_init() tries to find a default for dinfo->unit.  Doesn't
-- 
1.8.0

  parent reply	other threads:[~2012-11-23 15:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-23 15:56 [Qemu-devel] [PATCH 1.3 0/2] "drive_add NN if=scsi" fixes Paolo Bonzini
2012-11-23 15:56 ` [Qemu-devel] [PATCH 1.3 1/2] qom: dynamic_cast of NULL is always NULL Paolo Bonzini
2012-11-23 16:16   ` Andreas Färber
2012-11-23 16:25     ` Paolo Bonzini
2012-11-23 16:30       ` Andreas Färber
2012-11-23 16:51         ` Paolo Bonzini
2012-11-23 15:56 ` Paolo Bonzini [this message]
2012-11-26 12:50   ` [Qemu-devel] [PATCH 1.3 2/2] hmp: do not crash on invalid SCSI hotplug Luiz Capitulino
2012-11-26 21:48 ` [Qemu-devel] [PATCH 1.3 0/2] "drive_add NN if=scsi" fixes Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1353686178-27520-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).