From nobody Fri Oct 24 22:18:42 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 1520353364982190.48578085723886; Tue, 6 Mar 2018 08:22:44 -0800 (PST) Received: from localhost ([::1]:56718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etFML-0004xB-8p for importer@patchew.org; Tue, 06 Mar 2018 11:22:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etFEq-0007Kr-RX for qemu-devel@nongnu.org; Tue, 06 Mar 2018 11:14:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etFEo-000814-1X for qemu-devel@nongnu.org; Tue, 06 Mar 2018 11:14:52 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52568) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1etFEn-0007zf-Ie; 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-0002oD-Rp; Tue, 06 Mar 2018 17:14:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1etFET-0006Yg-1Y; 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=RxS4C9RLTELnSQyvir+e6xSsYKU8T6UIx1YeL48Np/g=; b=XIf8BQRyN5juPAWtICL2VJ5mdagOKQEhu6YJYvQfZ0tK8Fpv/ZTFFJuYOR78SCNrRShMsMOWokLtLT3xl6bJ6N6qVa1lwCNFj+5MFdILbeo8KKPDZB2AP8Htrankjv0TeSLhm0TmqKMW+hMVbcuNsMVxu6vZRnKp3Ff2jfwt1onu8CaRigJWs67FVfZRf+pKSGywbhytMb9qpHYbd/dzZmPxuEPam8xv29ahuUBmOy71vz7AkAAJzprskkzO7IpXZIhMHqAnU9t5NnsHZRWNq6IfKO3mEJXSu8SU3oGvtTtWBKWFVz4vIAmupSIuqpYLuGMSqWMQ6wDohw7UigZpXg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 18:14:07 +0200 Message-Id: <5ffd0b1fe2bd978735bbb3338503efdce1fa449b.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 2/7] qcow2: Check L1 table offset in qcow2_snapshot_load_tmp() 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 checks that the size of a snapshot's L1 table is not too large, but it doesn't validate the offset. 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-snapshot.c | 8 +++++--- tests/qemu-iotests/080 | 10 +++++++++- tests/qemu-iotests/080.out | 8 +++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index cee25f582b..bf94f4f434 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -704,9 +704,11 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, sn =3D &s->snapshots[snapshot_index]; =20 /* Allocate and read in the snapshot's L1 table */ - if (sn->l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) { - error_setg(errp, "Snapshot L1 table too large"); - return -EFBIG; + ret =3D qcow2_validate_table(bs, sn->l1_table_offset, sn->l1_size, + sizeof(uint64_t), QCOW_MAX_L1_SIZE, + "Snapshot L1 table", errp); + if (ret < 0) { + return ret; } new_l1_bytes =3D sn->l1_size * sizeof(uint64_t); new_l1_table =3D qemu_try_blockalign(bs->file->bs, diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 index 1c2bd85742..6a10e7defa 100755 --- a/tests/qemu-iotests/080 +++ b/tests/qemu-iotests/080 @@ -171,7 +171,15 @@ poke_file "$TEST_IMG" "$offset_l2_table_0" "\x80\x00\x= 00\xff\xff\xff\x00\x00" { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter= _testdir =20 echo -echo "=3D=3D Invalid snapshot L1 table =3D=3D" +echo "=3D=3D Invalid snapshot L1 table offset =3D=3D" +_make_test_img 64M +{ $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_= testdir +{ $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir +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 + +echo +echo "=3D=3D Invalid snapshot L1 table size =3D=3D" _make_test_img 64M { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_= testdir { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index 4c7790c9ee..f0d9038d55 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -59,7 +59,13 @@ wrote 512/512 bytes at offset 0 qemu-img: Could not create snapshot 'test': -27 (File too large) qemu-img: Could not create snapshot 'test': -11 (Resource temporarily unav= ailable) =20 -=3D=3D Invalid snapshot L1 table =3D=3D +=3D=3D Invalid snapshot L1 table offset =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 +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 + +=3D=3D Invalid snapshot L1 table size =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) --=20 2.11.0