qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH] qed: limit to image size in qed_find_cluster()
Date: Mon, 28 Nov 2011 16:18:20 +0000	[thread overview]
Message-ID: <1322497100-24167-1-git-send-email-stefanha@linux.vnet.ibm.com> (raw)

Callers of bdrv_is_allocated() may go beyond the end of the image.  For
general robustness we should limit to the end of the image so that
callers don't end up using out-of-range sector counts and receive -EIO.

This fix will allow the image streaming to terminate successfully.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block/qed-cluster.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/block/qed-cluster.c b/block/qed-cluster.c
index f64b2af..4632b32 100644
--- a/block/qed-cluster.c
+++ b/block/qed-cluster.c
@@ -142,6 +142,9 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
      */
     len = MIN(len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos);
 
+    /* Limit length to image size */
+    len = MIN(len, s->header.image_size - pos);
+
     l2_offset = s->l1_table->offsets[qed_l1_index(s, pos)];
     if (qed_offset_is_unalloc_cluster(l2_offset)) {
         cb(opaque, QED_CLUSTER_L1, 0, len);
-- 
1.7.7.3

             reply	other threads:[~2011-11-28 16:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28 16:18 Stefan Hajnoczi [this message]
2011-11-29  5:01 ` [Qemu-devel] [PATCH] qed: limit to image size in qed_find_cluster() Mark Wu
2011-11-29 13:29   ` 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=1322497100-24167-1-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=kwolf@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).