yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 3150a448434da70b69e0b96d71223161a78d536f Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Tue, 25 Mar 2014 14:23:20 +0100
0a122b
Subject: [PATCH 13/49] bochs: Check extent_size header field (CVE-2014-0142)
0a122b
0a122b
RH-Author: Kevin Wolf <kwolf@redhat.com>
0a122b
Message-id: <1395753835-7591-14-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: n/a
0a122b
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 13/48] bochs: Check extent_size header field (CVE-2014-0142)
0a122b
Bugzilla: 1079315
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=1079315
0a122b
Upstream status: Embargoed
0a122b
0a122b
This fixes two possible division by zero crashes: In bochs_open() and in
0a122b
seek_to_sector().
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
---
0a122b
 block/bochs.c              |    8 ++++++++
0a122b
 tests/qemu-iotests/078     |   13 +++++++++++++
0a122b
 tests/qemu-iotests/078.out |    8 ++++++++
0a122b
 3 files changed, 29 insertions(+), 0 deletions(-)
0a122b
0a122b
diff --git a/block/bochs.c b/block/bochs.c
0a122b
index d1b1a2c..0ec980a 100644
0a122b
--- a/block/bochs.c
0a122b
+++ b/block/bochs.c
0a122b
@@ -147,6 +147,14 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
     s->extent_blocks = 1 + (le32_to_cpu(bochs.extent) - 1) / 512;
0a122b
 
0a122b
     s->extent_size = le32_to_cpu(bochs.extent);
0a122b
+    if (s->extent_size == 0) {
0a122b
+        error_setg(errp, "Extent size may not be zero");
0a122b
+        return -EINVAL;
0a122b
+    } else if (s->extent_size > 0x800000) {
0a122b
+        error_setg(errp, "Extent size %" PRIu32 " is too large",
0a122b
+                   s->extent_size);
0a122b
+        return -EINVAL;
0a122b
+    }
0a122b
 
0a122b
     if (s->catalog_size < bs->total_sectors / s->extent_size) {
0a122b
         error_setg(errp, "Catalog size is too small for this disk size");
0a122b
diff --git a/tests/qemu-iotests/078 b/tests/qemu-iotests/078
0a122b
index 902ef0f..872e734 100755
0a122b
--- a/tests/qemu-iotests/078
0a122b
+++ b/tests/qemu-iotests/078
0a122b
@@ -43,6 +43,7 @@ _supported_proto generic
0a122b
 _supported_os Linux
0a122b
 
0a122b
 catalog_size_offset=$((0x48))
0a122b
+extent_size_offset=$((0x50))
0a122b
 disk_size_offset=$((0x58))
0a122b
 
0a122b
 echo
0a122b
@@ -68,6 +69,18 @@ _use_sample_img empty.bochs.bz2
0a122b
 poke_file "$TEST_IMG" "$disk_size_offset" "\x00\xc0\x0f\x00\x00\x00\x00\x7f"
0a122b
 { $QEMU_IO -c "read 2T 4k" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
0a122b
 
0a122b
+echo
0a122b
+echo "== Negative extent size =="
0a122b
+_use_sample_img empty.bochs.bz2
0a122b
+poke_file "$TEST_IMG" "$extent_size_offset" "\xff\xff\xff\xff"
0a122b
+{ $QEMU_IO -c "read 768k 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
0a122b
+
0a122b
+echo
0a122b
+echo "== Zero extent size =="
0a122b
+_use_sample_img empty.bochs.bz2
0a122b
+poke_file "$TEST_IMG" "$extent_size_offset" "\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/078.out b/tests/qemu-iotests/078.out
0a122b
index 7254693..ea95ffd 100644
0a122b
--- a/tests/qemu-iotests/078.out
0a122b
+++ b/tests/qemu-iotests/078.out
0a122b
@@ -15,4 +15,12 @@ no file open, try 'help open'
0a122b
 == Too small catalog bitmap for image size ==
0a122b
 qemu-io: can't open device TEST_DIR/empty.bochs: Catalog size is too small for this disk size
0a122b
 no file open, try 'help open'
0a122b
+
0a122b
+== Negative extent size ==
0a122b
+qemu-io: can't open device TEST_DIR/empty.bochs: Extent size 4294967295 is too large
0a122b
+no file open, try 'help open'
0a122b
+
0a122b
+== Zero extent size ==
0a122b
+qemu-io: can't open device TEST_DIR/empty.bochs: Extent size may not be zero
0a122b
+no file open, try 'help open'
0a122b
 *** done
0a122b
-- 
0a122b
1.7.1
0a122b