cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From a8a02156e1893fa0ea440c50a58171842f2aff1b Mon Sep 17 00:00:00 2001
0a122b
From: Jeff Cody <jcody@redhat.com>
0a122b
Date: Tue, 25 Mar 2014 14:23:47 +0100
0a122b
Subject: [PATCH 40/49] block: vdi bounds check qemu-io tests
0a122b
0a122b
RH-Author: Kevin Wolf <kwolf@redhat.com>
0a122b
Message-id: <1395753835-7591-41-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: n/a
0a122b
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 40/48] block: vdi bounds check qemu-io tests
0a122b
Bugzilla: 1066691
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
From: Jeff Cody <jcody@redhat.com>
0a122b
0a122b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1066691
0a122b
Upstream status: Series embargoed
0a122b
0a122b
This test checks for proper bounds checking of some VDI input
0a122b
headers. The following is checked:
0a122b
0a122b
1. Max image size (1024TB) with the appropriate Blocks In Image
0a122b
value (0x3fffffff) is detected as valid.
0a122b
0a122b
2. Image size exceeding max (1024TB) is seen as invalid
0a122b
0a122b
3. Valid image size but with Blocks In Image value that is too
0a122b
small fails
0a122b
0a122b
4. Blocks In Image size exceeding max (0x3fffffff) is seen as invalid
0a122b
0a122b
5. 64MB image, with 64 Blocks In Image, and 1MB Block Size is seen
0a122b
as valid
0a122b
0a122b
6. Block Size < 1MB not supported
0a122b
0a122b
7. Block Size > 1MB not supported
0a122b
0a122b
Signed-off-by: Jeff Cody <jcody@redhat.com>
0a122b
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
tests/qemu-iotests/group
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 tests/qemu-iotests/084     |  104 ++++++++++++++++++++++++++++++++++++++++++++
0a122b
 tests/qemu-iotests/084.out |   33 ++++++++++++++
0a122b
 tests/qemu-iotests/group   |    1 +
0a122b
 3 files changed, 138 insertions(+), 0 deletions(-)
0a122b
 create mode 100755 tests/qemu-iotests/084
0a122b
 create mode 100644 tests/qemu-iotests/084.out
0a122b
0a122b
diff --git a/tests/qemu-iotests/084 b/tests/qemu-iotests/084
0a122b
new file mode 100755
0a122b
index 0000000..10a5a65
0a122b
--- /dev/null
0a122b
+++ b/tests/qemu-iotests/084
0a122b
@@ -0,0 +1,104 @@
0a122b
+#!/bin/bash
0a122b
+#
0a122b
+# Test case for VDI header corruption; image too large, and too many blocks
0a122b
+#
0a122b
+# Copyright (C) 2013 Red Hat, Inc.
0a122b
+#
0a122b
+# This program is free software; you can redistribute it and/or modify
0a122b
+# it under the terms of the GNU General Public License as published by
0a122b
+# the Free Software Foundation; either version 2 of the License, or
0a122b
+# (at your option) any later version.
0a122b
+#
0a122b
+# This program is distributed in the hope that it will be useful,
0a122b
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
0a122b
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a122b
+# GNU General Public License for more details.
0a122b
+#
0a122b
+# You should have received a copy of the GNU General Public License
0a122b
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0a122b
+#
0a122b
+
0a122b
+# creator
0a122b
+owner=jcody@redhat.com
0a122b
+
0a122b
+seq=`basename $0`
0a122b
+echo "QA output created by $seq"
0a122b
+
0a122b
+here=`pwd`
0a122b
+tmp=/tmp/$$
0a122b
+status=1	# failure is the default!
0a122b
+
0a122b
+_cleanup()
0a122b
+{
0a122b
+	_cleanup_test_img
0a122b
+}
0a122b
+trap "_cleanup; exit \$status" 0 1 2 3 15
0a122b
+
0a122b
+# get standard environment, filters and checks
0a122b
+. ./common.rc
0a122b
+. ./common.filter
0a122b
+
0a122b
+# This tests vdi-specific header fields
0a122b
+_supported_fmt vdi
0a122b
+_supported_proto generic
0a122b
+_supported_os Linux
0a122b
+
0a122b
+ds_offset=368  # disk image size field offset
0a122b
+bs_offset=376  # block size field offset
0a122b
+bii_offset=384 # block in image field offset
0a122b
+
0a122b
+echo
0a122b
+echo "=== Testing image size bounds ==="
0a122b
+echo
0a122b
+_make_test_img 64M
0a122b
+
0a122b
+# check for image size too large
0a122b
+# poke max image size, and appropriate blocks_in_image value
0a122b
+echo "Test 1: Maximum size (1024 TB):"
0a122b
+poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf0\xff\xff\xff\x03\x00"
0a122b
+poke_file "$TEST_IMG" "$bii_offset" "\xff\xff\xff\x3f"
0a122b
+_img_info
0a122b
+
0a122b
+echo
0a122b
+echo "Test 2: Size too large (1024TB + 1)"
0a122b
+# This should be too large (-EINVAL):
0a122b
+poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf1\xff\xff\xff\x03\x00"
0a122b
+_img_info
0a122b
+
0a122b
+echo
0a122b
+echo "Test 3: Size valid (64M), but Blocks In Image too small (63)"
0a122b
+# This sets the size to 64M, but with a blocks_in_image size that is
0a122b
+# too small
0a122b
+poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00"
0a122b
+# For a 64M image, we would need a blocks_in_image value of at least 64,
0a122b
+# so 63 should be too small and give us -ENOTSUP
0a122b
+poke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00"
0a122b
+_img_info
0a122b
+
0a122b
+echo
0a122b
+echo "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed"
0a122b
+# Now check the bounds of blocks_in_image - 0x3fffffff should be the max
0a122b
+# value here, and we should get -ENOTSUP
0a122b
+poke_file "$TEST_IMG" "$bii_offset" "\x00\x00\x00\x40"
0a122b
+_img_info
0a122b
+
0a122b
+# Finally, 1MB is the only block size supported.  Verify that
0a122b
+# a value != 1MB results in error, both smaller and larger
0a122b
+echo
0a122b
+echo "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB"
0a122b
+poke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid
0a122b
+poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00"  # valid
0a122b
+_img_info
0a122b
+echo
0a122b
+echo "Test 6: Block Size != 1MB; too small test (1MB - 1)"
0a122b
+poke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00"  # invalid (too small)
0a122b
+_img_info
0a122b
+echo
0a122b
+echo "Test 7: Block Size != 1MB; too large test (1MB + 1)"
0a122b
+poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00"  # invalid (too large)
0a122b
+_img_info
0a122b
+# success, all done
0a122b
+echo
0a122b
+echo "*** done"
0a122b
+rm -f $seq.full
0a122b
+status=0
0a122b
diff --git a/tests/qemu-iotests/084.out b/tests/qemu-iotests/084.out
0a122b
new file mode 100644
0a122b
index 0000000..99c8e74
0a122b
--- /dev/null
0a122b
+++ b/tests/qemu-iotests/084.out
0a122b
@@ -0,0 +1,33 @@
0a122b
+QA output created by 084
0a122b
+
0a122b
+=== Testing image size bounds ===
0a122b
+
0a122b
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
0a122b
+Test 1: Maximum size (1024 TB):
0a122b
+image: TEST_DIR/t.IMGFMT
0a122b
+file format: IMGFMT
0a122b
+virtual size: 1024T (1125899905794048 bytes)
0a122b
+cluster_size: 1048576
0a122b
+
0a122b
+Test 2: Size too large (1024TB + 1)
0a122b
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Invalid argument
0a122b
+
0a122b
+Test 3: Size valid (64M), but Blocks In Image too small (63)
0a122b
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
0a122b
+
0a122b
+Test 4: Size valid (64M), but Blocks In Image exceeds max allowed
0a122b
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
0a122b
+
0a122b
+Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB
0a122b
+image: TEST_DIR/t.IMGFMT
0a122b
+file format: IMGFMT
0a122b
+virtual size: 64M (67108864 bytes)
0a122b
+cluster_size: 1048576
0a122b
+
0a122b
+Test 6: Block Size != 1MB; too small test (1MB - 1)
0a122b
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
0a122b
+
0a122b
+Test 7: Block Size != 1MB; too large test (1MB + 1)
0a122b
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
0a122b
+
0a122b
+*** done
0a122b
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
0a122b
index fc34194..e8ad780 100644
0a122b
--- a/tests/qemu-iotests/group
0a122b
+++ b/tests/qemu-iotests/group
0a122b
@@ -77,5 +77,6 @@
0a122b
 079 rw auto
0a122b
 080 rw auto
0a122b
 082 rw auto quick
0a122b
+084 img auto
0a122b
 086 rw auto quick
0a122b
 088 rw auto
0a122b
-- 
0a122b
1.7.1
0a122b