yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qcow2-Do-not-overflow-when-writing-an-L1-sector.patch

9ae3a8
From 5cefc50d497d347c2352d785657b04db99e06ec8 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Sat, 13 Jun 2015 16:22:07 +0200
9ae3a8
Subject: [PATCH 13/42] qcow2: Do not overflow when writing an L1 sector
9ae3a8
9ae3a8
Message-id: <1434212556-3927-14-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 66032
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH 13/42] qcow2: Do not overflow when writing an L1 sector
9ae3a8
Bugzilla: 1129893
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1129893
9ae3a8
9ae3a8
While writing an L1 table sector, qcow2_write_l1_entry() copies the
9ae3a8
respective range from s->l1_table to the local "buf" array. The size of
9ae3a8
s->l1_table does not have to be a multiple of L1_ENTRIES_PER_SECTOR;
9ae3a8
thus, limit the index which is used for copying all entries to the L1
9ae3a8
size.
9ae3a8
9ae3a8
Cc: qemu-stable@nongnu.org
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Peter Lieven <pl@kamp.de>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit a1391444fe1cfef14976458f3293a2c6945e725c)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2-cluster.c | 6 ++++--
9ae3a8
 1 file changed, 4 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
9ae3a8
index 0e3b8d7..053e9fe 100644
9ae3a8
--- a/block/qcow2-cluster.c
9ae3a8
+++ b/block/qcow2-cluster.c
9ae3a8
@@ -151,12 +151,14 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
9ae3a8
 int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index)
9ae3a8
 {
9ae3a8
     BDRVQcowState *s = bs->opaque;
9ae3a8
-    uint64_t buf[L1_ENTRIES_PER_SECTOR];
9ae3a8
+    uint64_t buf[L1_ENTRIES_PER_SECTOR] = { 0 };
9ae3a8
     int l1_start_index;
9ae3a8
     int i, ret;
9ae3a8
 
9ae3a8
     l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR - 1);
9ae3a8
-    for (i = 0; i < L1_ENTRIES_PER_SECTOR; i++) {
9ae3a8
+    for (i = 0; i < L1_ENTRIES_PER_SECTOR && l1_start_index + i < s->l1_size;
9ae3a8
+         i++)
9ae3a8
+    {
9ae3a8
         buf[i] = cpu_to_be64(s->l1_table[l1_start_index + i]);
9ae3a8
     }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8