From nobody Fri Oct 24 20:19:13 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 1520353366258386.04476650081494; Tue, 6 Mar 2018 08:22:46 -0800 (PST) Received: from localhost ([::1]:56719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etFMT-00057V-CV for importer@patchew.org; Tue, 06 Mar 2018 11:22:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etFEs-0007MD-Gj for qemu-devel@nongnu.org; Tue, 06 Mar 2018 11:14:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etFEn-00080Y-VV for qemu-devel@nongnu.org; Tue, 06 Mar 2018 11:14:54 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52573) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1etFEn-0007zl-Ig; 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-0002oA-QL; Tue, 06 Mar 2018 17:14:46 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1etFET-0006Ym-4Y; 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=8vMR3nS2TcfqUbuDoFYDHv+2jhPErEgY7hwSgAFo+eU=; b=pEohsFH2L4zVUd8t/7yOTVMIPdWJhdNIsVZK68Lji2giiKPEfyDvB6qBj6s6DnsV2CqHRRBDW2kY9Bq/fARQspvTB0yWqlBf5yoj1Vs/ed8784Io7DSymP3wtujvkrO3EdfV69m8DVe3mKAroLYm1p5AXUsDhzQEeMU1jhWNUlFPYjd3df2DPx1oxzu2YKnFkDJslT4BpeUNksEzFJ4BpW3lJtCruqemFGi2OTEP8f2nvgps311mSOv4SLI8yqTcmAGJ5oKUv7waO+mfiNzzv5up7nQD7RBD3zXFI1aIW7jrwVkZirQepoAlkvUam+Fe9KAa/fXpkyoZFRTMbXeXaQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 18:14:10 +0200 Message-Id: <483061de4af377793c1de733d1160dc6655496f8.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 5/7] qcow2: Check snapshot L1 table in qcow2_snapshot_goto() 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" This function copies a snapshot's L1 table into the active one without validating it first. We now have a function to take care of this, so let's use it. Signed-off-by: Alberto Garcia Cc: Eric Blake Reviewed-by: Eric Blake --- block/qcow2-snapshot.c | 9 +++++++++ tests/qemu-iotests/080 | 2 ++ tests/qemu-iotests/080.out | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index bf94f4f434..0faf728dc4 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -465,6 +465,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const cha= r *snapshot_id) { BDRVQcow2State *s =3D bs->opaque; QCowSnapshot *sn; + Error *local_err =3D NULL; int i, snapshot_index; int cur_l1_bytes, sn_l1_bytes; int ret; @@ -477,6 +478,14 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const ch= ar *snapshot_id) } sn =3D &s->snapshots[snapshot_index]; =20 + ret =3D qcow2_validate_table(bs, sn->l1_table_offset, sn->l1_size, + sizeof(uint64_t), QCOW_MAX_L1_SIZE, + "Snapshot L1 table", &local_err); + if (ret < 0) { + error_report_err(local_err); + goto fail; + } + if (sn->disk_size !=3D bs->total_sectors * BDRV_SECTOR_SIZE) { error_report("qcow2: Loading snapshots with different disk " "size is not implemented"); diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 index 018f815697..538857310f 100755 --- a/tests/qemu-iotests/080 +++ b/tests/qemu-iotests/080 @@ -180,6 +180,7 @@ poke_file "$TEST_IMG" "$offset_snap1_l1_offset" "\x00\x= 00\x00\x00\x00\x40\x02\x0 { $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 +{ $QEMU_IMG snapshot -a test $TEST_IMG; } 2>&1 | _filter_testdir =20 echo echo "=3D=3D Invalid snapshot L1 table size =3D=3D" @@ -191,6 +192,7 @@ poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x00= \x00\x00" { $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 +{ $QEMU_IMG snapshot -a test $TEST_IMG; } 2>&1 | _filter_testdir =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index d622ac06c0..1525e1b087 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -68,6 +68,8 @@ 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 +qemu-img: Snapshot L1 table offset invalid +qemu-img: Could not apply snapshot 'test': Failed to load snapshot: Invali= d argument =20 =3D=3D Invalid snapshot L1 table size =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 @@ -78,4 +80,6 @@ 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 +qemu-img: Snapshot L1 table too large +qemu-img: Could not apply snapshot 'test': Failed to load snapshot: File t= oo large *** done --=20 2.11.0