From: Kevin Wolf <kwolf@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Hanna Reitz <hreitz@redhat.com>,
qemu-stable@nongnu.org
Subject: Re: [PATCH for-11.2 0/2] block/qcow2: Avoid crash in qemu-img amend when reftable is empty
Date: Fri, 20 Nov 2026 18:32:12 +0100 [thread overview]
Message-ID: <awCEHC5U3sy1B0CN@redhat.com> (raw)
In-Reply-To: <20261119140338.2918386-1-peter.maydell@linaro.org>
Am 19.11.2026 um 15:03 hat Peter Maydell geschrieben:
> In a QCOW2 image, the header is always cluster zero, and so that
> cluster must have a non-zero refcount. This means that an image where
> the first entry in the refcount table is zero, or where it points to a
> refblock which is empty, must be corrupt.
>
> In the "qemu-img amend -o refcount_bits=..." codepath, we were
> implicitly relying on the image not being corrupted in this way. If
> the entire refcount table was zero, our "walk the table to see how big
> the new reftable size is" loop would say "zero", and we would then not
> allocate any memory for s->refcount_table, and
> update_max_refcount_table_index() would underflow when calculating
> s->refcount_table_size - 1 and then crash.
>
> This patchset fixes that bug, and adds a test case for it.
>
> It would also be possible to refuse to open an image for some of the
> more obvious cases of this corruption (e.g. "on open,
> refcount_table[0] is 0"), but checking the actual refcount of cluster
> 0 is a bit trickier as we only read in that refblock on demand. Plus
> some of the existing iotests (060, 098) rely on corrupted images of
> that kind only being detected later. So I have stuck to fixing the
> immediate bug.
>
> NB: this isn't a security issue because the crash can only be
> provoked for this specific qemu-img amend codepath, so it's a
> self-DoS.
>
> thanks
> -- PMM
>
> Peter Maydell (2):
> block/qcow2: Detect corrupt images where first refcount block is empty
> tests/qemu-iotest: Add test for qcow2 image with empty reftable
Thanks, applied to the block branch.
Kevin
prev parent reply other threads:[~2026-11-20 17:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 14:03 [PATCH for-11.2 0/2] block/qcow2: Avoid crash in qemu-img amend when reftable is empty Peter Maydell
2026-11-19 14:03 ` [PATCH for-11.2 1/2] block/qcow2: Detect corrupt images where first refcount block " Peter Maydell
2026-11-19 18:48 ` Peter Maydell
2026-11-19 19:42 ` Eric Blake
2026-11-19 14:03 ` [PATCH for-11.2 2/2] tests/qemu-iotest: Add test for qcow2 image with empty reftable Peter Maydell
2026-11-19 19:41 ` Eric Blake
2026-11-20 17:32 ` Kevin Wolf [this message]
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=awCEHC5U3sy1B0CN@redhat.com \
--to=kwolf@redhat.com \
--cc=hreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.