Blame SOURCES/kvm-vmdk-Fix-overflow-if-l1_size-is-0x20000000.patch

8be556
From fc2dd801b0a471b15fe8220d132186fa8a6a5588 Mon Sep 17 00:00:00 2001
8be556
From: Fam Zheng <famz@redhat.com>
8be556
Date: Mon, 1 Jun 2015 08:26:45 +0200
8be556
Subject: [PATCH 007/217] vmdk: Fix overflow if l1_size is 0x20000000
8be556
8be556
Message-id: <1433147205-15238-1-git-send-email-famz@redhat.com>
8be556
Patchwork-id: 65161
8be556
O-Subject: [RHEL-7.2 qemu-kvm-rhev PATCH] vmdk: Fix overflow if l1_size is 0x20000000
8be556
Bugzilla: 1226809
8be556
RH-Acked-by: Max Reitz <mreitz@redhat.com>
8be556
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
8be556
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
8be556
8be556
Richard Jones caught this bug with afl fuzzer.
8be556
8be556
In fact, that's the only possible value to overflow (extent->l1_size =
8be556
0x20000000) l1_size:
8be556
8be556
l1_size = extent->l1_size * sizeof(long) => 0x80000000;
8be556
8be556
g_try_malloc returns NULL because l1_size is interpreted as negative
8be556
during type casting from 'int' to 'gsize', which yields a enormous
8be556
value. Hence, by coincidence, we get a "not too bad" behavior:
8be556
8be556
qemu-img: Could not open '/tmp/afl6.img': Could not open
8be556
'/tmp/afl6.img': Cannot allocate memory
8be556
8be556
Values larger than 0x20000000 will be refused by the validation in
8be556
vmdk_add_extent.
8be556
8be556
Values smaller than 0x20000000 will not overflow l1_size.
8be556
8be556
Cc: qemu-stable@nongnu.org
8be556
Reported-by: Richard W.M. Jones <rjones@redhat.com>
8be556
Signed-off-by: Fam Zheng <famz@redhat.com>
8be556
Reviewed-by: Max Reitz <mreitz@redhat.com>
8be556
Tested-by: Richard W.M. Jones <rjones@redhat.com>
8be556
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8be556
(cherry picked from commit 13c4941cdd8685d28c7e3a09e393a5579b58db46)
8be556
Signed-off-by: Fam Zheng <famz@redhat.com>
8be556
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8be556
---
8be556
 block/vmdk.c | 3 ++-
8be556
 1 file changed, 2 insertions(+), 1 deletion(-)
8be556
8be556
diff --git a/block/vmdk.c b/block/vmdk.c
8be556
index 8410a15..214653c 100644
8be556
--- a/block/vmdk.c
8be556
+++ b/block/vmdk.c
8be556
@@ -451,7 +451,8 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,
8be556
                             Error **errp)
8be556
 {
8be556
     int ret;
8be556
-    int l1_size, i;
8be556
+    size_t l1_size;
8be556
+    int i;
8be556
 
8be556
     /* read the L1 table */
8be556
     l1_size = extent->l1_size * sizeof(uint32_t);
8be556
-- 
8be556
1.8.3.1
8be556