From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PULL 3/5] qcow2: Check request size in qcow2_co_pwritev_compressed_part()
Date: Tue, 7 Apr 2020 14:37:25 +0200 [thread overview]
Message-ID: <20200407123727.829933-4-mreitz@redhat.com> (raw)
In-Reply-To: <20200407123727.829933-1-mreitz@redhat.com>
From: Alberto Garcia <berto@igalia.com>
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>
Message-Id: <20200406143401.26854-1-berto@igalia.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/qcow2.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/block/qcow2.c b/block/qcow2.c
index e8cbcc1ec1..b524b0c53f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -4355,6 +4355,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);
--
2.25.1
next prev parent reply other threads:[~2020-04-07 12:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-07 12:37 [PULL 0/5] Block patches for 5.0-rc2 Max Reitz
2020-04-07 12:37 ` [PULL 1/5] qcow2: Forbid discard in qcow2 v2 images with backing files Max Reitz
2020-04-07 12:37 ` [PULL 2/5] qemu-img: Report convert errors by bytes, not sectors Max Reitz
2020-04-07 12:37 ` Max Reitz [this message]
2020-04-07 12:37 ` [PULL 4/5] iotests/common.pattern: Quote echos Max Reitz
2020-04-07 12:37 ` [PULL 5/5] xen-block: Fix double qlist remove and request leak Max Reitz
2020-04-07 18:12 ` [PULL 0/5] Block patches for 5.0-rc2 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200407123727.829933-4-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).