|
|
9ae3a8 |
From 34d9d86de2d566b4c9ecd1ed0294edc0bb95bec6 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 25 Mar 2014 14:23:27 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 20/49] qcow2: Check header_length (CVE-2014-0144)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1395753835-7591-21-git-send-email-kwolf@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: n/a
|
|
|
9ae3a8 |
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 20/48] qcow2: Check header_length (CVE-2014-0144)
|
|
|
9ae3a8 |
Bugzilla: 1079455
|
|
|
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=1079455
|
|
|
9ae3a8 |
Upstream status: Embargoed
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This fixes an unbounded allocation for s->unknown_header_fields.
|
|
|
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/qcow2.c | 34 ++++++++++++++++++------
|
|
|
9ae3a8 |
tests/qemu-iotests/080 | 61 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
tests/qemu-iotests/080.out | 9 ++++++
|
|
|
9ae3a8 |
tests/qemu-iotests/group | 1 +
|
|
|
9ae3a8 |
4 files changed, 96 insertions(+), 9 deletions(-)
|
|
|
9ae3a8 |
create mode 100755 tests/qemu-iotests/080
|
|
|
9ae3a8 |
create mode 100644 tests/qemu-iotests/080.out
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
9ae3a8 |
index 18e136e..ea51f8e 100644
|
|
|
9ae3a8 |
--- a/block/qcow2.c
|
|
|
9ae3a8 |
+++ b/block/qcow2.c
|
|
|
9ae3a8 |
@@ -460,6 +460,18 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
s->qcow_version = header.version;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ /* Initialise cluster size */
|
|
|
9ae3a8 |
+ if (header.cluster_bits < MIN_CLUSTER_BITS ||
|
|
|
9ae3a8 |
+ header.cluster_bits > MAX_CLUSTER_BITS) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Unsupported cluster size: 2^%i", header.cluster_bits);
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ goto fail;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ s->cluster_bits = header.cluster_bits;
|
|
|
9ae3a8 |
+ s->cluster_size = 1 << s->cluster_bits;
|
|
|
9ae3a8 |
+ s->cluster_sectors = 1 << (s->cluster_bits - 9);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
/* Initialise version 3 header fields */
|
|
|
9ae3a8 |
if (header.version == 2) {
|
|
|
9ae3a8 |
header.incompatible_features = 0;
|
|
|
9ae3a8 |
@@ -473,6 +485,18 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
be64_to_cpus(&header.autoclear_features);
|
|
|
9ae3a8 |
be32_to_cpus(&header.refcount_order);
|
|
|
9ae3a8 |
be32_to_cpus(&header.header_length);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (header.header_length < 104) {
|
|
|
9ae3a8 |
+ error_setg(errp, "qcow2 header too short");
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ goto fail;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (header.header_length > s->cluster_size) {
|
|
|
9ae3a8 |
+ error_setg(errp, "qcow2 header exceeds cluster size");
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (header.header_length > sizeof(header)) {
|
|
|
9ae3a8 |
@@ -529,12 +553,6 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
s->refcount_order = header.refcount_order;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (header.cluster_bits < MIN_CLUSTER_BITS ||
|
|
|
9ae3a8 |
- header.cluster_bits > MAX_CLUSTER_BITS) {
|
|
|
9ae3a8 |
- error_setg(errp, "Unsupported cluster size: 2^%i", header.cluster_bits);
|
|
|
9ae3a8 |
- ret = -EINVAL;
|
|
|
9ae3a8 |
- goto fail;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
if (header.crypt_method > QCOW_CRYPT_AES) {
|
|
|
9ae3a8 |
error_setg(errp, "Unsupported encryption method: %i",
|
|
|
9ae3a8 |
header.crypt_method);
|
|
|
9ae3a8 |
@@ -545,9 +563,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
if (s->crypt_method_header) {
|
|
|
9ae3a8 |
bs->encrypted = 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- s->cluster_bits = header.cluster_bits;
|
|
|
9ae3a8 |
- s->cluster_size = 1 << s->cluster_bits;
|
|
|
9ae3a8 |
- s->cluster_sectors = 1 << (s->cluster_bits - 9);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
s->l2_bits = s->cluster_bits - 3; /* L2 is always one cluster */
|
|
|
9ae3a8 |
s->l2_size = 1 << s->l2_bits;
|
|
|
9ae3a8 |
bs->total_sectors = header.size / 512;
|
|
|
9ae3a8 |
diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080
|
|
|
9ae3a8 |
new file mode 100755
|
|
|
9ae3a8 |
index 0000000..6512701
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/tests/qemu-iotests/080
|
|
|
9ae3a8 |
@@ -0,0 +1,61 @@
|
|
|
9ae3a8 |
+#!/bin/bash
|
|
|
9ae3a8 |
+#
|
|
|
9ae3a8 |
+# qcow2 format input validation tests
|
|
|
9ae3a8 |
+#
|
|
|
9ae3a8 |
+# Copyright (C) 2013 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 |
+ _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 qcow2
|
|
|
9ae3a8 |
+_supported_proto generic
|
|
|
9ae3a8 |
+_supported_os Linux
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+header_size=104
|
|
|
9ae3a8 |
+offset_header_size=100
|
|
|
9ae3a8 |
+offset_ext_magic=$header_size
|
|
|
9ae3a8 |
+offset_ext_size=$((header_size + 4))
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+echo
|
|
|
9ae3a8 |
+echo "== Huge header size =="
|
|
|
9ae3a8 |
+_make_test_img 64M
|
|
|
9ae3a8 |
+poke_file "$TEST_IMG" "$offset_header_size" "\xff\xff\xff\xff"
|
|
|
9ae3a8 |
+{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
|
|
|
9ae3a8 |
+poke_file "$TEST_IMG" "$offset_header_size" "\x7f\xff\xff\xff"
|
|
|
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 |
+status=0
|
|
|
9ae3a8 |
diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..41a166a
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/tests/qemu-iotests/080.out
|
|
|
9ae3a8 |
@@ -0,0 +1,9 @@
|
|
|
9ae3a8 |
+QA output created by 080
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+== Huge header size ==
|
|
|
9ae3a8 |
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
|
|
|
9ae3a8 |
+qemu-io: can't open device TEST_DIR/t.qcow2: qcow2 header exceeds cluster size
|
|
|
9ae3a8 |
+no file open, try 'help open'
|
|
|
9ae3a8 |
+qemu-io: can't open device TEST_DIR/t.qcow2: qcow2 header exceeds cluster size
|
|
|
9ae3a8 |
+no file open, try 'help open'
|
|
|
9ae3a8 |
+*** done
|
|
|
9ae3a8 |
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
|
|
|
9ae3a8 |
index 7d0d07e..fc34194 100644
|
|
|
9ae3a8 |
--- a/tests/qemu-iotests/group
|
|
|
9ae3a8 |
+++ b/tests/qemu-iotests/group
|
|
|
9ae3a8 |
@@ -75,6 +75,7 @@
|
|
|
9ae3a8 |
077 rw auto
|
|
|
9ae3a8 |
078 rw auto
|
|
|
9ae3a8 |
079 rw auto
|
|
|
9ae3a8 |
+080 rw auto
|
|
|
9ae3a8 |
082 rw auto quick
|
|
|
9ae3a8 |
086 rw auto quick
|
|
|
9ae3a8 |
088 rw auto
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|