thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-vdi-add-bounds-checks-for-blocks_in_image-and-disk_s.patch

0a122b
From 6ce116dda5d5a7708d660e32713ff40fc3f749ef Mon Sep 17 00:00:00 2001
0a122b
From: Jeff Cody <jcody@redhat.com>
0a122b
Date: Tue, 25 Mar 2014 14:23:24 +0100
0a122b
Subject: [PATCH 17/49] vdi: add bounds checks for blocks_in_image and disk_size header fields (CVE-2014-0144)
0a122b
0a122b
RH-Author: Kevin Wolf <kwolf@redhat.com>
0a122b
Message-id: <1395753835-7591-18-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: n/a
0a122b
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 17/48] vdi: add bounds checks for blocks_in_image and disk_size header fields (CVE-2014-0144)
0a122b
Bugzilla: 1079455
0a122b
RH-Acked-by: Jeff Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
From: Jeff Cody <jcody@redhat.com>
0a122b
0a122b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1079455
0a122b
Upstream status: Embargoed
0a122b
0a122b
The maximum blocks_in_image is 0xffffffff / 4, which also limits the
0a122b
maximum disk_size for a VDI image.
0a122b
0a122b
Signed-off-by: Jeff Cody <jcody@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
block/vdi.c
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block/vdi.c |   26 ++++++++++++++++++++++++--
0a122b
 1 files changed, 24 insertions(+), 2 deletions(-)
0a122b
0a122b
diff --git a/block/vdi.c b/block/vdi.c
0a122b
index f973883..0457298 100644
0a122b
--- a/block/vdi.c
0a122b
+++ b/block/vdi.c
0a122b
@@ -120,6 +120,12 @@ typedef unsigned char uuid_t[16];
0a122b
 
0a122b
 #define VDI_IS_ALLOCATED(X) ((X) < VDI_DISCARDED)
0a122b
 
0a122b
+#define VDI_BLOCK_SIZE           (1 * MiB)
0a122b
+/* max blocks in image is (0xffffffff / 4) */
0a122b
+#define VDI_BLOCKS_IN_IMAGE_MAX  0x3fffffff
0a122b
+#define VDI_DISK_SIZE_MAX        ((uint64_t)VDI_BLOCKS_IN_IMAGE_MAX * \
0a122b
+                                  (uint64_t)VDI_BLOCK_SIZE)
0a122b
+
0a122b
 #if !defined(CONFIG_UUID)
0a122b
 static inline void uuid_generate(uuid_t out)
0a122b
 {
0a122b
@@ -385,6 +391,11 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
     vdi_header_print(&header);
0a122b
 #endif
0a122b
 
0a122b
+    if (header.disk_size > VDI_DISK_SIZE_MAX) {
0a122b
+        ret = -EINVAL;
0a122b
+        goto fail;
0a122b
+    }
0a122b
+
0a122b
     if (header.disk_size % SECTOR_SIZE != 0) {
0a122b
         /* 'VBoxManage convertfromraw' can create images with odd disk sizes.
0a122b
            We accept them but round the disk size to the next multiple of
0a122b
@@ -417,7 +428,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
         logout("unsupported sector size %u B\n", header.sector_size);
0a122b
         ret = -ENOTSUP;
0a122b
         goto fail;
0a122b
-    } else if (header.block_size != 1 * MiB) {
0a122b
+    } else if (header.block_size != VDI_BLOCK_SIZE) {
0a122b
         logout("unsupported block size %u B\n", header.block_size);
0a122b
         ret = -ENOTSUP;
0a122b
         goto fail;
0a122b
@@ -434,6 +445,10 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
         logout("parent uuid != 0, unsupported\n");
0a122b
         ret = -ENOTSUP;
0a122b
         goto fail;
0a122b
+    } else if (header.blocks_in_image > VDI_BLOCKS_IN_IMAGE_MAX) {
0a122b
+        logout("unsupported number of blocks in image\n");
0a122b
+        ret = -ENOTSUP;
0a122b
+        goto fail;
0a122b
     }
0a122b
 
0a122b
     bs->total_sectors = header.disk_size / SECTOR_SIZE;
0a122b
@@ -682,11 +697,17 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
0a122b
         options++;
0a122b
     }
0a122b
 
0a122b
+    if (bytes > VDI_DISK_SIZE_MAX) {
0a122b
+        result = -EINVAL;
0a122b
+        goto exit;
0a122b
+    }
0a122b
+
0a122b
     fd = qemu_open(filename,
0a122b
                    O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
0a122b
                    0644);
0a122b
     if (fd < 0) {
0a122b
-        return -errno;
0a122b
+        result = -errno;
0a122b
+        goto exit;
0a122b
     }
0a122b
 
0a122b
     /* We need enough blocks to store the given disk size,
0a122b
@@ -747,6 +768,7 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
0a122b
         result = -errno;
0a122b
     }
0a122b
 
0a122b
+exit:
0a122b
     return result;
0a122b
 }
0a122b
 
0a122b
-- 
0a122b
1.7.1
0a122b