thebeanogamer / rpms / qemu-kvm

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