[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] block: fail on open when file size is unaligned to request_a
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH 3/3] block: fail on open when file size is unaligned to request_alignment |
Date: |
Thu, 30 Jan 2020 18:22:18 +0300 |
Prior to the commit the following command lead to crash:
./qemu-io --image-opts -c 'write 0 512' \
driver=blkdebug,align=4096,image.driver=null-co,image.size=512
It failes on assertion in bdrv_aligned_pwritev:
"end_sector <= bs->total_sectors || child->perm & BLK_PERM_RESIZE"
The problem is obvious: 512 is aligned to 4096 and becomes larger than
file size. And the core bad thing is that file size is unaligned to
request_alignment.
Let's catch such case on bdrv_open_driver and fail.
Note, that file size and request_alignment may become out of sync
later, so this commit is not full fix of the problem, but it's better
than nothing.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/block.c b/block.c
index ecd09dbbfd..4cfc6c33a2 100644
--- a/block.c
+++ b/block.c
@@ -1324,6 +1324,13 @@ static int bdrv_open_driver(BlockDriverState *bs,
BlockDriver *drv,
assert(bdrv_min_mem_align(bs) != 0);
assert(is_power_of_2(bs->bl.request_alignment));
+ if (bs->bl.request_alignment > 512 &&
+ !QEMU_IS_ALIGNED(bs->total_sectors, bs->bl.request_alignment / 512))
+ {
+ error_setg(errp, "File size is unaligned to request alignment");
+ return -EINVAL;
+ }
+
for (i = 0; i < bs->quiesce_counter; i++) {
if (drv->bdrv_co_drain_begin) {
drv->bdrv_co_drain_begin(bs);
--
2.21.0