[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 60/62] qcow2: Catch !*host_offset for data allocation
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 60/62] qcow2: Catch !*host_offset for data allocation |
Date: |
Fri, 8 Aug 2014 19:40:01 +0200 |
From: Max Reitz <address@hidden>
qcow2_alloc_cluster_offset() uses host_offset == 0 as "no preferred
offset" for the (data) cluster range to be allocated. However, this
offset is actually valid and may be allocated on images with a corrupted
refcount table or first refcount block.
In this case, the corruption prevention should normally catch that
write anyway (because it would overwrite the image header). But since 0
is a special value here, the function assumes that nothing has been
allocated at all which it asserts against.
Because this condition is not qemu's fault but rather that of a broken
image, it shouldn't throw an assertion but rather mark the image corrupt
and show an appropriate message, which this patch does by calling the
corruption check earlier than it would be called normally (before the
assertion).
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cluster.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index e7c5f48..5b36018 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1119,6 +1119,17 @@ static int handle_alloc(BlockDriverState *bs, uint64_t
guest_offset,
return 0;
}
+ /* !*host_offset would overwrite the image header and is reserved for "no
+ * host offset preferred". If 0 was a valid host offset, it'd trigger the
+ * following overlap check; do that now to avoid having an invalid value in
+ * *host_offset. */
+ if (!alloc_cluster_offset) {
+ ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset,
+ nb_clusters * s->cluster_size);
+ assert(ret < 0);
+ goto fail;
+ }
+
/*
* Save info needed for meta data update.
*
--
1.8.3.1
- [Qemu-devel] [PULL 51/62] raw-posix: Handle failure for potentially large allocations, (continued)
- [Qemu-devel] [PULL 51/62] raw-posix: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 52/62] raw-win32: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 49/62] qcow2: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 54/62] vdi: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 53/62] rbd: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 55/62] vhdx: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 57/62] vpc: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 58/62] mirror: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 59/62] qcow2: Return useful error code in refcount_init(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 56/62] vmdk: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 60/62] qcow2: Catch !*host_offset for data allocation,
Kevin Wolf <=
- [Qemu-devel] [PULL 61/62] iotests: Add test for image header overlap, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 62/62] block: Catch !bs->drv in bdrv_check(), Kevin Wolf, 2014/08/08
- Re: [Qemu-devel] [PULL 00/62] Block patches, Peter Maydell, 2014/08/15