From nobody Fri May 3 14:32:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1567085900; cv=none; d=zoho.com; s=zohoarc; b=Mc5Njn4xX35qXJxjCb582tn0sSh0NqHbiV12CEcEVphMxT9xoUonyfQY4rL/0ihpcRtiPDsbarbvZvPu2kQgz1k3enVc0rtBj82o8ytIxTE4sTooyo70bYnBEGOTSCyIP8Caqp9DTWUl0XkTyKSxp2OH11cl22q+Pul4GqgIjpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567085900; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=hd/GNg7vPfcC3c1gqJHBIo7Iduw++1kqPtnaARl/h+M=; b=GGGa3qHIVILzkVHCfNIvrNsAgo4uFHqSa6ai5BiJrFiWUvAx8WiqBzaMidp94VYMoeqQzXjmXOCh2wY0U/s2HLiOcwcSFctxQB5SF/T2CpO1oa4loT9iH1sVetmWpTo6lgkOe/jZF+no96QgezKuxSL+G09nhb0AfhqsG9Fo8G4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567085900503790.9252946911957; Thu, 29 Aug 2019 06:38:20 -0700 (PDT) Received: from localhost ([::1]:50030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Kd1-00047y-Ew for importer@patchew.org; Thu, 29 Aug 2019 09:38:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56135) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3KbC-0002lz-84 for qemu-devel@nongnu.org; Thu, 29 Aug 2019 09:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3KbA-00087B-Nm for qemu-devel@nongnu.org; Thu, 29 Aug 2019 09:36:25 -0400 Received: from kerio.kamp.de ([195.62.97.192]:36815) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i3KbA-0007wT-Fq for qemu-devel@nongnu.org; Thu, 29 Aug 2019 09:36:24 -0400 Received: from submission.kamp.de ([195.62.97.28]) by kerio.kamp.de with ESMTPS (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) for qemu-devel@nongnu.org; Thu, 29 Aug 2019 15:36:13 +0200 Received: (qmail 56887 invoked from network); 29 Aug 2019 13:36:15 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 29 Aug 2019 13:36:15 -0000 Received: by lieven-pc (Postfix, from userid 1060) id D72C313DF82; Thu, 29 Aug 2019 15:36:15 +0200 (CEST) X-Footer: a2FtcC5kZQ== From: Peter Lieven To: qemu-block@nongnu.org Date: Thu, 29 Aug 2019 15:36:15 +0200 Message-Id: <20190829133615.29873-1-pl@kamp.de> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.62.97.192 Subject: [Qemu-devel] [PATCH] block/vhdx: add check for truncated image files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, codyprime@gmail.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com, Jan-Hendrik Frintrop Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qemu is currently not able to detect truncated vhdx image files. Add a basic check if all allocated blocks are reachable to vhdx_co_check. Signed-off-by: Jan-Hendrik Frintrop Signed-off-by: Peter Lieven --- block/vhdx.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/vhdx.c b/block/vhdx.c index 6a09d0a55c..4382b1375d 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2068,10 +2068,29 @@ static int coroutine_fn vhdx_co_check(BlockDriverSt= ate *bs, BdrvCheckMode fix) { BDRVVHDXState *s =3D bs->opaque; + VHDXSectorInfo sinfo; + int64_t file_size =3D bdrv_get_allocated_file_size(bs); + int64_t sector_num; =20 if (s->log_replayed_on_open) { result->corruptions_fixed++; } + + for (sector_num =3D 0; sector_num < bs->total_sectors; + sector_num +=3D s->block_size / BDRV_SECTOR_SIZE) { + int nb_sectors =3D MIN(bs->total_sectors - sector_num, + s->block_size / BDRV_SECTOR_SIZE); + vhdx_block_translate(s, sector_num, nb_sectors, &sinfo); + if ((s->bat[sinfo.bat_idx] & VHDX_BAT_STATE_BIT_MASK) =3D=3D + PAYLOAD_BLOCK_FULLY_PRESENT) { + if (sinfo.file_offset + + sinfo.sectors_avail * BDRV_SECTOR_SIZE > file_size) { + /* block is past the end of file, image has been truncated= . */ + result->corruptions++; + } + } + } + return 0; } =20 --=20 2.17.1