qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Prasad J Pandit <pjp@fedoraproject.org>,
	Zhangboxian <zhangboxian@huawei.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>
Subject: [Qemu-devel] [PULL 6/7] virtio: check VirtQueue Vring object is set
Date: Fri, 1 Dec 2017 19:08:53 +0200	[thread overview]
Message-ID: <1512148088-28733-7-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1512148088-28733-1-git-send-email-mst@redhat.com>

From: Prasad J Pandit <pjp@fedoraproject.org>

A guest could attempt to use an uninitialised VirtQueue object
or unset Vring.align leading to a arithmetic exception. Add check
to avoid it.

Reported-by: Zhangboxian <zhangboxian@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 hw/virtio/virtio.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 703e672..ad564b0 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -182,7 +182,7 @@ void virtio_queue_update_rings(VirtIODevice *vdev, int n)
 {
     VRing *vring = &vdev->vq[n].vring;
 
-    if (!vring->desc) {
+    if (!vring->num || !vring->desc || !vring->align) {
         /* not yet setup -> nothing to do */
         return;
     }
@@ -1414,6 +1414,9 @@ void virtio_config_modern_writel(VirtIODevice *vdev,
 
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
 {
+    if (!vdev->vq[n].vring.num) {
+        return;
+    }
     vdev->vq[n].vring.desc = addr;
     virtio_queue_update_rings(vdev, n);
 }
@@ -1426,6 +1429,9 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
 void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc,
                             hwaddr avail, hwaddr used)
 {
+    if (!vdev->vq[n].vring.num) {
+        return;
+    }
     vdev->vq[n].vring.desc = desc;
     vdev->vq[n].vring.avail = avail;
     vdev->vq[n].vring.used = used;
@@ -1494,8 +1500,10 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
      */
     assert(k->has_variable_vring_alignment);
 
-    vdev->vq[n].vring.align = align;
-    virtio_queue_update_rings(vdev, n);
+    if (align) {
+        vdev->vq[n].vring.align = align;
+        virtio_queue_update_rings(vdev, n);
+    }
 }
 
 static bool virtio_queue_notify_aio_vq(VirtQueue *vq)
-- 
MST

  parent reply	other threads:[~2017-12-01 17:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01 17:08 [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3 Michael S. Tsirkin
2017-12-01 17:08 ` [Qemu-devel] [PULL 1/7] i386/msi: Correct mask of destination ID in MSI address Michael S. Tsirkin
2017-12-01 17:08 ` [Qemu-devel] [PULL 2/7] virtio: Add queue interface to restore avail index from vring used index Michael S. Tsirkin
2017-12-01 17:08 ` [Qemu-devel] [PULL 3/7] vhost: restore avail index from vring used index on disconnection Michael S. Tsirkin
2017-12-01 17:08 ` [Qemu-devel] [PULL 4/7] dump-guest-memory.py: fix No symbol "vmcoreinfo_find" Michael S. Tsirkin
2017-12-01 17:08 ` [Qemu-devel] [PULL 5/7] vhost: fix error check in vhost_verify_ring_mappings() Michael S. Tsirkin
2017-12-01 17:08 ` Michael S. Tsirkin [this message]
2017-12-01 17:09 ` [Qemu-devel] [PULL 7/7] pc: fix crash on attempted cpu unplug Michael S. Tsirkin
2017-12-01 18:05 ` [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3 Peter Maydell
2017-12-03  4:56   ` Michael S. Tsirkin
2017-12-04 10:16     ` Peter Maydell
2017-12-04 17:18       ` Peter Maydell
2017-12-05  0:56       ` Michael S. Tsirkin

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=1512148088-28733-7-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=zhangboxian@huawei.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).