qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org, hreitz@redhat.com, gerben@altlinux.org,
	qemu-devel@nongnu.org
Subject: Re: [PATCH] qcow2: Don't crash qemu-img info with missing crypto header
Date: Tue, 18 Mar 2025 22:41:03 +0000	[thread overview]
Message-ID: <Z9n2ZC9Y7Xkuc8H2@redhat.com> (raw)
In-Reply-To: <20250318201143.70657-1-kwolf@redhat.com>

On Tue, Mar 18, 2025 at 09:11:43PM +0100, Kevin Wolf wrote:
> qcow2_refresh_limits() assumes that s->crypto is non-NULL whenever
> bs->encrypted is true. This is actually not the case: qcow2_do_open()
> allows to open an image with a missing crypto header for BDRV_O_NO_IO,
> and then bs->encrypted is true, but s->crypto is still NULL.
> 
> It doesn't make sense to open an invalid image, so remove the exception
> for BDRV_O_NO_IO. This catches the problem early and any code that makes
> the same assumption is safe now.
> 
> At the same time, in the name of defensive programming, we shouldn't
> make the assumption in the first place. Let qcow2_refresh_limits() check
> s->crypto rather than bs->encrypted. If s->crypto is NULL, it also can't
> make any requirement on request alignment.
> 
> Finally, start a qcow2-encryption test case that only serves as a
> regression test for this crash for now.
> 
> Reported-by: Leonid Reviakin <L.reviakin@fobos-nt.ru>
> Reported-by: Denis Rastyogin <gerben@altlinux.org>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/qcow2.c                                 |  4 +-
>  tests/qemu-iotests/tests/qcow2-encryption     | 75 +++++++++++++++++++
>  tests/qemu-iotests/tests/qcow2-encryption.out | 32 ++++++++
>  3 files changed, 109 insertions(+), 2 deletions(-)
>  create mode 100755 tests/qemu-iotests/tests/qcow2-encryption
>  create mode 100644 tests/qemu-iotests/tests/qcow2-encryption.out

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



      reply	other threads:[~2025-03-18 22:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-18 20:11 [PATCH] qcow2: Don't crash qemu-img info with missing crypto header Kevin Wolf
2025-03-18 22:41 ` Daniel P. Berrangé [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=Z9n2ZC9Y7Xkuc8H2@redhat.com \
    --to=berrange@redhat.com \
    --cc=gerben@altlinux.org \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --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).