Skip to contentSkip to conversation

qcow2: fix null pointer dereference in crypto block

PATCH In review [email protected] 2 participants 4 messages Mar 18, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qcow2: fix null pointer dereference in crypto block

From: Denis Rastyogin <[email protected]>

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.

---
 block/qcow2.c | 4 ++++
 1 file changed, 4 insertions(+)
block/qcow2.c +4 -0
index dd6bcafbd8..55861a285a 100644
@@ -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;
Signature · 1 line
2.42.2
#1 lore raw

Am 18.03.2025 um 11:58 hat [email protected] geschrieben:

Quoted 10 lines

From: Denis Rastyogin <[email protected]>

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.

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

#3 lore raw

Am 18.03.2025 um 14:00 hat [email protected] geschrieben:

Quoted 3 lines

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