qcow2: Check request size in qcow2_co_pwritev_compressed_part()
PATCH v2 1/1 qcow2: Check request size in qcow2_co_pwritev_compressed_part()
When issuing a compressed write request the number of bytes must be a multiple of the cluster size or reach the end of the last cluster.
With the current code such requests are allowed and we hit an assertion:
$ qemu-img create -f qcow2 img.qcow2 1M $ qemu-io -c 'write -c 0 32k' img.qcow2
qemu-io: block/qcow2.c:4257: qcow2_co_pwritev_compressed_task:
Assertion `bytes == s->cluster_size || (bytes < s->cluster_size &&
(offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS))' failed.
Aborted
This patch fixes a regression introduced in 0d483dce38
--- block/qcow2.c | 5 +++++ 1 file changed, 5 insertions(+)
block/qcow2.c +5 -0
@@ -4349,6 +4349,11 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,return -EINVAL ; } +if (offset_into_cluster (s, bytes) && + (offset + bytes) != (bs->total_sectors <<BDRV_SECTOR_BITS )) { +return -EINVAL ; + } +while (bytes &&aio_task_pool_status (aio) ==0 ) {uint64_t chunk_size =MIN (bytes, s->cluster_size);
Signature · 1 line
2.20.1
________________________________
From: Alberto Garcia <[email protected]>
Sent: Monday, April 6, 2020 5:34 PM
To: [email protected] <[email protected]>
Cc: Alberto Garcia <[email protected]>; [email protected] <[email protected]>; Andrey Shinkevich <[email protected]>; Max Reitz <[email protected]>; Kevin Wolf <[email protected]>; Vladimir Sementsov-Ogievskiy <[email protected]>; Pavel Butsykin <[email protected]>
Subject: [PATCH v2] qcow2: Check request size in qcow2_co_pwritev_compressed_part()
I forgot to add the "for-5.0" tag in the subject, do I need to resend the patch?
Berto
I wouldn't mind either.
Andrey
________________________________
From: Alberto Garcia <[email protected]>
Sent: Monday, April 6, 2020 7:08 PM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; Andrey Shinkevich <[email protected]>; Max Reitz <[email protected]>; Kevin Wolf <[email protected]>; Vladimir Sementsov-Ogievskiy <[email protected]>; Pavel Butsykin <[email protected]>
Subject: Re: [PATCH v2] qcow2: Check request size in qcow2_co_pwritev_compressed_part()
I forgot to add the "for-5.0" tag in the subject, do I need to resend the patch?
Berto
Quoted 9 lines · Alberto Garcia
When issuing a compressed write request the number of bytes must be a multiple of the cluster size or reach the end of the last cluster.
With the current code such requests are allowed and we hit an assertion:
$ qemu-img create -f qcow2 img.qcow2 1M $ qemu-io -c 'write -c 0 32k' img.qcow2
Quoted 8 lines
qemu-io: block/qcow2.c:4257: qcow2_co_pwritev_compressed_task: Assertion `bytes == s->cluster_size || (bytes < s->cluster_size && (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS))' failed. AbortedThis patch fixes a regression introduced in
0d483dce38Signed-off-by Alberto Garcia <[email protected]>
Quoted 21 lines
--- block/qcow2.c | 5 +++++ 1 file changed, 5 insertions(+)block/qcow2.c +5
-0@@ -4349,6 +4349,11 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,return -EINVAL ; } +if (offset_into_cluster (s, bytes) && + (offset + bytes) != (bs->total_sectors <<BDRV_SECTOR_BITS )) { +return -EINVAL ; + } +while (bytes &&aio_task_pool_status (aio) ==0 ) {uint64_t chunk_size =MIN (bytes, s->cluster_size);
Signature · 2 lines
Best regards, Vladimir
Max Reitz
AppliedQuoted 14 lines · Alberto Garcia
When issuing a compressed write request the number of bytes must be a multiple of the cluster size or reach the end of the last cluster.
With the current code such requests are allowed and we hit an assertion:
$ qemu-img create -f qcow2 img.qcow2 1M $ qemu-io -c 'write -c 0 32k' img.qcow2qemu-io: block/qcow2.c:4257: qcow2_co_pwritev_compressed_task: Assertion `bytes == s->cluster_size || (bytes < s->cluster_size && (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS))' failed. Aborted
Quoted 6 lines
This patch fixes a regression introduced in
0d483dce38Signed-off-by Alberto Garcia <[email protected]>--- block/qcow2.c | 5 +++++ 1 file changed, 5 insertions(+)
Thanks, applied to my block branch:
https://git.xanclic.moe/XanClic/qemu/commits/branch/block
Max