Blame SOURCES/kvm-vmdk-Check-descriptor-file-length-when-reading-it.patch

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