[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/12] block: Require aligned image size to avoid assertion failur
From: |
Kevin Wolf |
Subject: |
[PULL 08/12] block: Require aligned image size to avoid assertion failure |
Date: |
Fri, 17 Jul 2020 14:55:06 +0200 |
Unaligned requests will automatically be aligned to bl.request_alignment
and we can't extend write requests to access space beyond the end of the
image without resizing the image, so if we have the WRITE permission,
but not the RESIZE one, it's required that the image size is aligned.
Failing to meet this requirement could cause assertion failures like
this if RESIZE permissions weren't requested:
qemu-img: block/io.c:1910: bdrv_co_write_req_prepare: Assertion `end_sector <=
bs->total_sectors || child->perm & BLK_PERM_RESIZE' failed.
This was e.g. triggered by qemu-img converting to a target image with 4k
request alignment when the image was only aligned to 512 bytes, but not
to 4k.
Turn this into a graceful error in bdrv_check_perm() so that WRITE
without RESIZE can only be taken if the image size is aligned. If a user
holds both permissions and drops only RESIZE, the function will return
an error, but bdrv_child_try_set_perm() will ignore the failure silently
if permissions are only requested to be relaxed and just keep both
permissions while returning success.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200716142601.111237-2-kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/block.c b/block.c
index 35a372df57..d9ac0e07eb 100644
--- a/block.c
+++ b/block.c
@@ -2025,6 +2025,22 @@ static int bdrv_check_perm(BlockDriverState *bs,
BlockReopenQueue *q,
return -EPERM;
}
+ /*
+ * Unaligned requests will automatically be aligned to bl.request_alignment
+ * and without RESIZE we can't extend requests to write to space beyond the
+ * end of the image, so it's required that the image size is aligned.
+ */
+ if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) &&
+ !(cumulative_perms & BLK_PERM_RESIZE))
+ {
+ if ((bs->total_sectors * BDRV_SECTOR_SIZE) % bs->bl.request_alignment)
{
+ error_setg(errp, "Cannot get 'write' permission without 'resize': "
+ "Image size is not a multiple of request "
+ "alignment");
+ return -EPERM;
+ }
+ }
+
/* Check this node */
if (!drv) {
return 0;
--
2.25.4
- [PULL 00/12] Block layer patches for 5.1.0-rc1, Kevin Wolf, 2020/07/17
- [PULL 01/12] vvfat: set status to odd fixes, Kevin Wolf, 2020/07/17
- [PULL 03/12] qemu-img resize: Require --shrink for shrinking all image formats, Kevin Wolf, 2020/07/17
- [PULL 02/12] Remove VXHS block device, Kevin Wolf, 2020/07/17
- [PULL 05/12] iotests/030: Reduce job speed to make race less likely, Kevin Wolf, 2020/07/17
- [PULL 06/12] nbd: make nbd_export_close_all() synchronous, Kevin Wolf, 2020/07/17
- [PULL 08/12] block: Require aligned image size to avoid assertion failure,
Kevin Wolf <=
- [PULL 04/12] crypto: use a stronger private key for tests, Kevin Wolf, 2020/07/17
- [PULL 09/12] file-posix: Allow byte-aligned O_DIRECT with NFS, Kevin Wolf, 2020/07/17
- [PULL 07/12] iotests: test shutdown when bitmap is exported through NBD, Kevin Wolf, 2020/07/17
- [PULL 10/12] file-posix: Move check_hdev_writable() up, Kevin Wolf, 2020/07/17
- [PULL 11/12] file-posix: Fix check_hdev_writable() with auto-read-only, Kevin Wolf, 2020/07/17
- [PULL 12/12] file-posix: Fix leaked fd in raw_open_common() error path, Kevin Wolf, 2020/07/17
- Re: [PULL 00/12] Block layer patches for 5.1.0-rc1, Peter Maydell, 2020/07/18