qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
Cc: Kevin Wolf <kwolf@redhat.com>, "Denis V. Lunev" <den@openvz.org>,
	Jeff Cody <jcody@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 3/9] block/parallels: fix access to not initialized memory in catalog_bitmap
Date: Mon, 27 Oct 2014 12:07:06 +0300	[thread overview]
Message-ID: <1414400832-17798-4-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1414400832-17798-1-git-send-email-den@openvz.org>

found by valgrind.

Command: ./qemu-img convert -f parallels -O qcow2 1.hds 1.img
Invalid read of size 4
   at 0x17D0EF: parallels_co_read (parallels.c:357)
   by 0x11FEE4: bdrv_aio_rw_vector (block.c:4640)
   by 0x11FFBF: bdrv_aio_readv_em (block.c:4652)
   by 0x11F55F: bdrv_co_readv_em (block.c:4862)
   by 0x123428: bdrv_aligned_preadv (block.c:3056)
   by 0x1239FA: bdrv_co_do_preadv (block.c:3162)
   by 0x125424: bdrv_rw_co_entry (block.c:2706)
   by 0x155DD9: coroutine_trampoline (coroutine-ucontext.c:118)
   by 0x6975B6F: ??? (in /lib/x86_64-linux-gnu/libc-2.19.so)

The problem is that s->catalog_bitmap is allocated/filled as
gmalloc(s->catalog_size) thus index validity check must be
inclusive, i.e. index >= s->catalog_size is invalid.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
CC: Jeff Cody <jcody@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/parallels.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/parallels.c b/block/parallels.c
index 2a814f3..4f9cd8d 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -155,7 +155,7 @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
     offset = sector_num % s->tracks;
 
     /* not allocated */
-    if ((index > s->catalog_size) || (s->catalog_bitmap[index] == 0))
+    if ((index >= s->catalog_size) || (s->catalog_bitmap[index] == 0))
         return -1;
     return
         ((uint64_t)s->catalog_bitmap[index] * s->off_multiplier + offset) * 512;
-- 
1.9.1

  parent reply	other threads:[~2014-10-27  9:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-27  9:07 [Qemu-devel] [PATCH 0/9] parallels format support improvements Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 1/9] iotests: replace fake parallels image with authentic one Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 2/9] iotests: add v2 parallels sample image and simple test for it Denis V. Lunev
2014-10-27  9:07 ` Denis V. Lunev [this message]
2014-10-27  9:07 ` [Qemu-devel] [PATCH 4/9] configure: add dependency from libxml2 Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 5/9] block/parallels: allow to specify DiskDescriptor.xml instead of image file Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 6/9] iotests: simple parallels XML disk descriptor file test added Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 7/9] block/parallels: support padded Parallels images Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 8/9] iotests: padded parallels image test Denis V. Lunev
2014-10-27  9:07 ` [Qemu-devel] [PATCH 9/9] parallels: change copyright information in the image header Denis V. Lunev

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=1414400832-17798-4-git-send-email-den@openvz.org \
    --to=den@openvz.org \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --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).