124342f2cSKevin Wolf#!/bin/bash 224342f2cSKevin Wolf# 324342f2cSKevin Wolf# qcow2 format input validation tests 424342f2cSKevin Wolf# 524342f2cSKevin Wolf# Copyright (C) 2013 Red Hat, Inc. 624342f2cSKevin Wolf# 724342f2cSKevin Wolf# This program is free software; you can redistribute it and/or modify 824342f2cSKevin Wolf# it under the terms of the GNU General Public License as published by 924342f2cSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1024342f2cSKevin Wolf# (at your option) any later version. 1124342f2cSKevin Wolf# 1224342f2cSKevin Wolf# This program is distributed in the hope that it will be useful, 1324342f2cSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1424342f2cSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1524342f2cSKevin Wolf# GNU General Public License for more details. 1624342f2cSKevin Wolf# 1724342f2cSKevin Wolf# You should have received a copy of the GNU General Public License 1824342f2cSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 1924342f2cSKevin Wolf# 2024342f2cSKevin Wolf 2124342f2cSKevin Wolf# creator 2224342f2cSKevin Wolfowner=kwolf@redhat.com 2324342f2cSKevin Wolf 2424342f2cSKevin Wolfseq=`basename $0` 2524342f2cSKevin Wolfecho "QA output created by $seq" 2624342f2cSKevin Wolf 2724342f2cSKevin Wolfhere=`pwd` 2824342f2cSKevin Wolftmp=/tmp/$$ 2924342f2cSKevin Wolfstatus=1 # failure is the default! 3024342f2cSKevin Wolf 3124342f2cSKevin Wolf_cleanup() 3224342f2cSKevin Wolf{ 3324342f2cSKevin Wolf _cleanup_test_img 3424342f2cSKevin Wolf} 3524342f2cSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3624342f2cSKevin Wolf 3724342f2cSKevin Wolf# get standard environment, filters and checks 3824342f2cSKevin Wolf. ./common.rc 3924342f2cSKevin Wolf. ./common.filter 4024342f2cSKevin Wolf 4124342f2cSKevin Wolf_supported_fmt qcow2 4224342f2cSKevin Wolf_supported_proto generic 4324342f2cSKevin Wolf_supported_os Linux 4424342f2cSKevin Wolf 4524342f2cSKevin Wolfheader_size=104 46a1b3955cSKevin Wolf 47a1b3955cSKevin Wolfoffset_backing_file_offset=8 48*2d51c32cSKevin Wolfoffset_l1_size=36 49*2d51c32cSKevin Wolfoffset_l1_table_offset=40 508c7de283SKevin Wolfoffset_refcount_table_offset=48 515dab2fadSKevin Wolfoffset_refcount_table_clusters=56 52ce48f2f4SKevin Wolfoffset_nb_snapshots=60 53ce48f2f4SKevin Wolfoffset_snapshots_offset=64 5424342f2cSKevin Wolfoffset_header_size=100 5524342f2cSKevin Wolfoffset_ext_magic=$header_size 5624342f2cSKevin Wolfoffset_ext_size=$((header_size + 4)) 5724342f2cSKevin Wolf 5824342f2cSKevin Wolfecho 5924342f2cSKevin Wolfecho "== Huge header size ==" 6024342f2cSKevin Wolf_make_test_img 64M 6124342f2cSKevin Wolfpoke_file "$TEST_IMG" "$offset_header_size" "\xff\xff\xff\xff" 6224342f2cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 6324342f2cSKevin Wolfpoke_file "$TEST_IMG" "$offset_header_size" "\x7f\xff\xff\xff" 6424342f2cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 6524342f2cSKevin Wolf 66a1b3955cSKevin Wolfecho 67a1b3955cSKevin Wolfecho "== Huge unknown header extension ==" 68a1b3955cSKevin Wolf_make_test_img 64M 69a1b3955cSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_offset" "\xff\xff\xff\xff\xff\xff\xff\xff" 70a1b3955cSKevin Wolfpoke_file "$TEST_IMG" "$offset_ext_magic" "\x12\x34\x56\x78" 71a1b3955cSKevin Wolfpoke_file "$TEST_IMG" "$offset_ext_size" "\x7f\xff\xff\xff" 72a1b3955cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 73a1b3955cSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" 74a1b3955cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 75a1b3955cSKevin Wolf 765dab2fadSKevin Wolfecho 775dab2fadSKevin Wolfecho "== Huge refcount table size ==" 785dab2fadSKevin Wolf_make_test_img 64M 795dab2fadSKevin Wolfpoke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\xff\xff\xff\xff" 805dab2fadSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 815dab2fadSKevin Wolfpoke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x02\x00\x01" 825dab2fadSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 835dab2fadSKevin Wolf 848c7de283SKevin Wolfecho 858c7de283SKevin Wolfecho "== Misaligned refcount table ==" 868c7de283SKevin Wolf_make_test_img 64M 878c7de283SKevin Wolfpoke_file "$TEST_IMG" "$offset_refcount_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" 888c7de283SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 898c7de283SKevin Wolf 908c7de283SKevin Wolfecho 918c7de283SKevin Wolfecho "== Huge refcount offset ==" 928c7de283SKevin Wolf_make_test_img 64M 938c7de283SKevin Wolfpoke_file "$TEST_IMG" "$offset_refcount_table_offset" "\xff\xff\xff\xff\xff\xff\x00\x00" 948c7de283SKevin Wolfpoke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x00\x00\x7f" 958c7de283SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 965dab2fadSKevin Wolf 97ce48f2f4SKevin Wolfecho 98ce48f2f4SKevin Wolfecho "== Invalid snapshot table ==" 99ce48f2f4SKevin Wolf_make_test_img 64M 100ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_nb_snapshots" "\xff\xff\xff\xff" 101ce48f2f4SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 102ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_nb_snapshots" "\x7f\xff\xff\xff" 103ce48f2f4SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 104ce48f2f4SKevin Wolf 105ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_snapshots_offset" "\xff\xff\xff\xff\xff\xff\x00\x00" 106ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\xff\xff" 107ce48f2f4SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 108ce48f2f4SKevin Wolf 109ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_snapshots_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" 110ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\x00\x00" 111ce48f2f4SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 112ce48f2f4SKevin Wolf 113ce48f2f4SKevin Wolfecho 114ce48f2f4SKevin Wolfecho "== Hitting snapshot table size limit ==" 115ce48f2f4SKevin Wolf_make_test_img 64M 116ce48f2f4SKevin Wolf# Put the refcount table in a more or less safe place (16 MB) 117ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_snapshots_offset" "\x00\x00\x00\x00\x01\x00\x00\x00" 118ce48f2f4SKevin Wolfpoke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x01\x00\x00" 119ce48f2f4SKevin Wolf{ $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir 120ce48f2f4SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 121ce48f2f4SKevin Wolf 122*2d51c32cSKevin Wolfecho 123*2d51c32cSKevin Wolfecho "== Invalid L1 table ==" 124*2d51c32cSKevin Wolf_make_test_img 64M 125*2d51c32cSKevin Wolfpoke_file "$TEST_IMG" "$offset_l1_size" "\xff\xff\xff\xff" 126*2d51c32cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 127*2d51c32cSKevin Wolfpoke_file "$TEST_IMG" "$offset_l1_size" "\x7f\xff\xff\xff" 128*2d51c32cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 129*2d51c32cSKevin Wolf 130*2d51c32cSKevin Wolfpoke_file "$TEST_IMG" "$offset_l1_table_offset" "\x7f\xff\xff\xff\xff\xff\x00\x00" 131*2d51c32cSKevin Wolfpoke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\xff\xff" 132*2d51c32cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 133*2d51c32cSKevin Wolf 134*2d51c32cSKevin Wolfpoke_file "$TEST_IMG" "$offset_l1_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" 135*2d51c32cSKevin Wolfpoke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x01" 136*2d51c32cSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 137*2d51c32cSKevin Wolf 13824342f2cSKevin Wolf# success, all done 13924342f2cSKevin Wolfecho "*** done" 14024342f2cSKevin Wolfrm -f $seq.full 14124342f2cSKevin Wolfstatus=0 142