[Devel] [PATCH VZ10 v2 7/7] drivers/md/dm-qcow2: forbid unaligned virtual size for images

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Wed Aug 19 03:07:45 MSK 2026


There are a few places where we do to_sector() conversions which
may cause us bugs when the image size is not aligned. For example,
advance_and_spawn_lower_seek_qio() advances old_qio to
to_sector(end). If end is not aliged, it may round down to the
same sector already set in old_qio. Thus we will endlessly loop.

It is OK to forbid such images since QEMU rounds up virtual size
on qcow2 creation and rejects unaligned resizes.

https://virtuozzo.atlassian.net/browse/VSTOR-139407
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/md/dm-qcow2-target.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 3f65897ce9da2..6ad510772410c 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -541,6 +541,7 @@ static int qcow2_check_convert_hdr(struct dm_target *ti,
 
 	clu_size = 1 << hdr->cluster_bits;
 	if (hdr->size < min_len || hdr->size > max_len ||
+	    !IS_ALIGNED(hdr->size, SECTOR_SIZE) ||
 	    /* Note, we do not extend L1 table: */
 	    (u64)hdr->l1_size * clu_size / sizeof(u64) * clu_size < min_len)
 		return -EBADSLT;
-- 
2.43.5



More information about the Devel mailing list