thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
34b321
From 86c71987b64382e1177f86e6bc00bfc19e20082d Mon Sep 17 00:00:00 2001
34b321
From: Fam Zheng <famz@redhat.com>
34b321
Date: Mon, 15 Feb 2016 09:28:18 +0100
34b321
Subject: [PATCH 05/18] vmdk: Check descriptor file length when reading it
34b321
34b321
RH-Author: Fam Zheng <famz@redhat.com>
34b321
Message-id: <1455528511-9357-6-git-send-email-famz@redhat.com>
34b321
Patchwork-id: 69171
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH 05/18] vmdk: Check descriptor file length when reading it
34b321
Bugzilla: 1299250
34b321
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
34b321
34b321
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1299250
34b321
34b321
Since a too small file cannot be a valid VMDK image, and also since the
34b321
buffer's first 4 bytes will be unconditionally examined by
34b321
vmdk_open_sparse, let's error out the small file case to be clear.
34b321
34b321
Signed-off-by: Fam Zheng <famz@redhat.com>
34b321
Reviewed-by: Max Reitz <mreitz@redhat.com>
34b321
Reviewed-by: Markus Armbruster <armbru@redhat.com>
34b321
Reviewed-by: Don Koch <dkoch@verizon.com>
34b321
Message-id: 1417649314-13704-5-git-send-email-famz@redhat.com
34b321
Signed-off-by: Max Reitz <mreitz@redhat.com>
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
(cherry picked from commit 03c3359dfc490eaf922f88955d6a8cc51a37ce92)
34b321
Signed-off-by: Fam Zheng <famz@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 block/vmdk.c | 8 ++++++++
34b321
 1 file changed, 8 insertions(+)
34b321
34b321
diff --git a/block/vmdk.c b/block/vmdk.c
34b321
index 3dfbd41..db3cdc0 100644
34b321
--- a/block/vmdk.c
34b321
+++ b/block/vmdk.c
34b321
@@ -559,6 +559,14 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
34b321
         return NULL;
34b321
     }
34b321
 
34b321
+    if (size < 4) {
34b321
+        /* Both descriptor file and sparse image must be much larger than 4
34b321
+         * bytes, also callers of vmdk_read_desc want to compare the first 4
34b321
+         * bytes with VMDK4_MAGIC, let's error out if less is read. */
34b321
+        error_setg(errp, "File is too small, not a valid image");
34b321
+        return NULL;
34b321
+    }
34b321
+
34b321
     size = MIN(size, (1 << 20) - 1);  /* avoid unbounded allocation */
34b321
     buf = g_malloc(size + 1);
34b321
 
34b321
-- 
34b321
1.8.3.1
34b321