All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-11.2 0/2] block/qcow2: Avoid crash in qemu-img amend when reftable is empty
@ 2026-11-19 14:03 Peter Maydell
  2026-11-19 14:03 ` [PATCH for-11.2 1/2] block/qcow2: Detect corrupt images where first refcount block " Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Peter Maydell @ 2026-11-19 14:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, Kevin Wolf, Hanna Reitz

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

 block/qcow2-refcount.c     | 15 ++++++++++
 tests/qemu-iotests/315     | 59 ++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/315.out |  9 ++++++
 3 files changed, 83 insertions(+)
 create mode 100755 tests/qemu-iotests/315
 create mode 100644 tests/qemu-iotests/315.out

-- 
2.43.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-20 17:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH for-11.2 0/2] block/qcow2: Avoid crash in qemu-img amend when reftable is empty Kevin Wolf

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.