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>
Subject: [Qemu-devel] [PULL 2/4] virtio-pci: don't crash on illegal length
Date: Mon, 13 Jul 2015 15:23:43 +0300	[thread overview]
Message-ID: <1436790197-18666-3-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1436790197-18666-1-git-send-email-mst@redhat.com>

Some guests seem to access cfg with an illegal length value.
It's worth fixing them but debugging is easier if
qemu does not crash.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/virtio-pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 6ca0258..c5e8cc0 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -546,7 +546,8 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
         off = le32_to_cpu(cfg->cap.offset);
         len = le32_to_cpu(cfg->cap.length);
 
-        if (len <= sizeof cfg->pci_cfg_data) {
+        if (len == 1 || len == 2 || len == 4) {
+            assert(len <= sizeof cfg->pci_cfg_data);
             virtio_address_space_write(&proxy->modern_as, off,
                                        cfg->pci_cfg_data, len);
         }
@@ -570,7 +571,8 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
         off = le32_to_cpu(cfg->cap.offset);
         len = le32_to_cpu(cfg->cap.length);
 
-        if (len <= sizeof cfg->pci_cfg_data) {
+        if (len == 1 || len == 2 || len == 4) {
+            assert(len <= sizeof cfg->pci_cfg_data);
             virtio_address_space_read(&proxy->modern_as, off,
                                       cfg->pci_cfg_data, len);
         }
-- 
MST

  parent reply	other threads:[~2015-07-13 12:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-13 12:23 [Qemu-devel] [PULL 0/4] pc,virtio: fixes for 2.4 Michael S. Tsirkin
2015-07-13 12:23 ` [Qemu-devel] [PULL 1/4] qdev: fix 64 bit properties Michael S. Tsirkin
2015-07-13 12:23 ` Michael S. Tsirkin [this message]
2015-07-13 12:23 ` [Qemu-devel] [PULL 3/4] Revert "virtio-net: enable virtio 1.0" Michael S. Tsirkin
2015-07-13 12:23 ` [Qemu-devel] [PULL 4/4] pc: fix reuse of pc-i440fx-2.4 in pc-i440fx-2.3 Michael S. Tsirkin
2015-07-13 13:42 ` [Qemu-devel] [PULL 0/4] pc,virtio: fixes for 2.4 Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2015-07-13 12:04 Michael S. Tsirkin
2015-07-13 12:04 ` [Qemu-devel] [PULL 2/4] virtio-pci: don't crash on illegal length 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=1436790197-18666-3-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).