9ae3a8
From 2f5fb1498fa48ea25f2d4155c9730001931bdef7 Mon Sep 17 00:00:00 2001
9ae3a8
From: Jeffrey Cody <jcody@redhat.com>
9ae3a8
Date: Tue, 16 Sep 2014 20:11:41 +0200
9ae3a8
Subject: [PATCH 03/20] block: make vdi bounds check match upstream
9ae3a8
9ae3a8
Message-id: <0935a62fcd0e3cce1ed66aa79fc460804ed938c7.1410897407.git.jcody@redhat.com>
9ae3a8
Patchwork-id: 61207
9ae3a8
O-Subject: [PATCH qemu-kvm-rhel RHEL7.1 02/15] block: make vdi bounds check match upstream
9ae3a8
Bugzilla: 1098086
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
There is a slight discrepancy between downstream, and upstream,
9ae3a8
in a patch done for CVE-2014-0144.  There is no difference in
9ae3a8
functionality - the (earlier) downstream patch contained a redundant
9ae3a8
'#define' that was removed upstream, and some upstream added error
9ae3a8
messages and different error returns.
9ae3a8
9ae3a8
Changing this to match upstream will make subsequent backports
9ae3a8
easier.
9ae3a8
9ae3a8
Downstream-only.
9ae3a8
9ae3a8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/vdi.c |   15 ++++++++++-----
9ae3a8
 1 files changed, 10 insertions(+), 5 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/vdi.c b/block/vdi.c
9ae3a8
index 0457298..5e2fad5 100644
9ae3a8
--- a/block/vdi.c
9ae3a8
+++ b/block/vdi.c
9ae3a8
@@ -120,11 +120,10 @@ typedef unsigned char uuid_t[16];
9ae3a8
 
9ae3a8
 #define VDI_IS_ALLOCATED(X) ((X) < VDI_DISCARDED)
9ae3a8
 
9ae3a8
-#define VDI_BLOCK_SIZE           (1 * MiB)
9ae3a8
 /* max blocks in image is (0xffffffff / 4) */
9ae3a8
 #define VDI_BLOCKS_IN_IMAGE_MAX  0x3fffffff
9ae3a8
 #define VDI_DISK_SIZE_MAX        ((uint64_t)VDI_BLOCKS_IN_IMAGE_MAX * \
9ae3a8
-                                  (uint64_t)VDI_BLOCK_SIZE)
9ae3a8
+                                  (uint64_t)DEFAULT_CLUSTER_SIZE)
9ae3a8
 
9ae3a8
 #if !defined(CONFIG_UUID)
9ae3a8
 static inline void uuid_generate(uuid_t out)
9ae3a8
@@ -392,7 +391,10 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
 #endif
9ae3a8
 
9ae3a8
     if (header.disk_size > VDI_DISK_SIZE_MAX) {
9ae3a8
-        ret = -EINVAL;
9ae3a8
+        error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64
9ae3a8
+                         ", max supported is 0x%" PRIx64 ")",
9ae3a8
+                          header.disk_size, VDI_DISK_SIZE_MAX);
9ae3a8
+        ret = -ENOTSUP;
9ae3a8
         goto fail;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -428,7 +430,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
         logout("unsupported sector size %u B\n", header.sector_size);
9ae3a8
         ret = -ENOTSUP;
9ae3a8
         goto fail;
9ae3a8
-    } else if (header.block_size != VDI_BLOCK_SIZE) {
9ae3a8
+    } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {
9ae3a8
         logout("unsupported block size %u B\n", header.block_size);
9ae3a8
         ret = -ENOTSUP;
9ae3a8
         goto fail;
9ae3a8
@@ -698,7 +700,10 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (bytes > VDI_DISK_SIZE_MAX) {
9ae3a8
-        result = -EINVAL;
9ae3a8
+        result = -ENOTSUP;
9ae3a8
+        error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64
9ae3a8
+                         ", max supported is 0x%" PRIx64 ")",
9ae3a8
+                          bytes, VDI_DISK_SIZE_MAX);
9ae3a8
         goto exit;
9ae3a8
     }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8