qcow2: Do not overflow when writing an L1 sector
PATCH 2/2 iotests: Add test for qcow2 L1 table update
In reply to Max ReitzUpdating the L1 table should not result in random data being written. This adds a test for that.
--- tests/qemu-iotests/107 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/107.out | 10 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 72 insertions(+) create mode 100755 tests/qemu-iotests/107 create mode 100644 tests/qemu-iotests/107.out
tests/qemu-iotests/107 new file +61 -0
@@ -0,0 +1,61 @@ +#!/bin/bash +# +# Tests updates of the qcow2 L1 table +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + + +IMG_SIZE=64K + +echo +echo '=== Updates should not write random data ===' +echo + +_make_test_img $IMG_SIZE +$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "open -o driver=raw $TEST_IMG" -c 'read -p -P 0 196616 65528' \ + | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 +
tests/qemu-iotests/107.out new file +10 -0
@@ -0,0 +1,10 @@ +QA output created by 107 + +=== Updates should not write random data === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536 +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65528/65528 bytes at offset 196616 +63.992 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done
tests/qemu-iotests/group +1 -0
@@ -106,3 +106,4 @@ 103 rw auto quick 104 rw auto 105 rw auto quick +107 rw auto quick
Signature · 1 line
2.1.2
cover qcow2: Do not overflow when writing an L1 sector
qcow2_write_l1_entry() may read L1 entries from beyond the end of the in-memory L1 table when updating a sector. Fix this and add a qemu-iotest.
Max Reitz (2):
qcow2: Do not overflow when writing an L1 sector
iotests: Add test for qcow2 L1 table update
block/qcow2-cluster.c | 6 +++-- tests/qemu-iotests/107 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/107.out | 10 ++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 tests/qemu-iotests/107 create mode 100644 tests/qemu-iotests/107.out
Signature · 1 line
2.1.2
PATCH 1/2 qcow2: Do not overflow when writing an L1 sector
While writing an L1 table sector, qcow2_write_l1_entry() copies the respective range from s->l1_table to the local "buf" array. The size of s->l1_table does not have to be a multiple of L1_ENTRIES_PER_SECTOR; thus, limit the index which is used for copying all entries to the L1 size.
--- block/qcow2-cluster.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
block/qcow2-cluster.c +4 -2
@@ -164,12 +164,14 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset,int qcow2_write_l1_entry (BlockDriverState *bs,int l1_index) {BDRVQcowState *s = bs->opaque; -uint64_t buf[L1_ENTRIES_PER_SECTOR ]; +uint64_t buf[L1_ENTRIES_PER_SECTOR ] = {0 };int l1_start_index;int i, ret; l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR -1 ); -for (i =0 ; i <L1_ENTRIES_PER_SECTOR ; i++) { +for (i =0 ; i <L1_ENTRIES_PER_SECTOR && l1_start_index + i < s->l1_size; + i++) + { buf[i] =cpu_to_be64 (s->l1_table[l1_start_index + i]); }
Signature · 1 line
2.1.2
Quoted 8 lines · Max Reitz
qcow2_write_l1_entry()may read L1 entries from beyond the end of the in-memory L1 table when updating a sector. Fix this and add a qemu-iotest.Max Reitz (2):
qcow2: Do not overflow when writing an L1 sector
iotests: Add test for qcow2 L1 table update
Series:
Quoted 9 lines
block/qcow2-cluster.c | 6 +++-- tests/qemu-iotests/107 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/107.out | 10 ++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 tests/qemu-iotests/107 create mode 100644 tests/qemu-iotests/107.out
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 23 lines · Max Reitz
While writing an L1 table sector,
qcow2_write_l1_entry()copies the respective range froms->l1_tableto the local "buf" array. The size ofs->l1_tabledoes not have to be a multiple ofL1_ENTRIES_PER_SECTOR; thus, limit the index which is used for copying all entries to the L1 size.Signed-off-by Max Reitz <[email protected]>--- block/qcow2-cluster.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)block/qcow2-cluster.c +1
-1@@ -164,12 +164,14 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset,int qcow2_write_l1_entry (BlockDriverState *bs,int l1_index) {BDRVQcowState *s = bs->opaque; -uint64_t buf[L1_ENTRIES_PER_SECTOR ]; +uint64_t buf[L1_ENTRIES_PER_SECTOR ] = {0 };int l1_start_index;
block/qcow2-cluster.c static int l2_load(BlockDriverState *bs, uint64_t l2_offset, · line 177
Quoted 10 lines
block/qcow2-cluster.c +3
-1int i, ret; l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR -1 ); -for (i =0 ; i <L1_ENTRIES_PER_SECTOR ; i++) { +for (i =0 ; i <L1_ENTRIES_PER_SECTOR && l1_start_index + i < s->l1_size; + i++) + { buf[i] =cpu_to_be64 (s->l1_table[l1_start_index + i]); }
Re: [Qemu-devel] [PATCH 2/2] iotests: Add test for qcow2 L1 table update
In reply to Max ReitzQuoted 50 lines · Max Reitz
Updating the L1 table should not result in random data being written. This adds a test for that.
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/107 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/107.out | 10 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 72 insertions(+)create mode 100755 tests/qemu-iotests/107
create mode 100644 tests/qemu-iotests/107.outtests/qemu-iotests/107 new file +32
-0@@ -0,0 +1,61 @@ +#!/bin/bash +# +# Tests updates of the qcow2 L1 table +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{
tests/qemu-iotests/107 line 42
Quoted 10 lines
tests/qemu-iotests/107 new file +10
-0+ _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file
This (and maybe other recently added tests) also works on NFS. As NFS on QCOW2 might be a reasonable combination I would add it.
Peter
Re: [Qemu-devel] [PATCH 2/2] iotests: Add test for qcow2 L1 table update
Quoted 57 lines · Peter Lieven
Quoted 56 lines · Max Reitz
Updating the L1 table should not result in random data being written. This adds a test for that.
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/107 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/107.out | 10 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 72 insertions(+)create mode 100755 tests/qemu-iotests/107
create mode 100644 tests/qemu-iotests/107.outtests/qemu-iotests/107 new file +37
-0@@ -0,0 +1,61 @@ +#!/bin/bash +# +# Tests updates of the qcow2 L1 table +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks
Quoted 8 lines
tests/qemu-iotests/107 line 42
Quoted 5 lines
tests/qemu-iotests/107 new file +5
-0+. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto fileThis (and maybe other recently added tests) also works on NFS. As NFS on QCOW2 might be a reasonable combination I would add it.
It probably works over some other protocols as well. I think we want to go through all the tests in a separate series and fix all of these cases. I'll fix it in a v2 if I need to do a v2, if not, I'll leave it as-is. If you want to test qcow2, you want to run all tests over file, probably. If you want to test nfs, you probably don't want to use qcow2 but raw (because many of the currently existing tests are too limited in their format and protocol choices).
Since you suggested looking into which tests actually support more formats and protocols than they currently pretend to, feel free to send such a series. ;-)
Max
Re: [Qemu-devel] [PATCH 2/2] iotests: Add test for qcow2 L1 table update
Quoted 66 lines · Max Reitz
Quoted 56 lines · Peter Lieven
Quoted 55 lines · Max Reitz
Updating the L1 table should not result in random data being written. This adds a test for that.
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/107 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/107.out | 10 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 72 insertions(+)create mode 100755 tests/qemu-iotests/107
create mode 100644 tests/qemu-iotests/107.outtests/qemu-iotests/107 new file +37
-0@@ -0,0 +1,61 @@ +#!/bin/bash +# +# Tests updates of the qcow2 L1 table +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checksQuoted 8 lines
tests/qemu-iotests/107 line 42
Quoted 5 lines
tests/qemu-iotests/107 new file +5
-0+. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto fileThis (and maybe other recently added tests) also works on NFS. As NFS on QCOW2 might be a reasonable combination I would add it.
Quoted 3 lines
It probably works over some other protocols as well. I think we want to go through all the tests in a separate series and fix all of these cases. I'll fix it in a v2 if I need to do a v2, if not, I'll leave it as-is. If you want to test qcow2, you want to run all tests over file, probably. If you want to test nfs, you probably don't want to use qcow2 but raw (because many of the currently existing tests are too limited in their format and protocol choices).
Since you suggested looking into which tests actually support more formats and protocols than they currently pretend to, feel free to send such a series. ;-)
I actually did when writing the NFS driver. I did modifications to a lot of tests to support other protocols. But the approach was too hackish. But I would like to see at least the tests that work without modifications to have supported protocols listed. And as someone likely will use a QCOW2 container on NFS I think is is an important test case. At least to have all the tests included that are working out of the box.
Peter
Kevin Wolf
AppliedAm 16.10.2014 um 15:25 hat Max Reitz geschrieben:
Quoted 3 lines
qcow2_write_l1_entry()may read L1 entries from beyond the end of the in-memory L1 table when updating a sector. Fix this and add a qemu-iotest.
Thanks, applied to the block branch.
Kevin