From nobody Fri Oct 24 13:14:16 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 1519921805833361.252235704114; Thu, 1 Mar 2018 08:30:05 -0800 (PST) Received: from localhost ([::1]:57923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erR5k-0000o1-43 for importer@patchew.org; Thu, 01 Mar 2018 11:30:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erR46-0008BV-HA for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:28:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erR41-0004K8-HK for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:28:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:54927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1erR40-0003uM-Te; Thu, 01 Mar 2018 11:28:13 -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 1erR3P-0003Dc-IR; Thu, 01 Mar 2018 17:27:35 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1erR36-0004OW-S0; Thu, 01 Mar 2018 18:27:16 +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=SutdRM4TbbzoQm94sdn/9lSOfZF9w2LL5yxzEinQsU4=; b=Y8MdCZRziuXI5vuxPZ6rh4LmLbU3QOYmHgJ0ZUfmVyiwgz2Q0H9nokAPkDae/wmG0MFQkF2v4/6Nrm3q3FLFtf5kpMrizzzkRgWv2jiHwa3PoJuHPx0VictqK9dSMGylMzBhN+DR8SDYXehqeJZaZaxq+OmUv4EkevxpW49HE+Hs+rgKDX+AR0en8SkkrtLMjgiKvpP8Iz9ZqZ0Acx8DO47BqwC0YwvhA6eHljYF8gA9a2rVmXVTRMiYUsKRgEGbUij59alCJ6KyMRCMGDOaA7Uj04tCaMKEcxjA6ZOMPNzMCj2VHilS/Safo1Usu2Bd43WTRWp3jXh77bVWRrwNfQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 18:27:10 +0200 Message-Id: <39f9a5666cc50c3733d01d4d01fb514a5a5da9a5.1519921268.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 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 d46b69d7f3..dcb96e2b16 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 5d9030ab93..cf8f863be2 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -65,6 +65,8 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Failed to load snapshot: 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 @@ -72,4 +74,6 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Failed to load snapshot: 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