From nobody Mon Feb 9 16:18:43 2026 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; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1573699856; cv=none; d=zoho.com; s=zohoarc; b=BsFI39esThNw0bVPA+VVaWFrrpRcoFkppBub86jhpqjDq254zXZDUoimf0O7XTYpGji3CRs6LS5UCWaUH7qH5iauX4KNpdiaXuRYbUUEXnp1kSbZ3Ve/pfSyl/Uc/AeH3Nv6NhfvHJEIL0CytQD3FWPs1AdPqatJ7HL4v8kCFjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573699856; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=47xaOjcuo94e/5zHn1u4hTI+rbUhD+M67pRD//YF174=; b=PgSPbaECLHsStmVZlp46WxfP+eA676ykd8erlUR0z2S3h1YPcQqOmJ5iLh8eDJdtSOYI3q370dAtg8GKuSkjJ1gsGeiZwKkkDyEKSXqFJz16ZwKwDVBsdm1e0WgOSEvBpmGTlu53U8AGN0GqBSWRrvRwKQ3Iu9yx5JA/2XT0D54= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573699856104970.1811851868832; Wed, 13 Nov 2019 18:50:56 -0800 (PST) Received: from localhost ([::1]:53028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iV5Dh-0000fJ-VK for importer@patchew.org; Wed, 13 Nov 2019 21:50:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60499) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iV59n-0005JR-KJ for qemu-devel@nongnu.org; Wed, 13 Nov 2019 21:46:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iV59l-00034c-2L for qemu-devel@nongnu.org; Wed, 13 Nov 2019 21:46:51 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:58010 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iV59k-000335-UU for qemu-devel@nongnu.org; Wed, 13 Nov 2019 21:46:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-418-qqT1jtxxOIOskAzBQDAK6Q-1; Wed, 13 Nov 2019 21:46:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCE70DB60; Thu, 14 Nov 2019 02:46:43 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-242.phx2.redhat.com [10.3.116.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56C9181759; Thu, 14 Nov 2019 02:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573699608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=47xaOjcuo94e/5zHn1u4hTI+rbUhD+M67pRD//YF174=; b=CIhN1Hf33arA2Gynx/vML8BENWEjc2nDwh0FFB6j9ORx61WQh1DTABju1g2Qj896kgDCR7 Oyc4VcLj69+U6+fX+n1pnLLtzvvEoFZpbIclzqDlcoFmThDcwh0l7nLAlB2qe3xiwlTHMp 0E4KnX5r86YwD6AmS0CG7/89oE6Qgpc= From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v3 2/4] bitmap: Enforce maximum bitmap name length Date: Wed, 13 Nov 2019 20:46:33 -0600 Message-Id: <20191114024635.11363-3-eblake@redhat.com> In-Reply-To: <20191114024635.11363-1-eblake@redhat.com> References: <20191114024635.11363-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: qqT1jtxxOIOskAzBQDAK6Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Kevin Wolf , vsementsov@virtuozzo.com, qemu-block@nongnu.org, Markus Armbruster , Max Reitz , mlevitsk@redhat.com, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We document that for qcow2 persistent bitmaps, the name cannot exceed 1023 bytes. It is inconsistent if transient bitmaps do not have to abide by the same limit, and it is unlikely that any existing client even cares about using bitmap names this long. It's time to codify that ALL bitmaps managed by qemu (whether persistent in qcow2 or not) have a documented maximum length. Signed-off-by: Eric Blake Reviewed-by: Maxim Levitsky Reviewed-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 2 +- include/block/dirty-bitmap.h | 2 ++ block/dirty-bitmap.c | 12 +++++++++--- block/qcow2-bitmap.c | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index aa97ee264112..0cf68fea1450 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2042,7 +2042,7 @@ # # @node: name of device/node which the bitmap is tracking # -# @name: name of the dirty bitmap +# @name: name of the dirty bitmap (must be less than 1024 bytes) # # @granularity: the bitmap granularity, default is 64k for # block-dirty-bitmap-add diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 958e7474fb51..e2b20ecab9a3 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -14,6 +14,8 @@ typedef enum BitmapCheckFlags { BDRV_BITMAP_INCONSISTENT) #define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT) +#define BDRV_BITMAP_MAX_NAME_SIZE 1023 + BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, uint32_t granularity, const char *name, diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 4bbb251b2c9c..7039e8252009 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -104,9 +104,15 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverS= tate *bs, assert(is_power_of_2(granularity) && granularity >=3D BDRV_SECTOR_SIZE= ); - if (name && bdrv_find_dirty_bitmap(bs, name)) { - error_setg(errp, "Bitmap already exists: %s", name); - return NULL; + if (name) { + if (bdrv_find_dirty_bitmap(bs, name)) { + error_setg(errp, "Bitmap already exists: %s", name); + return NULL; + } + if (strlen(name) > BDRV_BITMAP_MAX_NAME_SIZE) { + error_setg(errp, "Bitmap name too long: %s", name); + return NULL; + } } bitmap_size =3D bdrv_getlength(bs); if (bitmap_size < 0) { diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index ef9ef628a0d0..809bbc5d20c8 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -42,6 +42,8 @@ #define BME_MIN_GRANULARITY_BITS 9 #define BME_MAX_NAME_SIZE 1023 +QEMU_BUILD_BUG_ON(BME_MAX_NAME_SIZE !=3D BDRV_BITMAP_MAX_NAME_SIZE); + #if BME_MAX_TABLE_SIZE * 8ULL > INT_MAX #error In the code bitmap table physical size assumed to fit into int #endif --=20 2.21.0