From nobody Mon Feb 9 01:41:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728482529; cv=none; d=zohomail.com; s=zohoarc; b=bn6S9tZkWcduUeyDsHe5aAXQiAm0wtY89+Y7U391cVqOWe1/7slJMzHSDkDYt2jVEWYa3AHmQVSFfMVqJPTN7OvKJVS6Ls8ttI0s6xOQI7n1HS8cUfvv9ngCOQle0GPlcJck8LyMeM9+Lbofe55bjkEf3RBj91SnJvrwk7ldJhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728482529; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=IqL0vy7fOfiEYGjr1ttevxLphpw587ILRMR0bSq83E8=; b=ctMLi7dTDsak/dO+EE5KecJDSdoS7o+SNN7YRcak4s9e26KplDah3N4vr16HQuZHKMujmqF29q+NHm4Kshe3gX8NRXrkgZ7Z9SWszbgG6rmyX++nlQbMfrbZaT+BSUi8EFI6Q++L9mhEz9J1+UD32iYEdJDg5CfhrN0Z2+NYJrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728482529225132.38869396420978; Wed, 9 Oct 2024 07:02:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syXFQ-0006WR-EK; Wed, 09 Oct 2024 10:01:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syXFK-0006Tv-RA; Wed, 09 Oct 2024 10:00:59 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syXFH-0006YF-IP; Wed, 09 Oct 2024 10:00:58 -0400 Received: from [130.117.225.1] (helo=dev007.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1syXBf-00AR1a-2Q; Wed, 09 Oct 2024 16:00:38 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=IqL0vy7fOfiEYGjr1ttevxLphpw587ILRMR0bSq83E8=; b=JWwBoSaQS2uR 8rgL2GFax2/Tq2MxUO+KVgHug+pbC2ZlrLy3a08+x4oapuMUS1eIjkm9NW4rOqWBMqW6UZnVRHvSb l8Os4h8tqe71/wCsN4KxZEglEGHqGT7woKy9/bH94u3a5PD8R5FV1CuFlhYZxAngqZoSFNIifeeAr KW+y3pcpp4W9rJV81/hTTdDitttb+AFRhCgM6CbL9TY1LCKotSlqZsEuEonGQzCqD/3ouUAV72HG3 5pfzWj3qsKfCJl2R7UKCSDGnsfkTgt+3FFgQUC6bNvdel7UQhkzBtPLrfbLSlf/3iQThHaqbq9XcU S2Q6h/QLC8r5D0zQMuWGIw==; To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , Kevin Wolf Subject: [PATCH 1/2] preallocate: do not allow to change BDS permission improperly Date: Wed, 9 Oct 2024 16:58:50 +0300 Message-ID: <20241009140051.771660-2-den@openvz.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241009140051.771660-1-den@openvz.org> References: <20241009140051.771660-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1728482530161116600 Content-Type: text/plain; charset="utf-8" RW permissions could not be lifted from the preallocation filter if truncate operation has not been finished. In the other case this would mean WRITE operation (image truncate) called after the return from inactivate call. This is definitely a contract violation. Signed-off-by: Denis V. Lunev CC: Andrey Drobyshev CC: Vladimir Sementsov-Ogievskiy CC: Kevin Wolf Reviewed-by: Andrey Drobyshev --- block/preallocate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/preallocate.c b/block/preallocate.c index bfb638d8b1..1cf854966c 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -581,6 +581,17 @@ static void preallocate_child_perm(BlockDriverState *b= s, BdrvChild *c, } } =20 +static int preallocate_check_perm(BlockDriverState *bs, uint64_t perm, + uint64_t shared, Error **errp) +{ + BDRVPreallocateState *s =3D bs->opaque; + if (!can_write_resize(perm) && s->data_end !=3D -EINVAL) { + error_setg_errno(errp, EPERM, "Write access is required for trunca= te"); + return -EPERM; + } + return 0; +} + static BlockDriver bdrv_preallocate_filter =3D { .format_name =3D "preallocate", .instance_size =3D sizeof(BDRVPreallocateState), @@ -602,6 +613,7 @@ static BlockDriver bdrv_preallocate_filter =3D { =20 .bdrv_set_perm =3D preallocate_set_perm, .bdrv_child_perm =3D preallocate_child_perm, + .bdrv_check_perm =3D preallocate_check_perm, =20 .is_filter =3D true, }; --=20 2.43.5