qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark Kanda <mark.kanda@oracle.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: stefanha@redhat.com, karl.heubaum@oracle.com,
	ameya.more@oracle.com, Mark Kanda <mark.kanda@oracle.com>
Subject: [Qemu-devel] [PATCH] virtio-blk: check for NULL BlockDriverState
Date: Mon, 22 Jan 2018 09:01:49 -0600	[thread overview]
Message-ID: <1516633309-20803-1-git-send-email-mark.kanda@oracle.com> (raw)

Add a BlockDriverState NULL check to virtio_blk_handle_request()
to prevent a segfault if the drive is forcibly removed using HMP
'drive_del' (without performing a hotplug 'device_del' first).

Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
Reviewed-by: Ameya More <ameya.more@oracle.com>
---
 hw/block/virtio-blk.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index b1532e4..76ddbbf 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -507,6 +507,13 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
         return -1;
     }
 
+    /* If the drive was forcibly removed (e.g. HMP 'drive_del'), the block
+     * driver state may be NULL and there is nothing left to do. */
+    if (!blk_bs(req->dev->blk)) {
+        virtio_error(vdev, "virtio-blk BlockDriverState is NULL");
+        return -1;
+    }
+
     /* We always touch the last byte, so just see how big in_iov is.  */
     req->in_len = iov_size(in_iov, in_num);
     req->in = (void *)in_iov[in_num - 1].iov_base
-- 
1.8.3.1

             reply	other threads:[~2018-01-22 15:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 15:01 Mark Kanda [this message]
2018-01-24 11:31 ` [Qemu-devel] [PATCH] virtio-blk: check for NULL BlockDriverState Stefan Hajnoczi
2018-01-29 15:41   ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2018-01-29 16:13     ` Mark Kanda
2018-02-01 17:58       ` Stefan Hajnoczi
2018-01-30 12:38     ` Stefan Hajnoczi
2018-01-30 15:56       ` Kevin Wolf
2018-01-30 19:04         ` John Snow
2018-02-01 18:00         ` Stefan Hajnoczi

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=1516633309-20803-1-git-send-email-mark.kanda@oracle.com \
    --to=mark.kanda@oracle.com \
    --cc=ameya.more@oracle.com \
    --cc=karl.heubaum@oracle.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).