[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/36] qcow2: Fix alignment checks in encrypted images
From: |
Kevin Wolf |
Subject: |
[PULL 03/36] qcow2: Fix alignment checks in encrypted images |
Date: |
Tue, 18 Feb 2020 15:06:49 +0100 |
From: Alberto Garcia <address@hidden>
I/O requests to encrypted media should be aligned to the sector size
used by the underlying encryption method, not to BDRV_SECTOR_SIZE.
Fortunately this doesn't break anything at the moment because
both existing QCRYPTO_BLOCK_*_SECTOR_SIZE have the same value as
BDRV_SECTOR_SIZE.
The checks in qcow2_co_preadv_encrypted() are also unnecessary because
they are repeated immediately afterwards in qcow2_co_encdec().
Signed-off-by: Alberto Garcia <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Daniel P. Berrangé <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-threads.c | 12 ++++++++----
block/qcow2.c | 2 --
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
index 8f5a0d1ebe..77bb578cdf 100644
--- a/block/qcow2-threads.c
+++ b/block/qcow2-threads.c
@@ -246,12 +246,15 @@ qcow2_co_encdec(BlockDriverState *bs, uint64_t
host_offset,
.len = len,
.func = func,
};
+ uint64_t sector_size;
- assert(QEMU_IS_ALIGNED(guest_offset, BDRV_SECTOR_SIZE));
- assert(QEMU_IS_ALIGNED(host_offset, BDRV_SECTOR_SIZE));
- assert(QEMU_IS_ALIGNED(len, BDRV_SECTOR_SIZE));
assert(s->crypto);
+ sector_size = qcrypto_block_get_sector_size(s->crypto);
+ assert(QEMU_IS_ALIGNED(guest_offset, sector_size));
+ assert(QEMU_IS_ALIGNED(host_offset, sector_size));
+ assert(QEMU_IS_ALIGNED(len, sector_size));
+
return len == 0 ? 0 : qcow2_co_process(bs, qcow2_encdec_pool_func, &arg);
}
@@ -270,7 +273,8 @@ qcow2_co_encdec(BlockDriverState *bs, uint64_t host_offset,
* will be written to the underlying storage device at
* @host_offset
*
- * @len - length of the buffer (must be a BDRV_SECTOR_SIZE multiple)
+ * @len - length of the buffer (must be a multiple of the encryption
+ * sector size)
*
* Depending on the encryption method, @host_offset and/or @guest_offset
* may be used for generating the initialization vector for
diff --git a/block/qcow2.c b/block/qcow2.c
index ef96606f8d..8dcee5efec 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2068,8 +2068,6 @@ qcow2_co_preadv_encrypted(BlockDriverState *bs,
goto fail;
}
- assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE));
- assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE));
if (qcow2_co_decrypt(bs,
file_cluster_offset + offset_into_cluster(s, offset),
offset, buf, bytes) < 0)
--
2.20.1
- [PULL 00/36] Block layer patches, Kevin Wolf, 2020/02/18
- [PULL 04/36] block/vvfat: Do not unref qcow on closing backing bdrv, Kevin Wolf, 2020/02/18
- [PULL 02/36] mirror: Don't let an operation wait for itself, Kevin Wolf, 2020/02/18
- [PULL 05/36] qcow2: update_refcount(): Reset old_table_index after qcow2_cache_put(), Kevin Wolf, 2020/02/18
- [PULL 06/36] qcow2: Fix qcow2_alloc_cluster_abort() for external data file, Kevin Wolf, 2020/02/18
- [PULL 03/36] qcow2: Fix alignment checks in encrypted images,
Kevin Wolf <=
- [PULL 01/36] mirror: Store MirrorOp.co for debuggability, Kevin Wolf, 2020/02/18
- [PULL 08/36] block/qcow2-bitmap: Remove unneeded variable assignment, Kevin Wolf, 2020/02/18
- [PULL 07/36] iotests: Test copy offloading with external data file, Kevin Wolf, 2020/02/18
- [PULL 09/36] qapi: Document meaning of 'ignore' BlockdevOnError for jobs, Kevin Wolf, 2020/02/18
- [PULL 12/36] commit: Inline commit_populate(), Kevin Wolf, 2020/02/18
- [PULL 11/36] commit: Fix argument order for block_job_error_action(), Kevin Wolf, 2020/02/18
- [PULL 14/36] commit: Expose on-error option in QMP, Kevin Wolf, 2020/02/18
- [PULL 10/36] commit: Remove unused bytes_written, Kevin Wolf, 2020/02/18
- [PULL 16/36] block: Remove superfluous semicolons, Kevin Wolf, 2020/02/18
- [PULL 17/36] block/io_uring: Remove superfluous semicolon, Kevin Wolf, 2020/02/18