diff mbox series

[v2] qcow2: Check request size in qcow2_co_pwritev_compressed_part()

Message ID 20200406143401.26854-1-berto@igalia.com (mailing list archive)
State New, archived
Headers show
Series [v2] qcow2: Check request size in qcow2_co_pwritev_compressed_part() | expand

Commit Message

Alberto Garcia April 6, 2020, 2:34 p.m. UTC
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

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/qcow2.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Andrey Shinkevich April 6, 2020, 2:52 p.m. UTC | #1
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Alberto Garcia April 6, 2020, 4:08 p.m. UTC | #2
I forgot to add the "for-5.0" tag in the subject, do I need to resend
the patch?

Berto
Andrey Shinkevich April 7, 2020, 6:16 a.m. UTC | #3
I wouldn't mind either.

Andrey
Vladimir Sementsov-Ogievskiy April 7, 2020, 7:27 a.m. UTC | #4
06.04.2020 17:34, Alberto Garcia wrote:
> 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
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> ---
>   block/qcow2.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 2bb536b014..587cf51948 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -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);
>   
>
Max Reitz April 7, 2020, 8:51 a.m. UTC | #5
On 06.04.20 16:34, Alberto Garcia wrote:
> 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
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  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
diff mbox series

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 2bb536b014..587cf51948 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -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);