|
|
0a122b |
From ffbffdc438191db5bfa6ae6da52f0578db0fe7ac Mon Sep 17 00:00:00 2001
|
|
|
0a122b |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
0a122b |
Date: Tue, 25 Mar 2014 14:23:28 +0100
|
|
|
0a122b |
Subject: [PATCH 21/49] qcow2: Check backing_file_offset (CVE-2014-0144)
|
|
|
0a122b |
|
|
|
0a122b |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
0a122b |
Message-id: <1395753835-7591-22-git-send-email-kwolf@redhat.com>
|
|
|
0a122b |
Patchwork-id: n/a
|
|
|
0a122b |
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 21/48] qcow2: Check backing_file_offset (CVE-2014-0144)
|
|
|
0a122b |
Bugzilla: 1079455
|
|
|
0a122b |
RH-Acked-by: Jeff Cody <jcody@redhat.com>
|
|
|
0a122b |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
0a122b |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
0a122b |
|
|
|
0a122b |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1079455
|
|
|
0a122b |
Upstream status: Embargoed
|
|
|
0a122b |
|
|
|
0a122b |
Header, header extension and the backing file name must all be stored in
|
|
|
0a122b |
the first cluster. Setting the backing file to a much higher value
|
|
|
0a122b |
allowed header extensions to become much bigger than we want them to be
|
|
|
0a122b |
(unbounded allocation).
|
|
|
0a122b |
|
|
|
0a122b |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
0a122b |
---
|
|
|
0a122b |
block/qcow2.c | 6 ++++++
|
|
|
0a122b |
tests/qemu-iotests/080 | 12 ++++++++++++
|
|
|
0a122b |
tests/qemu-iotests/080.out | 7 +++++++
|
|
|
0a122b |
3 files changed, 25 insertions(+), 0 deletions(-)
|
|
|
0a122b |
|
|
|
0a122b |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
0a122b |
index ea51f8e..5568cf9 100644
|
|
|
0a122b |
--- a/block/qcow2.c
|
|
|
0a122b |
+++ b/block/qcow2.c
|
|
|
0a122b |
@@ -511,6 +511,12 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
0a122b |
}
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
+ if (header.backing_file_offset > s->cluster_size) {
|
|
|
0a122b |
+ error_setg(errp, "Invalid backing file offset");
|
|
|
0a122b |
+ ret = -EINVAL;
|
|
|
0a122b |
+ goto fail;
|
|
|
0a122b |
+ }
|
|
|
0a122b |
+
|
|
|
0a122b |
if (header.backing_file_offset) {
|
|
|
0a122b |
ext_end = header.backing_file_offset;
|
|
|
0a122b |
} else {
|
|
|
0a122b |
diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080
|
|
|
0a122b |
index 6512701..6d588dd 100755
|
|
|
0a122b |
--- a/tests/qemu-iotests/080
|
|
|
0a122b |
+++ b/tests/qemu-iotests/080
|
|
|
0a122b |
@@ -43,6 +43,8 @@ _supported_proto generic
|
|
|
0a122b |
_supported_os Linux
|
|
|
0a122b |
|
|
|
0a122b |
header_size=104
|
|
|
0a122b |
+
|
|
|
0a122b |
+offset_backing_file_offset=8
|
|
|
0a122b |
offset_header_size=100
|
|
|
0a122b |
offset_ext_magic=$header_size
|
|
|
0a122b |
offset_ext_size=$((header_size + 4))
|
|
|
0a122b |
@@ -55,6 +57,16 @@ poke_file "$TEST_IMG" "$offset_header_size" "\xff\xff\xff\xff"
|
|
|
0a122b |
poke_file "$TEST_IMG" "$offset_header_size" "\x7f\xff\xff\xff"
|
|
|
0a122b |
{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
|
|
|
0a122b |
|
|
|
0a122b |
+echo
|
|
|
0a122b |
+echo "== Huge unknown header extension =="
|
|
|
0a122b |
+_make_test_img 64M
|
|
|
0a122b |
+poke_file "$TEST_IMG" "$offset_backing_file_offset" "\xff\xff\xff\xff\xff\xff\xff\xff"
|
|
|
0a122b |
+poke_file "$TEST_IMG" "$offset_ext_magic" "\x12\x34\x56\x78"
|
|
|
0a122b |
+poke_file "$TEST_IMG" "$offset_ext_size" "\x7f\xff\xff\xff"
|
|
|
0a122b |
+{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
|
|
|
0a122b |
+poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
0a122b |
+{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
|
|
|
0a122b |
+
|
|
|
0a122b |
# success, all done
|
|
|
0a122b |
echo "*** done"
|
|
|
0a122b |
rm -f $seq.full
|
|
|
0a122b |
diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out
|
|
|
0a122b |
index 41a166a..48c40aa 100644
|
|
|
0a122b |
--- a/tests/qemu-iotests/080.out
|
|
|
0a122b |
+++ b/tests/qemu-iotests/080.out
|
|
|
0a122b |
@@ -6,4 +6,11 @@ qemu-io: can't open device TEST_DIR/t.qcow2: qcow2 header exceeds cluster size
|
|
|
0a122b |
no file open, try 'help open'
|
|
|
0a122b |
qemu-io: can't open device TEST_DIR/t.qcow2: qcow2 header exceeds cluster size
|
|
|
0a122b |
no file open, try 'help open'
|
|
|
0a122b |
+
|
|
|
0a122b |
+== Huge unknown header extension ==
|
|
|
0a122b |
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
|
|
|
0a122b |
+qemu-io: can't open device TEST_DIR/t.qcow2: Invalid backing file offset
|
|
|
0a122b |
+no file open, try 'help open'
|
|
|
0a122b |
+qemu-io: can't open device TEST_DIR/t.qcow2: Header extension too large
|
|
|
0a122b |
+no file open, try 'help open'
|
|
|
0a122b |
*** done
|
|
|
0a122b |
--
|
|
|
0a122b |
1.7.1
|
|
|
0a122b |
|