]>
Commit | Line | Data |
---|---|---|
24342f2c KW |
1 | #!/bin/bash |
2 | # | |
3 | # qcow2 format input validation tests | |
4 | # | |
5 | # Copyright (C) 2013 Red Hat, Inc. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | [email protected] | |
23 | ||
24 | seq=`basename $0` | |
25 | echo "QA output created by $seq" | |
26 | ||
27 | here=`pwd` | |
24342f2c KW |
28 | status=1 # failure is the default! |
29 | ||
30 | _cleanup() | |
31 | { | |
6a83f8b5 KW |
32 | rm -f $TEST_IMG.snap |
33 | _cleanup_test_img | |
24342f2c KW |
34 | } |
35 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
36 | ||
37 | # get standard environment, filters and checks | |
38 | . ./common.rc | |
39 | . ./common.filter | |
40 | ||
41 | _supported_fmt qcow2 | |
c5f7c0af | 42 | _supported_proto file |
24342f2c | 43 | _supported_os Linux |
94254c9b HR |
44 | # - Internal snapshots are (currently) impossible with refcount_bits=1 |
45 | # - This is generally a test for compat=1.1 images | |
46 | _unsupported_imgopts 'refcount_bits=1[^0-9]' 'compat=0.10' | |
24342f2c KW |
47 | |
48 | header_size=104 | |
a1b3955c KW |
49 | |
50 | offset_backing_file_offset=8 | |
6d33e8e7 | 51 | offset_backing_file_size=16 |
2d51c32c KW |
52 | offset_l1_size=36 |
53 | offset_l1_table_offset=40 | |
8c7de283 | 54 | offset_refcount_table_offset=48 |
5dab2fad | 55 | offset_refcount_table_clusters=56 |
ce48f2f4 KW |
56 | offset_nb_snapshots=60 |
57 | offset_snapshots_offset=64 | |
24342f2c KW |
58 | offset_header_size=100 |
59 | offset_ext_magic=$header_size | |
60 | offset_ext_size=$((header_size + 4)) | |
61 | ||
b106ad91 KW |
62 | offset_l2_table_0=$((0x40000)) |
63 | ||
6a83f8b5 KW |
64 | offset_snap1=$((0x70000)) |
65 | offset_snap1_l1_offset=$((offset_snap1 + 0)) | |
66 | offset_snap1_l1_size=$((offset_snap1 + 8)) | |
67 | ||
24342f2c KW |
68 | echo |
69 | echo "== Huge header size ==" | |
70 | _make_test_img 64M | |
71 | poke_file "$TEST_IMG" "$offset_header_size" "\xff\xff\xff\xff" | |
72 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
73 | poke_file "$TEST_IMG" "$offset_header_size" "\x7f\xff\xff\xff" | |
74 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
75 | ||
a1b3955c KW |
76 | echo |
77 | echo "== Huge unknown header extension ==" | |
78 | _make_test_img 64M | |
79 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\xff\xff\xff\xff\xff\xff\xff\xff" | |
80 | poke_file "$TEST_IMG" "$offset_ext_magic" "\x12\x34\x56\x78" | |
81 | poke_file "$TEST_IMG" "$offset_ext_size" "\x7f\xff\xff\xff" | |
82 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
2ebafc85 KW |
83 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x$(printf %x $offset_ext_size)" |
84 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
a1b3955c KW |
85 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" |
86 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
87 | ||
5dab2fad KW |
88 | echo |
89 | echo "== Huge refcount table size ==" | |
90 | _make_test_img 64M | |
91 | poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\xff\xff\xff\xff" | |
92 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
93 | poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x02\x00\x01" | |
94 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
95 | ||
8c7de283 KW |
96 | echo |
97 | echo "== Misaligned refcount table ==" | |
98 | _make_test_img 64M | |
99 | poke_file "$TEST_IMG" "$offset_refcount_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" | |
100 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
101 | ||
102 | echo | |
103 | echo "== Huge refcount offset ==" | |
104 | _make_test_img 64M | |
105 | poke_file "$TEST_IMG" "$offset_refcount_table_offset" "\xff\xff\xff\xff\xff\xff\x00\x00" | |
106 | poke_file "$TEST_IMG" "$offset_refcount_table_clusters" "\x00\x00\x00\x7f" | |
107 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
5dab2fad | 108 | |
ce48f2f4 KW |
109 | echo |
110 | echo "== Invalid snapshot table ==" | |
111 | _make_test_img 64M | |
112 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\xff\xff\xff\xff" | |
113 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
114 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x7f\xff\xff\xff" | |
115 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
116 | ||
117 | poke_file "$TEST_IMG" "$offset_snapshots_offset" "\xff\xff\xff\xff\xff\xff\x00\x00" | |
118 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\xff\xff" | |
119 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
120 | ||
121 | poke_file "$TEST_IMG" "$offset_snapshots_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" | |
122 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x00\x00\x00" | |
123 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
124 | ||
125 | echo | |
126 | echo "== Hitting snapshot table size limit ==" | |
127 | _make_test_img 64M | |
128 | # Put the refcount table in a more or less safe place (16 MB) | |
129 | poke_file "$TEST_IMG" "$offset_snapshots_offset" "\x00\x00\x00\x00\x01\x00\x00\x00" | |
130 | poke_file "$TEST_IMG" "$offset_nb_snapshots" "\x00\x01\x00\x00" | |
131 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir | |
132 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
133 | ||
2d51c32c KW |
134 | echo |
135 | echo "== Invalid L1 table ==" | |
136 | _make_test_img 64M | |
137 | poke_file "$TEST_IMG" "$offset_l1_size" "\xff\xff\xff\xff" | |
138 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
139 | poke_file "$TEST_IMG" "$offset_l1_size" "\x7f\xff\xff\xff" | |
140 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
141 | ||
142 | poke_file "$TEST_IMG" "$offset_l1_table_offset" "\x7f\xff\xff\xff\xff\xff\x00\x00" | |
143 | poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\xff\xff" | |
144 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
145 | ||
146 | poke_file "$TEST_IMG" "$offset_l1_table_offset" "\x12\x34\x56\x78\x90\xab\xcd\xef" | |
147 | poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x01" | |
148 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
149 | ||
11b128f4 KW |
150 | echo |
151 | echo "== Invalid L1 table (with internal snapshot in the image) ==" | |
152 | _make_test_img 64M | |
153 | { $QEMU_IMG snapshot -c foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
154 | poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x00" | |
155 | _img_info | |
156 | ||
6d33e8e7 KW |
157 | echo |
158 | echo "== Invalid backing file size ==" | |
159 | _make_test_img 64M | |
160 | poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\x00\x00\x00\x10\x00" | |
161 | poke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff" | |
162 | { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
163 | ||
b106ad91 KW |
164 | echo |
165 | echo "== Invalid L2 entry (huge physical offset) ==" | |
166 | _make_test_img 64M | |
167 | { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
168 | poke_file "$TEST_IMG" "$offset_l2_table_0" "\xbf\xff\xff\xff\xff\xff\x00\x00" | |
169 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
170 | poke_file "$TEST_IMG" "$offset_l2_table_0" "\x80\x00\x00\xff\xff\xff\x00\x00" | |
171 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
172 | ||
6a83f8b5 | 173 | echo |
314e8d39 AG |
174 | echo "== Invalid snapshot L1 table offset ==" |
175 | _make_test_img 64M | |
176 | { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
177 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir | |
178 | poke_file "$TEST_IMG" "$offset_snap1_l1_offset" "\x00\x00\x00\x00\x00\x40\x02\x00" | |
179 | { $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_testdir | |
c9a442e4 | 180 | { $QEMU_IMG amend -o compat=0.10 $TEST_IMG; } 2>&1 | _filter_testdir |
c7a9d81d AG |
181 | { $QEMU_IO -c "open -o overlap-check.inactive-l2=on $TEST_IMG" \ |
182 | -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir | |
314e8d39 AG |
183 | |
184 | echo | |
185 | echo "== Invalid snapshot L1 table size ==" | |
6a83f8b5 KW |
186 | _make_test_img 64M |
187 | { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir | |
188 | { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir | |
189 | poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x00\x00\x00" | |
190 | { $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_testdir | |
c9a442e4 | 191 | { $QEMU_IMG amend -o compat=0.10 $TEST_IMG; } 2>&1 | _filter_testdir |
c7a9d81d AG |
192 | { $QEMU_IO -c "open -o overlap-check.inactive-l2=on $TEST_IMG" \ |
193 | -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir | |
6a83f8b5 | 194 | |
24342f2c KW |
195 | # success, all done |
196 | echo "*** done" | |
197 | rm -f $seq.full | |
198 | status=0 |