[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.7 1/5] block/parallels: check new image size
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL for-2.7 1/5] block/parallels: check new image size |
Date: |
Fri, 5 Aug 2016 10:24:38 +0100 |
From: Klim Kireev <address@hidden>
Before this patch incorrect image could be created via qemu-img
(Example: qemu-img create -f parallels -o size=4096T hack.img),
incorrect images cannot be used due to overflow in main image structure.
This patch add check of size in image creation.
After reading size it compare it with UINT32_MAX * cluster_size.
Signed-off-by: Klim Kireev <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
Message-id: address@hidden
CC: Stefan Hajnoczi <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/parallels.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/block/parallels.c b/block/parallels.c
index 807a801..2ccefa7 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -43,6 +43,7 @@
#define HEADER_MAGIC2 "WithouFreSpacExt"
#define HEADER_VERSION 2
#define HEADER_INUSE_MAGIC (0x746F6E59)
+#define MAX_PARALLELS_IMAGE_FACTOR (1ull << 32)
#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */
@@ -475,6 +476,10 @@ static int parallels_create(const char *filename, QemuOpts
*opts, Error **errp)
BDRV_SECTOR_SIZE);
cl_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
DEFAULT_CLUSTER_SIZE), BDRV_SECTOR_SIZE);
+ if (total_size >= MAX_PARALLELS_IMAGE_FACTOR * cl_size) {
+ error_propagate(errp, local_err);
+ return -E2BIG;
+ }
ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
--
2.7.4
- [Qemu-devel] [PULL for-2.7 0/5] Block patches, Stefan Hajnoczi, 2016/08/05
- [Qemu-devel] [PULL for-2.7 1/5] block/parallels: check new image size,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL for-2.7 2/5] throttle: Don't allow burst limits to be lower than the normal limits, Stefan Hajnoczi, 2016/08/05
- [Qemu-devel] [PULL for-2.7 3/5] throttle: Test burst limits lower than the normal limits, Stefan Hajnoczi, 2016/08/05
- [Qemu-devel] [PULL for-2.7 5/5] virtio-blk: Remove stale comment about draining, Stefan Hajnoczi, 2016/08/05
- [Qemu-devel] [PULL for-2.7 4/5] virtio-blk: Release s->rq queue at system_reset, Stefan Hajnoczi, 2016/08/05
- Re: [Qemu-devel] [PULL for-2.7 0/5] Block patches, Peter Maydell, 2016/08/05