From nobody Sun Nov 9 23:22:17 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552423363037372.3600144300808; Tue, 12 Mar 2019 13:42:43 -0700 (PDT) Received: from localhost ([127.0.0.1]:33031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3oEQ-0003R7-W0 for importer@patchew.org; Tue, 12 Mar 2019 16:42:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3nxN-0005B3-Gs for qemu-devel@nongnu.org; Tue, 12 Mar 2019 16:25:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3nxM-0002rr-Cc for qemu-devel@nongnu.org; Tue, 12 Mar 2019 16:25:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3nxI-0002oJ-F5 for qemu-devel@nongnu.org; Tue, 12 Mar 2019 16:24:58 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71985F74A1; Tue, 12 Mar 2019 20:24:54 +0000 (UTC) Received: from probe.redhat.com (ovpn-125-62.rdu2.redhat.com [10.10.125.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12DD760BF7; Tue, 12 Mar 2019 20:24:45 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 16:23:35 -0400 Message-Id: <20190312202337.5278-21-jsnow@redhat.com> In-Reply-To: <20190312202337.5278-1-jsnow@redhat.com> References: <20190312202337.5278-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 12 Mar 2019 20:24:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 20/22] block/qcow2-bitmap: Don't check size for IN_USE bitmap 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: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com 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" From: Vladimir Sementsov-Ogievskiy We are going to allow image resize when there are persistent bitmaps. It may lead to appearing of inconsistent bitmaps (IN_USE=3D1) with inconsistent size. But we still want to load them as inconsistent. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20190311185147.52309-3-vsementsov@virtuozzo.com Signed-off-by: John Snow --- block/qcow2-bitmap.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 885f36c2ab..92cef1cfd4 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -462,10 +462,25 @@ static int check_dir_entry(BlockDriverState *bs, Qcow= 2BitmapDirEntry *entry) return len; } =20 - fail =3D (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) || - (len > ((phys_bitmap_bytes * 8) << entry->granularity_bits)); + if (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) { + return -EINVAL; + } =20 - return fail ? -EINVAL : 0; + if (!(entry->flags & BME_FLAG_IN_USE) && + (len > ((phys_bitmap_bytes * 8) << entry->granularity_bits))) + { + /* + * We've loaded a valid bitmap (IN_USE not set) or we are going to + * store a valid bitmap, but the allocated bitmap table size is not + * enough to store this bitmap. + * + * Note, that it's OK to have an invalid bitmap with invalid size = due + * to a bitmap that was not correctly saved after image resize. + */ + return -EINVAL; + } + + return 0; } =20 static inline void bitmap_directory_to_be(uint8_t *dir, size_t size) --=20 2.17.2