]> git.ipfire.org Git - thirdparty/qemu.git/commit
qcow2: Don't crash qemu-img info with missing crypto header
authorKevin Wolf <kwolf@redhat.com>
Tue, 18 Mar 2025 20:11:43 +0000 (21:11 +0100)
committerKevin Wolf <kwolf@redhat.com>
Tue, 8 Apr 2025 10:13:17 +0000 (12:13 +0200)
commit8e4ffb4ef434af3667a90276d75d301b582bf78c
tree09ccf462bd88a7edb6f041de2aaa302c57881192
parent6b36a578316e3b14a53ae7699571d01b00fc2f8a
qcow2: Don't crash qemu-img info with missing crypto header

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>
Message-ID: <20250318201143.70657-1-kwolf@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/qcow2.c
tests/qemu-iotests/tests/qcow2-encryption [new file with mode: 0755]
tests/qemu-iotests/tests/qcow2-encryption.out [new file with mode: 0644]