thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-qcow2-Use-pread-for-inactive-L1-in-overlap-check.patch

9ae3a8
From 712a6ef0d0d3bbc91953305ad8e7e96f82f19cf0 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Mon, 4 Nov 2013 22:32:27 +0100
9ae3a8
Subject: [PATCH 34/87] qcow2: Use pread for inactive L1 in overlap check
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383604354-12743-37-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55336
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 36/43] qcow2: Use pread for inactive L1 in overlap check
9ae3a8
Bugzilla: 1004347
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1004347
9ae3a8
9ae3a8
Currently, qcow2_check_metadata_overlap uses bdrv_read to read inactive
9ae3a8
L1 tables from disk. The number of sectors to read is calculated through
9ae3a8
a truncating integer division, therefore, if the L1 table size is not a
9ae3a8
multiple of the sector size, the final entries will not be read and
9ae3a8
their entries in memory remain undefined (from the g_malloc).
9ae3a8
Using bdrv_pread fixes this.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 998b959c1e59044f5d5f64c482f4ce8facc8e0bc)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2-refcount.c | 7 +++----
9ae3a8
 1 file changed, 3 insertions(+), 4 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2-refcount.c |    7 +++----
9ae3a8
 1 files changed, 3 insertions(+), 4 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
9ae3a8
index 34fcf2f..5c5683d 100644
9ae3a8
--- a/block/qcow2-refcount.c
9ae3a8
+++ b/block/qcow2-refcount.c
9ae3a8
@@ -1701,12 +1701,11 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int chk, int64_t offset,
9ae3a8
         for (i = 0; i < s->nb_snapshots; i++) {
9ae3a8
             uint64_t l1_ofs = s->snapshots[i].l1_table_offset;
9ae3a8
             uint32_t l1_sz  = s->snapshots[i].l1_size;
9ae3a8
-            uint64_t *l1 = g_malloc(l1_sz * sizeof(uint64_t));
9ae3a8
+            uint64_t l1_sz2 = l1_sz * sizeof(uint64_t);
9ae3a8
+            uint64_t *l1 = g_malloc(l1_sz2);
9ae3a8
             int ret;
9ae3a8
 
9ae3a8
-            ret = bdrv_read(bs->file, l1_ofs / BDRV_SECTOR_SIZE, (uint8_t *)l1,
9ae3a8
-                            l1_sz * sizeof(uint64_t) / BDRV_SECTOR_SIZE);
9ae3a8
-
9ae3a8
+            ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2);
9ae3a8
             if (ret < 0) {
9ae3a8
                 g_free(l1);
9ae3a8
                 return ret;
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8