From nobody Fri Oct 24 22:18:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520353394508359.7096617509319; Tue, 6 Mar 2018 08:23:14 -0800 (PST) Received: from localhost ([::1]:56720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etFMv-0005To-O1 for importer@patchew.org; Tue, 06 Mar 2018 11:23:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etFEs-0007MR-Od for qemu-devel@nongnu.org; Tue, 06 Mar 2018 11:14:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etFEo-00080z-1j for qemu-devel@nongnu.org; Tue, 06 Mar 2018 11:14:54 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52559) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1etFEn-0007zj-Jp; Tue, 06 Mar 2018 11:14:49 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1etFEk-0002o7-TU; Tue, 06 Mar 2018 17:14:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1etFET-0006Yk-3a; Tue, 06 Mar 2018 18:14:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Pytc/yvI10zU4V7a/YL3MJM8FhAdqXZ7D/MuWlQ4p7M=; b=ce5KVEwhOcsXZCmVcwRl6vft2+GiTW71FvTiK9rCv4I7jdhpQZ8c7rrXcw9DT+3OAUni66kdPobNuzvvTvgKuCTrkIRhWgCGP/ZTmL1OwVXGfAgLtGB6+epe/gqnpEHiauXK5eROcXpa0tTg/O+z9PBVjoEcMyq5XOfs6dq2J/49hHBdHuiB2jeaciYoT8BtTjHkxUhewNcci2CQahvTOcwVuCDowFRD+rBkbfXfJmkaw+nMhGlM+TPTf2gWT+FRGPtsUEqLvGEetjd4w3JhPfF5wSICdCeinsn81qLj8hkBL2DSnnXMWe2D0SMvkhll0r6rgq/R7qngOhqOM0WHwQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 18:14:09 +0200 Message-Id: <9c2d3f530811be74521e2963f51bd8f23770879f.1520352600.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 4/7] qcow2: Check snapshot L1 tables in qcow2_check_metadata_overlap() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The inactive-l2 overlap check iterates uses the L1 tables from all snapshots, but it does not validate them first. We now have a function to take care of this, so let's use it. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- block/qcow2-refcount.c | 10 +++++++++- tests/qemu-iotests/080 | 4 ++++ tests/qemu-iotests/080.out | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 126cca3276..443ec0a6e5 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -2614,9 +2614,17 @@ int qcow2_check_metadata_overlap(BlockDriverState *b= s, int ign, int64_t offset, uint64_t l1_ofs =3D s->snapshots[i].l1_table_offset; uint32_t l1_sz =3D s->snapshots[i].l1_size; uint64_t l1_sz2 =3D l1_sz * sizeof(uint64_t); - uint64_t *l1 =3D g_try_malloc(l1_sz2); + uint64_t *l1; int ret; =20 + ret =3D qcow2_validate_table(bs, l1_ofs, l1_sz, sizeof(uint64_= t), + QCOW_MAX_L1_SIZE, "", NULL); + if (ret < 0) { + return ret; + } + + l1 =3D g_try_malloc(l1_sz2); + if (l1_sz2 && l1 =3D=3D NULL) { return -ENOMEM; } diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 index 5622604f83..018f815697 100755 --- a/tests/qemu-iotests/080 +++ b/tests/qemu-iotests/080 @@ -178,6 +178,8 @@ _make_test_img 64M poke_file "$TEST_IMG" "$offset_snap1_l1_offset" "\x00\x00\x00\x00\x00\x40\= x02\x00" { $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_tes= tdir { $QEMU_IMG amend -o compat=3D0.10 $TEST_IMG; } 2>&1 | _filter_testdir +{ $QEMU_IO -c "open -o overlap-check.inactive-l2=3Don $TEST_IMG" \ + -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir =20 echo echo "=3D=3D Invalid snapshot L1 table size =3D=3D" @@ -187,6 +189,8 @@ _make_test_img 64M poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x00\x00\x00" { $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_tes= tdir { $QEMU_IMG amend -o compat=3D0.10 $TEST_IMG; } 2>&1 | _filter_testdir +{ $QEMU_IO -c "open -o overlap-check.inactive-l2=3Don $TEST_IMG" \ + -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index 315edbc26f..d622ac06c0 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -66,6 +66,8 @@ wrote 512/512 bytes at offset 0 qemu-img: Failed to load snapshot: Snapshot L1 table offset invalid qemu-img: Snapshot L1 table offset invalid qemu-img: Error while amending options: Invalid argument +Failed to flush the refcount block cache: Invalid argument +write failed: Invalid argument =20 =3D=3D Invalid snapshot L1 table size =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 @@ -74,4 +76,6 @@ wrote 512/512 bytes at offset 0 qemu-img: Failed to load snapshot: Snapshot L1 table too large qemu-img: Snapshot L1 table too large qemu-img: Error while amending options: File too large +Failed to flush the refcount block cache: File too large +write failed: File too large *** done --=20 2.11.0