yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From 8d0f3218313c74d2e9df015385b809a7cb03734e Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 25 Mar 2014 14:23:55 +0100
9ae3a8
Subject: [PATCH 48/49] parallels: Sanity check for s->tracks (CVE-2014-0142)
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1395753835-7591-49-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: n/a
9ae3a8
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 48/48] parallels: Sanity check for s->tracks (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 avoids a possible division by zero.
9ae3a8
9ae3a8
Convert s->tracks to unsigned as well because it feels better than
9ae3a8
surviving just because the results of calculations with s->tracks are
9ae3a8
converted to unsigned anyway.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block/parallels.c          |    7 ++++++-
9ae3a8
 tests/qemu-iotests/076     |    7 +++++++
9ae3a8
 tests/qemu-iotests/076.out |    4 ++++
9ae3a8
 3 files changed, 17 insertions(+), 1 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/parallels.c b/block/parallels.c
9ae3a8
index 5d1c0af..d83cde4 100644
9ae3a8
--- a/block/parallels.c
9ae3a8
+++ b/block/parallels.c
9ae3a8
@@ -51,7 +51,7 @@ typedef struct BDRVParallelsState {
9ae3a8
     uint32_t *catalog_bitmap;
9ae3a8
     unsigned int catalog_size;
9ae3a8
 
9ae3a8
-    int tracks;
9ae3a8
+    unsigned int tracks;
9ae3a8
 } BDRVParallelsState;
9ae3a8
 
9ae3a8
 static int parallels_probe(const uint8_t *buf, int buf_size, const char *filename)
9ae3a8
@@ -92,6 +92,11 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     bs->total_sectors = le32_to_cpu(ph.nb_sectors);
9ae3a8
 
9ae3a8
     s->tracks = le32_to_cpu(ph.tracks);
9ae3a8
+    if (s->tracks == 0) {
9ae3a8
+        error_setg(errp, "Invalid image: Zero sectors per track");
9ae3a8
+        ret = -EINVAL;
9ae3a8
+        goto fail;
9ae3a8
+    }
9ae3a8
 
9ae3a8
     s->catalog_size = le32_to_cpu(ph.catalog_entries);
9ae3a8
     if (s->catalog_size > INT_MAX / 4) {
9ae3a8
diff --git a/tests/qemu-iotests/076 b/tests/qemu-iotests/076
9ae3a8
index 6028ac5..b614a7d 100755
9ae3a8
--- a/tests/qemu-iotests/076
9ae3a8
+++ b/tests/qemu-iotests/076
9ae3a8
@@ -42,6 +42,7 @@ _supported_fmt parallels
9ae3a8
 _supported_proto generic
9ae3a8
 _supported_os Linux
9ae3a8
 
9ae3a8
+tracks_offset=$((0x1c))
9ae3a8
 catalog_entries_offset=$((0x20))
9ae3a8
 nb_sectors_offset=$((0x24))
9ae3a8
 
9ae3a8
@@ -63,6 +64,12 @@ poke_file "$TEST_IMG" "$nb_sectors_offset" "\xff\xff\xff\xff"
9ae3a8
 poke_file "$TEST_IMG" "$catalog_entries_offset" "\x01\x00\x00\x40"
9ae3a8
 { $QEMU_IO -c "read 64M 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
9ae3a8
 
9ae3a8
+echo
9ae3a8
+echo "== Zero sectors per track =="
9ae3a8
+_use_sample_img fake.parallels.bz2
9ae3a8
+poke_file "$TEST_IMG" "$tracks_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/076.out b/tests/qemu-iotests/076.out
9ae3a8
index 12af42a..f7745d8 100644
9ae3a8
--- a/tests/qemu-iotests/076.out
9ae3a8
+++ b/tests/qemu-iotests/076.out
9ae3a8
@@ -11,4 +11,8 @@ no file open, try 'help open'
9ae3a8
 == Overflow in catalog allocation ==
9ae3a8
 qemu-io: can't open device TEST_DIR/fake.parallels: Catalog too large
9ae3a8
 no file open, try 'help open'
9ae3a8
+
9ae3a8
+== Zero sectors per track ==
9ae3a8
+qemu-io: can't open device TEST_DIR/fake.parallels: Invalid image: Zero sectors per track
9ae3a8
+no file open, try 'help open'
9ae3a8
 *** done
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8