From e681df92e8b35497dbb3ce2c57fcd9f386f72046 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Fri, 2 May 2014 16:58:48 -0500 Subject: [PATCH 16/26] qcow2: Use pread for inactive L1 in overlap check RH-Author: Max Reitz Message-id: <1399049936-13496-17-git-send-email-mreitz@redhat.com> Patchwork-id: 58662 O-Subject: [RHEL-6.6 qemu-kvm PATCH v3 16/24] qcow2: Use pread for inactive L1 in overlap check Bugzilla: 1004420 RH-Acked-by: Laszlo Ersek RH-Acked-by: Kevin Wolf RH-Acked-by: Stefan Hajnoczi BZ: 1004420 Currently, qcow2_check_metadata_overlap uses bdrv_read to read inactive L1 tables from disk. The number of sectors to read is calculated through a truncating integer division, therefore, if the L1 table size is not a multiple of the sector size, the final entries will not be read and their entries in memory remain undefined (from the g_malloc). Using bdrv_pread fixes this. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf (cherry picked from commit 998b959c1e59044f5d5f64c482f4ce8facc8e0bc) Signed-off-by: Max Reitz --- block/qcow2-refcount.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) Signed-off-by: Jeff E. Nelson --- block/qcow2-refcount.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 367f3c8..67a8c9b 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1558,12 +1558,11 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int chk, int64_t offset, for (i = 0; i < s->nb_snapshots; i++) { uint64_t l1_ofs = s->snapshots[i].l1_table_offset; uint32_t l1_sz = s->snapshots[i].l1_size; - uint64_t *l1 = g_malloc(l1_sz * sizeof(uint64_t)); + uint64_t l1_sz2 = l1_sz * sizeof(uint64_t); + uint64_t *l1 = g_malloc(l1_sz2); int ret; - ret = bdrv_read(bs->file, l1_ofs / BDRV_SECTOR_SIZE, (uint8_t *)l1, - l1_sz * sizeof(uint64_t) / BDRV_SECTOR_SIZE); - + ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2); if (ret < 0) { g_free(l1); return ret; -- 1.7.1