9ae3a8
From a8a02156e1893fa0ea440c50a58171842f2aff1b Mon Sep 17 00:00:00 2001
9ae3a8
From: Jeff Cody <jcody@redhat.com>
9ae3a8
Date: Tue, 25 Mar 2014 14:23:47 +0100
9ae3a8
Subject: [PATCH 40/49] block: vdi bounds check qemu-io tests
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1395753835-7591-41-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: n/a
9ae3a8
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 40/48] block: vdi bounds check qemu-io tests
9ae3a8
Bugzilla: 1066691
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
From: Jeff Cody <jcody@redhat.com>
9ae3a8
9ae3a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1066691
9ae3a8
Upstream status: Series embargoed
9ae3a8
9ae3a8
This test checks for proper bounds checking of some VDI input
9ae3a8
headers. The following is checked:
9ae3a8
9ae3a8
1. Max image size (1024TB) with the appropriate Blocks In Image
9ae3a8
value (0x3fffffff) is detected as valid.
9ae3a8
9ae3a8
2. Image size exceeding max (1024TB) is seen as invalid
9ae3a8
9ae3a8
3. Valid image size but with Blocks In Image value that is too
9ae3a8
small fails
9ae3a8
9ae3a8
4. Blocks In Image size exceeding max (0x3fffffff) is seen as invalid
9ae3a8
9ae3a8
5. 64MB image, with 64 Blocks In Image, and 1MB Block Size is seen
9ae3a8
as valid
9ae3a8
9ae3a8
6. Block Size < 1MB not supported
9ae3a8
9ae3a8
7. Block Size > 1MB not supported
9ae3a8
9ae3a8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9ae3a8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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
 tests/qemu-iotests/084     |  104 ++++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 tests/qemu-iotests/084.out |   33 ++++++++++++++
9ae3a8
 tests/qemu-iotests/group   |    1 +
9ae3a8
 3 files changed, 138 insertions(+), 0 deletions(-)
9ae3a8
 create mode 100755 tests/qemu-iotests/084
9ae3a8
 create mode 100644 tests/qemu-iotests/084.out
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/084 b/tests/qemu-iotests/084
9ae3a8
new file mode 100755
9ae3a8
index 0000000..10a5a65
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/084
9ae3a8
@@ -0,0 +1,104 @@
9ae3a8
+#!/bin/bash
9ae3a8
+#
9ae3a8
+# Test case for VDI header corruption; image too large, and too many blocks
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=jcody@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
+# This tests vdi-specific header fields
9ae3a8
+_supported_fmt vdi
9ae3a8
+_supported_proto generic
9ae3a8
+_supported_os Linux
9ae3a8
+
9ae3a8
+ds_offset=368  # disk image size field offset
9ae3a8
+bs_offset=376  # block size field offset
9ae3a8
+bii_offset=384 # block in image field offset
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing image size bounds ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+
9ae3a8
+# check for image size too large
9ae3a8
+# poke max image size, and appropriate blocks_in_image value
9ae3a8
+echo "Test 1: Maximum size (1024 TB):"
9ae3a8
+poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf0\xff\xff\xff\x03\x00"
9ae3a8
+poke_file "$TEST_IMG" "$bii_offset" "\xff\xff\xff\x3f"
9ae3a8
+_img_info
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "Test 2: Size too large (1024TB + 1)"
9ae3a8
+# This should be too large (-EINVAL):
9ae3a8
+poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf1\xff\xff\xff\x03\x00"
9ae3a8
+_img_info
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "Test 3: Size valid (64M), but Blocks In Image too small (63)"
9ae3a8
+# This sets the size to 64M, but with a blocks_in_image size that is
9ae3a8
+# too small
9ae3a8
+poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00"
9ae3a8
+# For a 64M image, we would need a blocks_in_image value of at least 64,
9ae3a8
+# so 63 should be too small and give us -ENOTSUP
9ae3a8
+poke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00"
9ae3a8
+_img_info
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed"
9ae3a8
+# Now check the bounds of blocks_in_image - 0x3fffffff should be the max
9ae3a8
+# value here, and we should get -ENOTSUP
9ae3a8
+poke_file "$TEST_IMG" "$bii_offset" "\x00\x00\x00\x40"
9ae3a8
+_img_info
9ae3a8
+
9ae3a8
+# Finally, 1MB is the only block size supported.  Verify that
9ae3a8
+# a value != 1MB results in error, both smaller and larger
9ae3a8
+echo
9ae3a8
+echo "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB"
9ae3a8
+poke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid
9ae3a8
+poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00"  # valid
9ae3a8
+_img_info
9ae3a8
+echo
9ae3a8
+echo "Test 6: Block Size != 1MB; too small test (1MB - 1)"
9ae3a8
+poke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00"  # invalid (too small)
9ae3a8
+_img_info
9ae3a8
+echo
9ae3a8
+echo "Test 7: Block Size != 1MB; too large test (1MB + 1)"
9ae3a8
+poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00"  # invalid (too large)
9ae3a8
+_img_info
9ae3a8
+# success, all done
9ae3a8
+echo
9ae3a8
+echo "*** done"
9ae3a8
+rm -f $seq.full
9ae3a8
+status=0
9ae3a8
diff --git a/tests/qemu-iotests/084.out b/tests/qemu-iotests/084.out
9ae3a8
new file mode 100644
9ae3a8
index 0000000..99c8e74
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/084.out
9ae3a8
@@ -0,0 +1,33 @@
9ae3a8
+QA output created by 084
9ae3a8
+
9ae3a8
+=== Testing image size bounds ===
9ae3a8
+
9ae3a8
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
9ae3a8
+Test 1: Maximum size (1024 TB):
9ae3a8
+image: TEST_DIR/t.IMGFMT
9ae3a8
+file format: IMGFMT
9ae3a8
+virtual size: 1024T (1125899905794048 bytes)
9ae3a8
+cluster_size: 1048576
9ae3a8
+
9ae3a8
+Test 2: Size too large (1024TB + 1)
9ae3a8
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Invalid argument
9ae3a8
+
9ae3a8
+Test 3: Size valid (64M), but Blocks In Image too small (63)
9ae3a8
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
9ae3a8
+
9ae3a8
+Test 4: Size valid (64M), but Blocks In Image exceeds max allowed
9ae3a8
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
9ae3a8
+
9ae3a8
+Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB
9ae3a8
+image: TEST_DIR/t.IMGFMT
9ae3a8
+file format: IMGFMT
9ae3a8
+virtual size: 64M (67108864 bytes)
9ae3a8
+cluster_size: 1048576
9ae3a8
+
9ae3a8
+Test 6: Block Size != 1MB; too small test (1MB - 1)
9ae3a8
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
9ae3a8
+
9ae3a8
+Test 7: Block Size != 1MB; too large test (1MB + 1)
9ae3a8
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Operation not supported
9ae3a8
+
9ae3a8
+*** done
9ae3a8
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
9ae3a8
index fc34194..e8ad780 100644
9ae3a8
--- a/tests/qemu-iotests/group
9ae3a8
+++ b/tests/qemu-iotests/group
9ae3a8
@@ -77,5 +77,6 @@
9ae3a8
 079 rw auto
9ae3a8
 080 rw auto
9ae3a8
 082 rw auto quick
9ae3a8
+084 img auto
9ae3a8
 086 rw auto quick
9ae3a8
 088 rw auto
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8