From patchwork Mon Apr 24 09:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13221880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 612F7C7618E for ; Mon, 24 Apr 2023 09:22:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqsOP-0006C4-Ti; Mon, 24 Apr 2023 05:21:53 -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 1pqsON-0006BE-RU for qemu-devel@nongnu.org; Mon, 24 Apr 2023 05:21:51 -0400 Received: from mail-db8eur05on2114.outbound.protection.outlook.com ([40.107.20.114] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqsOM-0004XK-9g for qemu-devel@nongnu.org; Mon, 24 Apr 2023 05:21:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JHkROZUqptS8Wvj/CzAgic5jSNb5sNkG8crzA4JPKeiTe5hPsZzXAfqNgOwQqjd/NhvsQv55GgB4g3SeUPDogC2BJnleMn+9hDsZIEbIvnAhqJMFEuo7yeIbVCyVoe08CmfFnyAQZhws+q1Z5Lo+wyzjyuE6VHWYu+LVxhI3CH6oxySAWnB86QDWMxjFYmIHaJSl03FzazM3xCPMexLcir/G/4C0ZOED8n6SCfHW4Tk9SkOEX5BdNS8A5M3azrOmMq/Xrfjk3To2EUJvMbGLutwFQftw3ahNRl5/9n9GmKmnfCrpGvj7CAMK6gExtt1Luex1pDzkq5qyJl33lyXkmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bXOwa/L67joB3+1DEfpVcK72jpfn9Lr1WBBHTA2x4Wc=; b=MnLsaUq/UeoU2xH/jd9WE1fo1CLnaPvo/xA2Nkh2I3mbbAAmfDukNFRrsTzX7s51YA1slnjOtWhwGT5uSc0ViTF2soNvN1l6dF1beq0aKuiqKwF9bRefcw0Gb22qIjjvANsRw93CcPZM5bBEkxnPlv6QhIpWwAozKSHN8cf0G6CuEEc4r+00/+pr07SXammTa+2Oe546bLrqxj4k64ODZ7nwPdSPfLZGox+QkhqK03Hky9NlHBbisGTRWFYt0VziCCVREzawCkfvu8Ss8vm3h7ekGVZHl6hBuCdpQQzVlA0sasIpTZddMesxoFYoBs+nmOGB1x0ccg1DWv+2TEPplw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bXOwa/L67joB3+1DEfpVcK72jpfn9Lr1WBBHTA2x4Wc=; b=v+eLQ1MuY7T7OwU/8rRl5GruWcXc8KzYOo8oNWeRgEZDRYI2ubZOhbeSJ8AsMJRtU8vdlJ50kiSBWTtLlWQmUfkbnXwj2wSYRJmmOgiWx+W8LWTYr7HttpeNeIBXnKck4uvTg8McKCAYO0Hn+hQy9Ffjerx+CmZYd//5HEU2XA8/KwRArfv5mQYv9hH/qW8ImC4WtU6ofH89mk07qijyfnHw/ins7WP5/H23AZyDbARf9DPcMHwIPtR+YtG+ewIUmgkHvCMURexNK07mwr9ksM55vooU4Y6YMTt999TIq26CZr8ZOm3JgKa6ksfD82h9iL5a975F6vrrgOw8sd4TCQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DBAPR08MB5832.eurprd08.prod.outlook.com (2603:10a6:10:1a5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.33; Mon, 24 Apr 2023 09:16:43 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::b630:c4eb:fba3:1158]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::b630:c4eb:fba3:1158%6]) with mapi id 15.20.6319.033; Mon, 24 Apr 2023 09:16:43 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH v11 01/12] parallels: Out of image offset in BAT leads to image inflation Date: Mon, 24 Apr 2023 11:16:15 +0200 Message-Id: <20230424091626.195590-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424091626.195590-1-alexander.ivanov@virtuozzo.com> References: <20230424091626.195590-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1P18901CA0008.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DBAPR08MB5832:EE_ X-MS-Office365-Filtering-Correlation-Id: 002ba3c5-4853-4916-1588-08db44a49cbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t21mQyVUIbsP0zv+U3cwmwxhoY5r7CFyw8F/wQqKG7hQCRC9HyvfYRgjeB9DvQ8kI9LVK1gxt06tlS9zOeUBxvFuI2uyINLnTXhXtnlRYiKEkHsrQW8HkzxTJ/auGTN8FaqmBxYHA0SXrSOzLTo0o9xKK1e2UYkNrf4fSVtQnIDe+uaK9nEqxiyWo4doLS+JrTvkKNuFYdk3XgynL9CuD4b390iPRgP/EvU5WPqVuQlKi/oVTTjIstoGnOP9GjyDiuyPwvkZ45Uoum3Cm65x+ydsk16cJ8Ea4+TwZHdk/ewIoGHrqLnT2AmDVX0PqEUyZDt/3+ib85gq7EMupQajFT5uQi0njw/L/btgFqSlmamiMnqMdBN2G9m15UCsHA8zh7gmtS3rY7TfqocKsq7BQYJicm+2rYTuJZPxUMdBkUuhS3Jh6Ah4QZlPaj/iJhRAPdwTn09GpmrIPdc7YHk0wI2Ey1tXP0IIoOpkeDyTTfH8BFIUNQVItRw+NSpC0rOqPYKz5wUp6ghAAr61T63k7aPsmFliW82uqq9z2By6fTCrIHYneG2nrI0/I1nH+oDodgsT97Grq+NI2YmkKeGbKeA5QVa07S/pPyLkpIQJrJR/u0bIP/y1PowZ/veIWvJ4 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(376002)(346002)(136003)(39840400004)(396003)(366004)(451199021)(5660300002)(44832011)(2616005)(86362001)(83380400001)(186003)(6512007)(6506007)(26005)(1076003)(38100700002)(38350700002)(8936002)(8676002)(478600001)(316002)(6666004)(6486002)(52116002)(41300700001)(36756003)(4326008)(66476007)(66556008)(66946007)(6916009)(2906002); DIR:O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98G3rU4dnAaqRc0xuQJ4rcBQbPhbLrqzK6sd6r+3Ys7X/74v+4u+Dhzco/8koQ/XJAc9l7atZ7ggIwKWwmc0vfyqXq4chOqqjsEyLiKHDj45vYa2kLh2MNAbjN26rJDkpoVddEiDUP42grtC9vRiFws5EI9fdY5ibFbE/Oa0Tgd0FDzhE43Gf8bT/696v2Ox5iBBusFbaQaRMY5ISUFlCrLzwSStxcA5O5aNO3qUkL8t0IgACZc1NY6cniJ8s9nnEkH/qOh35pkL8Mvfp7vRZF5J6sLzWO+Jw+pQUZ8IOlqR0HDaLGNkMVPDvAZ1/g4MPivSuxr5385zr0T5RaSAUE3/581namQYWJ02DRkYht30zYQVA5JNNtxg9SvNQ0w5g7geJzh1YQ0GOE0FmqpkwSVlxjLsXeqgG0ytCQNxoZUXsGWtplnlBjrK+DOPZos8WiMQwlknx/u1bb6DWQa/25/R84eDAMqHhlS4cHSEVEGtMAoQRoYzR6EnhjcF44cjcC013QxFEmuWpVZBy9Ea3t9/DsmeD+iIbXRBKNJFT8kqr2qVmu+ZjLiCeLl66PcGwUJBh/qfs3DB+gvJuqtmEndW5j9ZHG7CrEA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 002ba3c5-4853-4916-1588-08db44a49cbe X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2023 09:16:39.9155 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8npTYyVvsJ2fNJi/UOWw847pDlJNNTirfZuRveEBgwcKuxgAmjPOS62W0uJe/ZSEzAMIG8nywCZ8vcuw2524fIM51DNipMrKS+9KUQR3XAI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5832 Received-SPF: pass client-ip=40.107.20.114; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org data_end field in BDRVParallelsState is set to the biggest offset present in BAT. If this offset is outside of the image, any further write will create the cluster at this offset and/or the image will be truncated to this offset on close. This is definitely not correct. Raise an error in parallels_open() if data_end points outside the image and it is not a check (let the check to repaire the image). Set data_end to the end of the cluster with the last correct offset. Signed-off-by: Alexander Ivanov --- block/parallels.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/parallels.c b/block/parallels.c index 013684801a..7e563062eb 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -733,6 +733,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, BDRVParallelsState *s = bs->opaque; ParallelsHeader ph; int ret, size, i; + int64_t file_nb_sectors; QemuOpts *opts = NULL; Error *local_err = NULL; char *buf; @@ -742,6 +743,11 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, return ret; } + file_nb_sectors = bdrv_nb_sectors(bs->file->bs); + if (file_nb_sectors < 0) { + return -EINVAL; + } + ret = bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0); if (ret < 0) { goto fail; @@ -806,6 +812,17 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, for (i = 0; i < s->bat_size; i++) { int64_t off = bat2sect(s, i); + if (off >= file_nb_sectors) { + if (flags & BDRV_O_CHECK) { + continue; + } + error_setg(errp, "parallels: Offset %" PRIi64 " in BAT[%d] entry " + "is larger than file size (%" PRIi64 ")", + off << BDRV_SECTOR_BITS, i, + file_nb_sectors << BDRV_SECTOR_BITS); + ret = -EINVAL; + goto fail; + } if (off >= s->data_end) { s->data_end = off + s->tracks; }