thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-bochs-Check-extent_size-header-field-CVE-2014-0142.patch

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