* [PATCH] qcow2: fix null pointer dereference in crypto block
@ 2025-03-18 10:58 gerben
2025-03-18 12:00 ` Kevin Wolf
0 siblings, 1 reply; 4+ messages in thread
From: gerben @ 2025-03-18 10:58 UTC (permalink / raw)
To: qemu-devel, kwolf, hreitz; +Cc: sdl.qemu
From: Denis Rastyogin <gerben@altlinux.org>
This error was discovered by fuzzing qemu-img.
The qcow2_refresh_limits() is missing a check
for the s->crypto pointer, which can lead to
a null pointer dereference. This commit adds the necessary check.
Reported-by: Leonid Reviakin <L.reviakin@fobos-nt.ru>
Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
---
block/qcow2.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/block/qcow2.c b/block/qcow2.c
index dd6bcafbd8..55861a285a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1978,6 +1978,10 @@ static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp)
if (bs->encrypted) {
/* Encryption works on a sector granularity */
+ if (!s->crypto) {
+ error_setg(errp, "Encryption context is missing");
+ return;
+ }
bs->bl.request_alignment = qcrypto_block_get_sector_size(s->crypto);
}
bs->bl.pwrite_zeroes_alignment = s->subcluster_size;
--
2.42.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] qcow2: fix null pointer dereference in crypto block
2025-03-18 10:58 [PATCH] qcow2: fix null pointer dereference in crypto block gerben
@ 2025-03-18 12:00 ` Kevin Wolf
2025-03-18 13:00 ` gerben
0 siblings, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2025-03-18 12:00 UTC (permalink / raw)
To: gerben; +Cc: qemu-devel, hreitz, sdl.qemu
Am 18.03.2025 um 11:58 hat gerben@altlinux.org geschrieben:
> From: Denis Rastyogin <gerben@altlinux.org>
>
> This error was discovered by fuzzing qemu-img.
>
> The qcow2_refresh_limits() is missing a check
> for the s->crypto pointer, which can lead to
> a null pointer dereference. This commit adds the necessary check.
>
> Reported-by: Leonid Reviakin <L.reviakin@fobos-nt.ru>
> Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
Please provide more information how to trigger this. This is probably
the wrong place to fix it. I think a qcow2 image that has bs->encrypted
should always also have s->crypto, so we need to understand why this
isn't the case here.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] qcow2: fix null pointer dereference in crypto block
2025-03-18 12:00 ` Kevin Wolf
@ 2025-03-18 13:00 ` gerben
2025-03-18 19:53 ` Kevin Wolf
0 siblings, 1 reply; 4+ messages in thread
From: gerben @ 2025-03-18 13:00 UTC (permalink / raw)
To: kwolf; +Cc: hreitz, qemu-devel, sdl.qemu
You can reproduce this issue by running ./qemu-img info segv.
The segv file used for reproduction can be found here:
https://github.com/Gerben100/reproduce_qemu-img_error
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] qcow2: fix null pointer dereference in crypto block
2025-03-18 13:00 ` gerben
@ 2025-03-18 19:53 ` Kevin Wolf
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2025-03-18 19:53 UTC (permalink / raw)
To: gerben; +Cc: hreitz, qemu-devel, sdl.qemu
Am 18.03.2025 um 14:00 hat gerben@altlinux.org geschrieben:
> You can reproduce this issue by running ./qemu-img info segv.
> The segv file used for reproduction can be found here:
> https://github.com/Gerben100/reproduce_qemu-img_error
Thanks. Your patch makes sure that qemu-img doesn't crash any more, but
we should catch the invalid image already while opening it. I'll send a
different patch.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-18 19:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-18 10:58 [PATCH] qcow2: fix null pointer dereference in crypto block gerben
2025-03-18 12:00 ` Kevin Wolf
2025-03-18 13:00 ` gerben
2025-03-18 19:53 ` Kevin Wolf
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).