Skip to contentSkip to conversation

qcow2: Reject unrealistically large header extensions

PATCH Superseded Kevin Wolf 2 participants 5 messages Feb 27, 2012 – Feb 28, 2012 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 qcow2: Reject unrealistically large header extensions

Image files that make qemu-img info read several gigabytes into the unknown header extensions list are bad. Just fail opening the image if an extension claims to be large.

---
 block/qcow2.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
block/qcow2.c +5 -0
index f68f0e1..077fe05 100644
@@ -108,6 +108,11 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
 #ifdef DEBUG_EXT
         printf("ext.magic = 0x%x\n", ext.magic);
 #endif
+        if (ext.len > 65536) {
+            error_report("Header extension larger than 64k - this looks wrong");
+            return -ENOTSUP;
+        }
+
         switch (ext.magic) {
         case QCOW2_EXT_MAGIC_END:
             return 0;
Signature · 1 line
1.7.6.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Kevin Wolf

+        if (ext.len > 65536) {
+            error_report("Header extension larger than 64k - this looks wrong");
+            return -ENOTSUP;
+        }

This is an implementation limit and not in the spec, but I think it's reasonable.

author
#2 lore raw

Am 28.02.2012 10:33, schrieb Stefan Hajnoczi:

Quoted 10 lines · Kevin Wolf

block/qcow2.c static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, · line 114

Quoted 4 lines
block/qcow2.c +4 -0
+        if (ext.len > 65536) {
+            error_report("Header extension larger than 64k - this looks wrong");
+            return -ENOTSUP;
+        }

This is an implementation limit and not in the spec, but I think it's reasonable.

Hm, actually, now that I look at this patch again, I think there's a much better error condition that even matches the spec:

if (offset + ext.len > end_offset)

I'll send a changed version of the patch.

Kevin

#3 lore raw
Quoted 10 lines · Kevin Wolf

Am 28.02.2012 10:33, schrieb Stefan Hajnoczi:

Quoted 9 lines · Kevin Wolf
Quoted 4 lines

+        if (ext.len > 65536) {
+            error_report("Header extension larger than 64k - this looks wrong");
+            return -ENOTSUP;
+        }

This is an implementation limit and not in the spec, but I think it's reasonable.

Quoted 6 lines
Quoted 1 line

Hm, actually, now that I look at this patch again, I think there's a much better error condition that even matches the spec:

   if (offset + ext.len > end_offset)

Careful, integer overflow.

Stefan

author
#4 lore raw

Am 28.02.2012 11:00, schrieb Stefan Hajnoczi:

Quoted 11 lines · Kevin Wolf
Quoted 10 lines

Am 28.02.2012 10:33, schrieb Stefan Hajnoczi:

Quoted 9 lines · Kevin Wolf

block/qcow2.c static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, · line 114

Quoted 4 lines
block/qcow2.c +4 -0
+        if (ext.len > 65536) {
+            error_report("Header extension larger than 64k - this looks wrong");
+            return -ENOTSUP;
+        }

This is an implementation limit and not in the spec, but I think it's reasonable.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Hm, actually, now that I look at this patch again, I think there's a much better error condition that even matches the spec:

if (offset + ext.len > end_offset)

Careful, integer overflow.

offset/end_offset are uint64_t offsets into the first cluster, ext.len is uint32_t. Looks safe.

Kevin