[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 13/22] qcow2-bitmap: check constraints
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-devel] [PATCH 13/22] qcow2-bitmap: check constraints |
Date: |
Fri, 30 Sep 2016 13:53:19 +0300 |
Check bitmap header constraints as specified in docs/specs/qcow2.txt
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/qcow2-bitmap.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 8cf40f0..1c3abea 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -154,6 +154,34 @@ static inline void bitmap_directory_to_be(uint8_t *dir,
size_t size)
}
}
+static int check_constraints(BlockDriverState *bs, Qcow2BitmapDirEntry *h)
+{
+ BDRVQcow2State *s = bs->opaque;
+ uint64_t phys_bitmap_bytes =
+ (uint64_t)h->bitmap_table_size * s->cluster_size;
+ uint64_t max_virtual_bits = (phys_bitmap_bytes * 8) << h->granularity_bits;
+ int64_t nb_sectors = bdrv_nb_sectors(bs);
+
+ if (nb_sectors < 0) {
+ return nb_sectors;
+ }
+
+ int fail =
+ ((h->bitmap_table_size == 0) != (h->bitmap_table_offset == 0)) ||
+ (h->bitmap_table_offset % s->cluster_size) ||
+ (h->bitmap_table_size > BME_MAX_TABLE_SIZE) ||
+ (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) ||
+ (h->bitmap_table_offset != 0 &&
+ (nb_sectors << BDRV_SECTOR_BITS) > max_virtual_bits) ||
+ (h->granularity_bits > BME_MAX_GRANULARITY_BITS) ||
+ (h->granularity_bits < BME_MIN_GRANULARITY_BITS) ||
+ (h->flags & BME_RESERVED_FLAGS) ||
+ (h->name_size > BME_MAX_NAME_SIZE) ||
+ (h->type != BT_DIRTY_TRACKING_BITMAP);
+
+ return fail ? -EINVAL : 0;
+}
+
static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_table,
uint32_t bitmap_table_size)
{
@@ -372,6 +400,12 @@ static uint8_t *directory_read(BlockDriverState *bs,
bdrv_get_device_or_node_name(bs));
goto fail;
}
+
+ ret = check_constraints(bs, e);
+ if (ret < 0) {
+ error_setg(errp, "Bitmap doesn't satisfy the constraints.");
+ goto fail;
+ }
}
assert((uint8_t *)e == dir_end);
@@ -713,6 +747,11 @@ static int store_bitmap(BlockDriverState *bs,
entry->extra_data_size = 0;
memcpy(entry + 1, bm_name, entry->name_size);
+ ret = check_constraints(bs, entry);
+ if (ret < 0) {
+ goto fail;
+ }
+
return 0;
fail:
--
1.8.3.1
- [Qemu-devel] [PATCH 14/22] qcow2: delete bitmaps on truncate, (continued)
- [Qemu-devel] [PATCH 14/22] qcow2: delete bitmaps on truncate, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 15/22] qcow2-bitmap: add autoclear bit, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 16/22] qmp: add persistent flag to block-dirty-bitmap-add, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 06/22] qcow2: add dirty bitmaps extension, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 18/22] qapi: add md5 checksum of last dirty bitmap level to query-block, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 19/22] iotests: test qcow2 persistent dirty bitmap, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 10/22] block/dirty-bitmap: add bdrv_dirty_bitmap_next(), Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 03/22] block: fix bdrv_dirty_bitmap_granularity signature, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 17/22] qmp: add autoload parameter to block-dirty-bitmap-add, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 02/22] tests: add hbitmap iter test, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 13/22] qcow2-bitmap: check constraints,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-devel] [PATCH 09/22] block: introduce persistent dirty bitmaps, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 05/22] qcow2-bitmap: structs and consts, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 20/22] qcow2-dirty-bitmap: refcounts, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 04/22] block/dirty-bitmap: add deserialize_ones func, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 07/22] qcow2-bitmap: introduce auto-loading bitmaps, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 11/22] qcow2-bitmap: add qcow2_store_persistent_bitmaps(), Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 22/22] specs/qcow2: do not use wording 'bitmap header', Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 12/22] qcow2-bitmap: add IN_USE flag, Vladimir Sementsov-Ogievskiy, 2016/09/30
- [Qemu-devel] [PATCH 08/22] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap, Vladimir Sementsov-Ogievskiy, 2016/09/30