All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	 Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
Subject: Re: [PATCH for-11.2 1/2] block/qcow2: Detect corrupt images where first refcount block is empty
Date: Thu, 19 Nov 2026 13:42:43 -0600	[thread overview]
Message-ID: <av9RFfYVm0_IvKu6@redhat.com> (raw)
In-Reply-To: <20261119140338.2918386-2-peter.maydell@linaro.org>

On Thu, Nov 19, 2026 at 02:03:37PM +0000, Peter Maydell wrote:
> 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.  Detect this in
> alloc_refblock().
> 
> This fixes a bug where 'qemu-img amend -o refcount_bits=...' would
> crash on a corrupted image where the entire refcount table was empty.
> The crash happened because walk_over_reftable() would return with
> new_reftable_size == 0 and new_reftable == NULL.
> qcow2_change_refcount_table() updated s->refcount_table and
> s->refcount_table_size with these bogus values, and
> update_max_refcount_table_index() would crash trying to dereference
> NULL[UINT_MAX]. We add a defensive assertion here that the
> new refcount table isn't zero-sized; this can't be reached because
> it only happens in the corruption case that we now detect.
> 
> Cc: qemu-stable@nongnu.org
> Fixes: 791c9a004efbcff ("qcow2: Add function for refcount order amendment")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3690
> Suggested-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  block/qcow2-refcount.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



  parent reply	other threads:[~2026-11-19 19:43 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 [this message]
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 ` [PATCH for-11.2 0/2] block/qcow2: Avoid crash in qemu-img amend when reftable is empty Kevin Wolf

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=av9RFfYVm0_IvKu6@redhat.com \
    --to=eblake@redhat.com \
    --cc=hreitz@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 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.