From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Alistair Francis <alistair.francis@xilinx.com>
Subject: [Qemu-devel] [PULL v2 5/5] sdhci.c: Limit the maximum block size
Date: Mon, 12 Oct 2015 11:23:05 +0100	[thread overview]
Message-ID: <1444645385-24009-6-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1444645385-24009-1-git-send-email-stefanha@redhat.com>
From: Alistair Francis <alistair.francis@xilinx.com>
It is possible for the guest to set an invalid block
size which is larger then the fifo_buffer[] array. This
could cause a buffer overflow.
To avoid this limit the maximum size of the blksize variable.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Reported-by: Intel Security ATR <secure@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Message-id: abe4c51f513290bbb85d1ee271cb1a3d463d7561.1444067470.git.alistair.francis@xilinx.com
Suggested-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Reported-by: Intel Security ATR <secure@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/sd/sdhci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 7f9d814..7f73527 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1009,6 +1009,16 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
             MASKED_WRITE(s->blksize, mask, value);
             MASKED_WRITE(s->blkcnt, mask >> 16, value >> 16);
         }
+
+        /* Limit block size to the maximum buffer size */
+        if (extract32(s->blksize, 0, 12) > s->buf_maxsz) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: Size 0x%x is larger than " \
+                          "the maximum buffer 0x%x", __func__, s->blksize,
+                          s->buf_maxsz);
+
+            s->blksize = deposit32(s->blksize, 0, 12, s->buf_maxsz);
+        }
+
         break;
     case SDHC_ARGUMENT:
         MASKED_WRITE(s->argument, mask, value);
-- 
2.4.3
next prev parent reply	other threads:[~2015-10-12 10:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-12 10:23 [Qemu-devel] [PULL v2 0/5] Block patches Stefan Hajnoczi
2015-10-12 10:23 ` [Qemu-devel] [PULL v2 1/5] sdhci: Pass drive parameter to sdhci-pci via qdev property Stefan Hajnoczi
2015-10-12 10:23 ` [Qemu-devel] [PULL v2 2/5] virtio-blk: use blk_io_plug/unplug for Linux AIO batching Stefan Hajnoczi
2015-10-12 10:23 ` [Qemu-devel] [PULL v2 3/5] virtio dataplane: adapt dataplane for virtio Version 1 Stefan Hajnoczi
2015-10-12 10:23 ` [Qemu-devel] [PULL v2 4/5] block: switch from g_slice allocator to malloc Stefan Hajnoczi
2015-10-12 10:23 ` Stefan Hajnoczi [this message]
2015-10-12 15:52 ` [Qemu-devel] [PULL v2 0/5] Block patches Peter Maydell
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=1444645385-24009-6-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=alistair.francis@xilinx.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).