cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From 94cdf32d7dfbfb12041eb58215e3074525a176b1 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 25 Mar 2014 14:23:23 +0100
9ae3a8
Subject: [PATCH 16/49] vpc: Validate block size (CVE-2014-0142)
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1395753835-7591-17-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: n/a
9ae3a8
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 16/48] vpc: Validate block size (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 some cases of division by zero crashes.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
Conflicts:
9ae3a8
tests/qemu-iotests/group
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block/vpc.c                |    5 +++
9ae3a8
 tests/qemu-iotests/088     |   64 ++++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 tests/qemu-iotests/088.out |   17 +++++++++++
9ae3a8
 tests/qemu-iotests/group   |    1 +
9ae3a8
 4 files changed, 87 insertions(+), 0 deletions(-)
9ae3a8
 create mode 100755 tests/qemu-iotests/088
9ae3a8
 create mode 100644 tests/qemu-iotests/088.out
9ae3a8
9ae3a8
diff --git a/block/vpc.c b/block/vpc.c
9ae3a8
index de5bc22..000d1c6 100644
9ae3a8
--- a/block/vpc.c
9ae3a8
+++ b/block/vpc.c
9ae3a8
@@ -235,6 +235,11 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
         }
9ae3a8
 
9ae3a8
         s->block_size = be32_to_cpu(dyndisk_header->block_size);
9ae3a8
+        if (!is_power_of_2(s->block_size) || s->block_size < BDRV_SECTOR_SIZE) {
9ae3a8
+            error_setg(errp, "Invalid block size %" PRIu32, s->block_size);
9ae3a8
+            ret = -EINVAL;
9ae3a8
+            goto fail;
9ae3a8
+        }
9ae3a8
         s->bitmap_size = ((s->block_size / (8 * 512)) + 511) & ~511;
9ae3a8
 
9ae3a8
         s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries);
9ae3a8
diff --git a/tests/qemu-iotests/088 b/tests/qemu-iotests/088
9ae3a8
new file mode 100755
9ae3a8
index 0000000..c09adf8
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/088
9ae3a8
@@ -0,0 +1,64 @@
9ae3a8
+#!/bin/bash
9ae3a8
+#
9ae3a8
+# vpc (VHD) format input validation tests
9ae3a8
+#
9ae3a8
+# Copyright (C) 2014 Red Hat, Inc.
9ae3a8
+#
9ae3a8
+# This program is free software; you can redistribute it and/or modify
9ae3a8
+# it under the terms of the GNU General Public License as published by
9ae3a8
+# the Free Software Foundation; either version 2 of the License, or
9ae3a8
+# (at your option) any later version.
9ae3a8
+#
9ae3a8
+# This program is distributed in the hope that it will be useful,
9ae3a8
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
9ae3a8
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9ae3a8
+# GNU General Public License for more details.
9ae3a8
+#
9ae3a8
+# You should have received a copy of the GNU General Public License
9ae3a8
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9ae3a8
+#
9ae3a8
+
9ae3a8
+# creator
9ae3a8
+owner=kwolf@redhat.com
9ae3a8
+
9ae3a8
+seq=`basename $0`
9ae3a8
+echo "QA output created by $seq"
9ae3a8
+
9ae3a8
+here=`pwd`
9ae3a8
+tmp=/tmp/$$
9ae3a8
+status=1	# failure is the default!
9ae3a8
+
9ae3a8
+_cleanup()
9ae3a8
+{
9ae3a8
+    rm -f $TEST_IMG.snap
9ae3a8
+    _cleanup_test_img
9ae3a8
+}
9ae3a8
+trap "_cleanup; exit \$status" 0 1 2 3 15
9ae3a8
+
9ae3a8
+# get standard environment, filters and checks
9ae3a8
+. ./common.rc
9ae3a8
+. ./common.filter
9ae3a8
+
9ae3a8
+_supported_fmt vpc
9ae3a8
+_supported_proto generic
9ae3a8
+_supported_os Linux
9ae3a8
+
9ae3a8
+offset_block_size=$((512 + 32))
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "== Invalid block size =="
9ae3a8
+_make_test_img 64M
9ae3a8
+poke_file "$TEST_IMG" "$offset_block_size" "\x00\x00\x00\x00"
9ae3a8
+{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
9ae3a8
+{ $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
9ae3a8
+poke_file "$TEST_IMG" "$offset_block_size" "\x00\x00\x00\x80"
9ae3a8
+{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
9ae3a8
+{ $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
9ae3a8
+poke_file "$TEST_IMG" "$offset_block_size" "\x12\x34\x56\x78"
9ae3a8
+{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
9ae3a8
+{ $QEMU_IO -c "write 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
+status=0
9ae3a8
diff --git a/tests/qemu-iotests/088.out b/tests/qemu-iotests/088.out
9ae3a8
new file mode 100644
9ae3a8
index 0000000..d961609
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/088.out
9ae3a8
@@ -0,0 +1,17 @@
9ae3a8
+QA output created by 088
9ae3a8
+
9ae3a8
+== Invalid block size ==
9ae3a8
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vpc: Invalid block size 0
9ae3a8
+no file open, try 'help open'
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vpc: Invalid block size 0
9ae3a8
+no file open, try 'help open'
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vpc: Invalid block size 128
9ae3a8
+no file open, try 'help open'
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vpc: Invalid block size 128
9ae3a8
+no file open, try 'help open'
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vpc: Invalid block size 305419896
9ae3a8
+no file open, try 'help open'
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vpc: Invalid block size 305419896
9ae3a8
+no file open, try 'help open'
9ae3a8
+*** done
9ae3a8
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
9ae3a8
index 30a0fd8..7d0d07e 100644
9ae3a8
--- a/tests/qemu-iotests/group
9ae3a8
+++ b/tests/qemu-iotests/group
9ae3a8
@@ -77,3 +77,4 @@
9ae3a8
 079 rw auto
9ae3a8
 082 rw auto quick
9ae3a8
 086 rw auto quick
9ae3a8
+088 rw auto
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8