qcow2: Fix alignment checks in encrypted images
PATCH 1/1 qcow2: Fix alignment checks in encrypted images
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().
--- block/qcow2-threads.c | 12 ++++++++---- block/qcow2.c | 2 -- 2 files changed, 8 insertions(+), 6 deletions(-)
block/qcow2-threads.c +8 -4
@@ -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
block/qcow2.c +0 -2
@@ -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 )
Signature · 1 line
2.20.1
Quoted 6 lines · Alberto Garcia
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 asBDRV_SECTOR_SIZE.
Quoted 8 lines
The checks in
qcow2_co_preadv_encrypted()are also unnecessary because they are repeated immediately afterwards inqcow2_co_encdec().Signed-off-by Alberto Garcia <[email protected]>--- block/qcow2-threads.c | 12 ++++++++---- block/qcow2.c | 2 -- 2 files changed, 8 insertions(+), 6 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Kevin Wolf
AppliedAm 13.02.2020 um 18:16 hat Alberto Garcia geschrieben:
Quoted 10 lines
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 asBDRV_SECTOR_SIZE.The checks in
qcow2_co_preadv_encrypted()are also unnecessary because they are repeated immediately afterwards inqcow2_co_encdec().Signed-off-by Alberto Garcia <[email protected]>
Thanks, applied to the block branch.
Kevin