From patchwork Thu Jan 6 06:47:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12705154 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 6E3E8C433EF for ; Thu, 6 Jan 2022 06:57:19 +0000 (UTC) Received: from localhost ([::1]:49552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Mi5-0004Wi-Lm for qemu-devel@archiver.kernel.org; Thu, 06 Jan 2022 01:57:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYh-0001HD-1B for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:38 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:22644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYc-0003Tg-H7 for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:33 -0500 Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 205N5d7j019176; Wed, 5 Jan 2022 22:47:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=xTXUa0V5/w7nkUas7PxLZMYxnH++OqMtYi1YlrXD+tU=; b=x9Ly7IkIxhzDpWu1ITZKpBdFab25s8khIvuodSRlBTEc/1RoIfo2crxoQIJyyrlmUWgA w3kGQsKjyIo28HKrxvR5wAKmYFEFv9HhviTGMA0al6h3D5Acf/Z0l4DZwZZ1Kk9USQJe grl32U3WBuguCfCoTJJXr8zpalAtPMgATxKekvNbXlngbkRw0R91SiSWxOPONRGiI7ol U6+MqMHeNm/fYfWpptJzSj+SD0CmKZlg09SyTaxeaEI0LKS9v57XUkQELhEsylVKXTb6 UI0ikfrxcxHLd/aBCzYRFDcS5olS6KHR4Q1chzFVSuVssN7NPavnVVcrRnlcRaTL4lQM uw== Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2046.outbound.protection.outlook.com [104.47.74.46]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ddmq00jfk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jan 2022 22:47:27 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQNtKlE4pc38WG+96z/Rs+0m/B+hDP/jCFh6E4BZ5YaiyYWedPQYGiyQuJNPf4ObVGI/DbTukBDMv4bYeptRsz/q2FyZO1u1UYaB+JAdbubckx/h9BCb3qIpdWwHL3gTELA2Dx6TkEzpD2IYq7LLMIt4yxbtqqSDXaAP7/yusNYoXDuaqlELDO8SFjkFPhJLrDclmRBzZMRk0sQyYyboFukYbkSgbO5VTtYTj2FBqXKq61HQ1nkggMm3xI+9UCL0jVCbwZLICFHcC38kiMtqDKGouJU0XYRrSZGnIiHgE853EMmDZBUxq85ERxKdBJCMzDrvO2glEQlpmWaiyuBN3g== 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=xTXUa0V5/w7nkUas7PxLZMYxnH++OqMtYi1YlrXD+tU=; b=csrFbbLFwIyTv34wAJ5Qqjsw625GixirubneXpPP/4X7NOzxTMIMwRRIRKCsK8Sfe8cUNRXSHJ9sNpt5n8KOZOhFw6FDOZTRHhV2r/deMTuC2Iq/H/8n94WGQUe0ZHEdGGFJX7Tn2lawAamFxzlN7PSLETLBNk6l1dSZbb4INUblXRWxV+63mt+TndZSGFrkiXIeXW0NVSdMUpFd4SRb3vJIK54vsCBMMj9IOU0Zehc1cchWtKuCdFbC+9yCQXX93KiBJ709FDwM8t/7vWIDSLorjA4glMl/7HeDOZYqAY36o6BdM7fIsSdqJ7X1npSM5wo8toVGhg0a33c78eroMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BL3PR02MB7938.namprd02.prod.outlook.com (2603:10b6:208:355::20) by BL0PR02MB6530.namprd02.prod.outlook.com (2603:10b6:208:1c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.7; Thu, 6 Jan 2022 06:47:26 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da%6]) with mapi id 15.20.4867.009; Thu, 6 Jan 2022 06:47:26 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v2 1/5] libvhost-user: Add vu_rem_mem_reg input validation Thread-Topic: [PATCH v2 1/5] libvhost-user: Add vu_rem_mem_reg input validation Thread-Index: AQHYAslEhQY8WRvwAEOt3/M7Uq9W0A== Date: Thu, 6 Jan 2022 06:47:26 +0000 Message-ID: <20220106064717.7477-2-raphael.norwitz@nutanix.com> References: <20220106064717.7477-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220106064717.7477-1-raphael.norwitz@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c7b8c46a-801f-417f-cf26-08d9d0e066cb x-ms-traffictypediagnostic: BL0PR02MB6530:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:346; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HSsmclzK6YUhI2bVLfi0HerXqa1Ogq3yUNSLS+K56PhELXy/5mIK64QJEqwC2E2zvNHG1cR4DM/D+A44Qxd9FGE/+rx7AsUCP/AjjrW2dUW4+tJsBrL616XxTd+3EWK82I522hvApu5WXYpLt3oO/HAIcIewl7VoKCDmOnKKLeT/sjHzM9lCGLvEC09QjSsOVtbL/aS684FVvmH0+ozggyrb9WekcA3CN7E8Y+mRW3ifDXud5tD8hhTsNtDbzM1jDu8+v0tpCkpkK1f9HU8ewVFQiVUPi4BNO5bWQKh99KizOzrrZSNEnrItSDp/WHizQNTbdbIWRjPkYy3BFBHTFVwUs6alydYSP+rGcWnLqfS0KdkpEHJxSqJ2FHk+gMwUwvTQDOJhamUGBsLlehhFIOFkL0DMHA6aEdYtjHwTNNfEVe1ZXSaFyXP/X2b0kSvbxQ7uZfqylWN6k57zUBahvVp0Qcznj5NujR7Mdu663X+NDVG35S9Vk55d/JZm2r1yOwI4Ugt8Swsckc5ktyU4Ud+N0JeHiMsqlB6lyOB3rVroLC3qyFauP+gwHX0sQASpN5cmQl4BR9c1p4riZriPXDQSu9uv6dBDZAvZv7NkYe3Pt3Weg7AYTijtW/YF0a3g1kyXwZ2KfC2mfW/AeVnKF/dMuRf5nfzqYVHSbuberASUNibZO8il9uTuY0Rg0H0YlCSHIqPaNJ9SRk8fIKNJ/Q== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL3PR02MB7938.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6506007)(508600001)(66446008)(4326008)(76116006)(186003)(2906002)(316002)(4744005)(122000001)(6512007)(66476007)(71200400001)(66556008)(66946007)(5660300002)(91956017)(64756008)(54906003)(6486002)(38070700005)(110136005)(44832011)(36756003)(1076003)(2616005)(38100700002)(86362001)(107886003)(8676002)(26005)(8936002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?JN26IwEAQkPFkN4RqXfG8UK?= =?iso-8859-1?q?xqP8xhAx90Np2rtec4tLK89xMIVqVc+HPUyCTh/yj/PGV9blF8oOR85DB5q+?= =?iso-8859-1?q?KII/uVRKOz9iZaToGtgBKGSAH36itK9mu4a46TSlq6XAJjEetU0cwu5HhkUp?= =?iso-8859-1?q?gM3LgQT2eMtDJpbWrfxakW35VkexvFP2tCPk6TQh9LU3CMSQzaB8WGerdxHU?= =?iso-8859-1?q?4zYd8XKPtte1qnnAvd4lBXJTKA4eOM9WlM9TX8oE2IJjQOUHsGL7wWOUJf5Q?= =?iso-8859-1?q?ct7dgf3yzYpjGsE9SSMKdrk/aaEQu0MeRetlEVS8UzrPH2rbar/s/KarZjJK?= =?iso-8859-1?q?vwzwuKFtYKHZiGUHUpfrE+1Tap3/TFi0PR4cCBmS8MdThL9EswK8/sglQhgY?= =?iso-8859-1?q?nm4a1X/ptKo44hBkhuMiLgxRhgE8dv2ddoWPOlFX/6JiGjZeyRKcrQ+JsWrG?= =?iso-8859-1?q?Ecstx0YaOOvuYS3eAiEYDkdizlZH5S9MXrMGDnuK3jK5CSVdN7n0fT2qIb/9?= =?iso-8859-1?q?h8w7qBeUktykgOqOK8GT4b7PRDQ9DHKAlN8E2Vskz1f+dz9K0yhvHBnsCvh2?= =?iso-8859-1?q?IRmnzZKHCeWEcxHO+mxIAmguJ01eNvC0uIFqsVabJz4MY7Oyym+1sZvmNvKU?= =?iso-8859-1?q?8gc70Aol8KisFdQfMR+Aqh2hjqn4loKF62Xlw9ZzbDiaMdjjKDKzOOVAGbmy?= =?iso-8859-1?q?FH2wWO5x9wVxb1XF+VpBRI83rR8Rp7bpTahfI/V/Q2runKWAz6FqVecMzkOF?= =?iso-8859-1?q?5x3MywVnyytgltPGDd1K7GhyVYKnzweGy9qZA6Whv/EaV8I4C026HmYGVg/z?= =?iso-8859-1?q?YFngcMbORc8npnv306echny3R3Ns1yrthe/ZxyJDRcYdOQd4pSEJuo5wfhtR?= =?iso-8859-1?q?hFcL/7Zv0vgAe+5J0m17bV+s5nJu4k8Kw8HbpCkIWvkFJ54BblBIwHe5KK62?= =?iso-8859-1?q?fSp4mmZKN+Q/FlxII8LrLRLKV+FEezXuPC+OsEI/445B4Ftj4F3UWNYdTgq4?= =?iso-8859-1?q?W3Ow8IR6DeC9H+c8eERmWzR3JHifs6peQkQAy655cjglADLqvDE9bgAcqcTK?= =?iso-8859-1?q?0jzUO0OwF+Pl2e9H5zyX1i7hR84srI/VTfUe7f3nWC5fbXh8NcGQWMt0o737?= =?iso-8859-1?q?HOBsVRM/Ldi2tCtPB1bqnp4+eWOIRxXsaQiETd+kcNEI4dCVorDwJlW+fb9q?= =?iso-8859-1?q?hsmHLQaqeguuAq5TukPrluDZ2AHQ110BVVBY7Ei94PRAd2NyUKyk0pIOc/mp?= =?iso-8859-1?q?nLNHHxJZAK04sEcm2zEjypLVD7lAAsMJ4rpRb0mk2tYhmW90+U+2pvSjJ518?= =?iso-8859-1?q?c3Vke/u5w2d+TMmjuaLqdytXhHJKj5OrsJo71z/yo0i2hNwpIgEPM3RdEhx0?= =?iso-8859-1?q?MlLHASf/MnTBk7Fu1J/j39aeOi13lzXpOO9gl7t3l5Prwyucm0s8HgcnB0tm?= =?iso-8859-1?q?rKz3tss3gBk8JldIIqVKtubovyjR/W2QF0g4RleLAtW5iLCyWB5daTITPoNk?= =?iso-8859-1?q?68M7zRpXhC5fbf0kD2ULc9y2zCpQzKxwkMlAEgYz6dqPhW0djDrrVlk+OHCk?= =?iso-8859-1?q?ISmqmRgHi8n5ga9xoIxWM2e7BlNdOA7mewaDQlxE5KCCvV9JV5y7U3OaKbhJ?= =?iso-8859-1?q?cTn2QPWBAHEMaZNoz6zwT2IZh15F/Xn7sb2KH1dKQQQ0P8qrlI309LtvXzuF?= =?iso-8859-1?q?/VVnwnwSVy/YsNkqJKwMkIoQo2px2+YXGvqRscUrHkNT2EV1L+0peYtKLaZW?= =?iso-8859-1?q?rpFQ=3D?= MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL3PR02MB7938.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7b8c46a-801f-417f-cf26-08d9d0e066cb X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2022 06:47:26.5051 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: T1zau8uPcYTkQa18MJUrfbSUJ9IAT3e4qHfxv9aHCp9KwZznGWZp5a3prkWFx9LmFjzVm38PtGOSNm1qYZRwDGEFCUu9FzNf4GtFEjuRlSQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB6530 X-Proofpoint-GUID: z-5gjyDMUx7eHETzrRY-M0IsQ1EYsqss X-Proofpoint-ORIG-GUID: z-5gjyDMUx7eHETzrRY-M0IsQ1EYsqss X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-06_02,2022-01-04_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=raphael.norwitz@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.372, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: "raphael.s.norwitz@gmail.com" , "qemu-devel@nongnu.org" , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Raphael Norwitz Reviewed-by: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 787f4d2d4f..a6dadeb637 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -801,6 +801,12 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VuDevRegion shadow_regions[VHOST_USER_MAX_RAM_SLOTS] = {}; VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m; + if (vmsg->fd_num != 1 || + vmsg->size != sizeof(vmsg->payload.memreg)) { + vu_panic(dev, "VHOST_USER_REM_MEM_REG received multiple regions"); + return false; + } + DPRINT("Removing region:\n"); DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", msg_region->guest_phys_addr); From patchwork Thu Jan 6 06:47:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12705155 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 2A816C433F5 for ; Thu, 6 Jan 2022 06:57:24 +0000 (UTC) Received: from localhost ([::1]:49606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5MiB-0004Yn-3C for qemu-devel@archiver.kernel.org; Thu, 06 Jan 2022 01:57:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYn-0001HW-BR for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:41 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:47998) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYi-0003Ul-0V for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:37 -0500 Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 205N5oQF020173; Wed, 5 Jan 2022 22:47:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=Of0L9UWpNJycxFbG078adlk+uLZxh/IDEXkvRnBStbI=; b=T+um8xfG1q3IZKW3Y3adJLkWVSiWJ9hFMXMo4iTxxBf03zNSEXS0iIk42MzsoLpmrDyz F+s0zRDROUM7xqEIOuBpcdRQrOtlISzKQFNF29bJTYPkdd8bPtr+hLOdk6rYxFrWgQtc GuIpI4hcKT+ndXpAVuMFYTBoaMj9bKu4suG5QbAanEBdkn52vpk0nvI25DLe7NqiEzsU if4YGM+WqiLiHNY5A/ZrD6NNhMAzLZEhVmym/+pov3WlZ2oTRTNLA+ycbA3bZZssK+Em dRgKJzdt7N6DnIQZP3fQ8P5o3RxqgSmbr8GXHnYWkqMlkr+Y4g2UOIzTB9ZzKf6qW4sM KQ== Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2049.outbound.protection.outlook.com [104.47.74.49]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ddmpyrjmj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jan 2022 22:47:33 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FcS7n1PFsiGodrwxEFCMHsCCwWx2izF1xAq+WOpjDcq2oZlTidSgcu+uXVcdomAj1ZZMSlwhlxX62FwChI706wjypWo5Z3g9h9BzY+YZlZpCIK6If8W2hqm+Z5JJz7A8SyvUKjZJuGRHmsI1KGNCqerONTL3cTCyZoPrOV8NBKfzVvQ7x4Y+GrET8A9JxaZr+HxYuBhuKZ8Kh1TCQgl1UJibeLf530X/4FpNZ19GqR4l5Oqq/SMWkqAU9A03Aj1+iVVH67FhrSRslpRsi/N7wou/Wi/0hykriViHu3jNrog4fo2w5ycw44xJEt+uKD1c7+GCpZJYg+xjl4WRusIsow== 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=Of0L9UWpNJycxFbG078adlk+uLZxh/IDEXkvRnBStbI=; b=GtwfNpbO2kPPd2ficnJRU/XUnJaKtGr2MZDhrCpj6i/vHzSHgNA4ejLmb30u+jFQOXgCvtCWRLjN7wU3rMiBiUwI6xzMUuqwSjioLEWc3A4F6eATW7KitkhJpbegJEFZbZc1YruhSIpTGOjRG9+KRIZZ7NJwZyfiJTlergLOlFD39DiDy+7yxgTB7tSWE7YitkpkIS/ypgLMfAtZ6oJRmPtxOEKUCkWaTPsmR5c6ndkPn1euOanvAOcICE65lQ9p0BjMXRw6NFXaiatathG0UqPj4nM3g3OW/AvFvXv0QyzrjC+m56KS9qN5OHIaH4cix9V8pT26uIi5lg1TiZFZjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BL3PR02MB7938.namprd02.prod.outlook.com (2603:10b6:208:355::20) by BL0PR02MB6530.namprd02.prod.outlook.com (2603:10b6:208:1c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.7; Thu, 6 Jan 2022 06:47:32 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da%6]) with mapi id 15.20.4867.009; Thu, 6 Jan 2022 06:47:32 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v2 2/5] libvhost-user: Add vu_add_mem_reg input validation Thread-Topic: [PATCH v2 2/5] libvhost-user: Add vu_add_mem_reg input validation Thread-Index: AQHYAslH9uxqbChK6kiVnTDL8kYa4A== Date: Thu, 6 Jan 2022 06:47:32 +0000 Message-ID: <20220106064717.7477-3-raphael.norwitz@nutanix.com> References: <20220106064717.7477-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220106064717.7477-1-raphael.norwitz@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 520d4760-94ef-43d6-71ac-08d9d0e06a26 x-ms-traffictypediagnostic: BL0PR02MB6530:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:2803; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HdZdbeF6aAv51vgd79dk9fQeb8sWQfUZ2t4jbskdCFcBbthrL45/AanFLxqFrStYE3krTkCcuxRuCC3RmODoKF/suao05gu/r3aC6sAx2WEJ+7qhvF3UFAI0EIiEuZmVBUzVFlgvzZX8xJ6hN34JoPPKERNQiR8Yw78om7xMcgkISZyJPB/4bFqMeNgbh6PEhorHfa6mpccziVudXXZLzCBZmrnTZkbo//djhTkuDlJypfMScnJzxa7uUg2j0yRqUmzlfq2mBnECySy2cBPKm6vYiUFlvcAOsLdGK5m1Z3QtpWBfLrr67YkCEeKWBO50HqipbIg5qJaqvCKDFxlUpLEP1dcrj8mhN81DbqBiWkGale19JHp8zM/o2mvMpuqOBatLLl6lj6XpJCs7c1+mmrCtPrANAWzSrZCLKqihhh4M1JbnMzfcmI8A/j3KzOYkolc/bx0qxHp8NjsSAobLaQLff5I9UEvBLDDo/5GG/k3rKPyLI/B0vFgXje9kceL4ZbphuoHM3P1sFKCBHR4jPLgC0uqYEbUSDeX8FAHlgnf5ft0pZtRM/8kz+c3BUAF6GlIp0cyWFxbsKnC3P2cqx0hrbMZvYnbTz2n/xZlirpiZXdTfngVWLcLzhNU8ofGv5hvQAUqf9fHBTXC3ahxraorLtorXK0/X1oVhPA2cSy0zTjLgOQ7Cd6LKt+He8Kh9NXNuvWmIr8PQmd5ZXDJcog== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL3PR02MB7938.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6506007)(508600001)(66446008)(4326008)(76116006)(186003)(2906002)(316002)(4744005)(122000001)(6512007)(66476007)(71200400001)(66556008)(66946007)(5660300002)(91956017)(64756008)(54906003)(6486002)(38070700005)(110136005)(44832011)(36756003)(1076003)(2616005)(38100700002)(86362001)(107886003)(8676002)(26005)(8936002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?TAznErh1kOCifxRWReSTMBJ?= =?iso-8859-1?q?jec0q7R4gx6mnfCq1bSWH9tETpNogzDhzuB2V/oWObCaMtf1ZpuzD2SLwXXm?= =?iso-8859-1?q?vYYTppoUh12CnqZ75J7uRM4ng4D4M+sxt3bTOD/as9PF8Ankg/yCN296Kacv?= =?iso-8859-1?q?bThbc6DujKFBX3UyR/bJXPeCk+Acdyro7DntDbvmS6EcR8Sc9hWZgBZhMHPz?= =?iso-8859-1?q?5jsJ7WQ0EOmch6zgyILo1ptukt169emaYPHySqDdOduEI8T6aKX+K66qoeYY?= =?iso-8859-1?q?Ui1FMAndZhmKDdKjKbpwo8pPkKLttcxOf8D9UzhCnTAkqJz3VmXakw40S0ZN?= =?iso-8859-1?q?1myErDlVC6ONX6RC+jWawnBaW+qBV5iF273Cw6mpnOlIPgS2kOWDD2In5TSq?= =?iso-8859-1?q?QTC/RsvA7UW6kDaJfGRscgzuyItAq5aoMdm7RIPsToYJ9cXAOyedTIngbhMi?= =?iso-8859-1?q?7ccDLbp1Hfr5l0IkjsbGlF38dTmZOdedUgGEiI9D0oSb3+rM8dv6HTTxgIYz?= =?iso-8859-1?q?u2hHNQbORk3TUbqHxmBejvPARjQTxHL+5oeMrg7IaRnWaN/rdVMY4n6+ZgJS?= =?iso-8859-1?q?Jc+FqswcPpHHjVQ3u6nzOWcqs+YlG0OaG88bYomqShiDmXrepq2LkszXPA12?= =?iso-8859-1?q?VkxNGGHX0lk3A94sEjHDwnqzex1n2eXRyyJ32szNOCe3EsGgn9fcfO0j8Grb?= =?iso-8859-1?q?92PikvcWP6Rktx3R9hT+Na+nQxLBirt2/WJx3gC5ETqdQAbC/+I7rer8p08Y?= =?iso-8859-1?q?cFN/YGl7VAJa2NzLr2Fb0JBeNb6yPKFX7xqi5OF68tdSLo8zfVpI816GI4wa?= =?iso-8859-1?q?xd+tTPTFpl17Zg7GuN/GLeiB72M2y1EaMhAVHsEonwBNki89HYg3djee9ovC?= =?iso-8859-1?q?8Vxf9Dj1FCrznrIJzEYMjY4/iUm57Fkv1apPWnjgu79GMUugaedAE1jDkzaK?= =?iso-8859-1?q?wILBZxktTRi07TT/OW+PN8xFX+vWHkqynt1IMYU6Ivspd6OKsRT7NLqXosvx?= =?iso-8859-1?q?sT4CHn/1qV0coahkIfErcMkOYz5DH7fDF7lOVZ+bMRZLLwLKJfCF4IGNogw3?= =?iso-8859-1?q?SX53VAqCj9N5fIwMbDsf7axdkJcPwcpAUW+1ghKdqOBHXwhL/aB9JW6mAiCw?= =?iso-8859-1?q?YEE1NJKn8uUpcPdjkLjSqZYdlhobqb2fTNOCKJDZ4hh9U8OneUhPp303Rt9z?= =?iso-8859-1?q?ZGCI9yFuWrzkWj5r40VTso2RbeR0MgdgpWtyB+1PT3iHGdNgEtaJee1tX3WS?= =?iso-8859-1?q?lqtjVX8nBWe9clBPUYzc/9eSTmCDPXSnLNXOq9bie2TTJz94uj4JVqws8yw8?= =?iso-8859-1?q?7KFu45w401fk8xO1Mtm0qU+kPgdhJbJuhUIlUf7qSAZMUFn5cM9ubiv9n3t0?= =?iso-8859-1?q?5af6XR8YxT/jS3FLKNoNiBbHfei5apN4Ub8HrKeU4DSNCMonsh7Yy/dwfqnB?= =?iso-8859-1?q?IuS1qYPWsRKZAbCdiM4zxeYq4E1lZAmxMoslEygx+549pyBGSkqnS/VdAm/5?= =?iso-8859-1?q?4DliGuVa1VMLbuRHyVZuG9p19wA/5eSArp4mFBTAwNUZxUJnCaJsMWvqSIKW?= =?iso-8859-1?q?oYoxOufHrsieVQVVssIIevP2VNz17ukJPSyU9L+c/3ZvAFLBCjeaJFXQKCh0?= =?iso-8859-1?q?ZVi+5ShJI+4kFGiRLmBlmPFZoEgAo8poLKH8hGuAMRoF1JQSFuPvU8oqpwy0?= =?iso-8859-1?q?UoI8Vt9Ae8FjQcViks13DaG/QrxHYirLyfBRayvHrvkcSczUbS52q0xVncgQ?= =?iso-8859-1?q?P0ZI=3D?= MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL3PR02MB7938.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 520d4760-94ef-43d6-71ac-08d9d0e06a26 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2022 06:47:32.1479 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: lki6QXtIaDJv350jqlLqRu2n0qoAVgXqjcKCB5PJ7rBLcIGs01jlPpP6obJ1Jmrt63FE+TfHjS4ISaO5agq8jsiZbckNCEmDDxYU50TtQ0s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB6530 X-Proofpoint-ORIG-GUID: eK3POZApj5LLiZV34XxQDx3Y8eHXQwTb X-Proofpoint-GUID: eK3POZApj5LLiZV34XxQDx3Y8eHXQwTb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-06_02,2022-01-04_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=raphael.norwitz@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.372, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: "raphael.s.norwitz@gmail.com" , "qemu-devel@nongnu.org" , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Raphael Norwitz Reviewed-by: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a6dadeb637..d61285e991 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -690,6 +690,12 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VuDevRegion *dev_region = &dev->regions[dev->nregions]; void *mmap_addr; + if (vmsg->fd_num != 1 || + vmsg->size != sizeof(vmsg->payload.memreg)) { + vu_panic(dev, "VHOST_USER_REM_MEM_REG received multiple regions"); + return false; + } + /* * If we are in postcopy mode and we receive a u64 payload with a 0 value * we know all the postcopy client bases have been received, and we From patchwork Thu Jan 6 06:47:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12705171 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 E38CBC433EF for ; Thu, 6 Jan 2022 07:05:04 +0000 (UTC) Received: from localhost ([::1]:59218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Mpa-0002iY-Na for qemu-devel@archiver.kernel.org; Thu, 06 Jan 2022 02:05:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYs-0001IW-HJ for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:47 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:19576) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYk-0003Us-Gd for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:42 -0500 Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 205N628Z016432; Wed, 5 Jan 2022 22:47:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=zyXPgW+0qzttbT91NqCoOCa9/f2y2Xi7NjmTjYqCXGQ=; b=TQw1AMdAcUHSY4l5kydAh/T01Pq7ZU8QCTRvixd8VBiScipkYxKQpTd0yJEI6lCzlbRj oBe5RgJh37hGBIwxevLptbFZxpBZ+xYLngIoVISGbxk6KfHfUuz6JG6hLSiGctZIrU2g NEi/5bOQYnbaIpgD+I8q90STDGma/QNpGu+W4hfydtVwBSm8fzCSAvZGNhMOsMs3fHEy 0aYQYYmXYwclJUGW13Vkk/AZtL+vnT9xiBRIWwL3aHiIRgn5w9hCu8yin21ow+gsDUYJ hZbjtBP5R1AzWtTIVcL40xwVpuPOo0Pme5qvhRUtaWXR4NeR/9KoNxklwWa2seJC7QTd Zw== Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2047.outbound.protection.outlook.com [104.47.74.47]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ddmq0rjs8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jan 2022 22:47:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G7PuFfnNNvr4WWhKovBmL28tj289Jg2AM5hcgfiyQOvXjrvZI7GP/ok2WI3NL8Wopy57syNqpFwIe/5/buij0Q5zZgXAGEO7WPh2Zd8MUBbTT+cFnN4RxsaDkZAYmm1Ja+f9dSwJXnj7Dw5x3CObpLk5hhNM75Tbr6s9lqtolE+agB7v2WReRvXiabBVaVadOaK3s6i+Y5nLShIEdMaD0JyRC/nAHtjTvqPDviSh3S52PKadz5Kanv/OmrsOU49NteeAQpG87xdb8aWGXJDdF+TPm3DfZLjmNGXBdSnJ4zLsA/3snhvtrONe6b9m3Xbg61G+seJb17od0wzqEvo8/Q== 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=zyXPgW+0qzttbT91NqCoOCa9/f2y2Xi7NjmTjYqCXGQ=; b=lTRYYqAgMsZ+hvqdNKvyiL1JJiNGEM59JUb5qEgyr3I8W+72vj1zpG6sPafGpv4EcZY0EAKziTJ77EdpauuQ7csbnBEMJ2k4wJfZM18W3RkGWBIfjaUQUkrniyXyyNu7xK/xF3xewdPcdb3VerT3P+/+xgItnNHcLGEEqf3hKzMepVuWb92JEpnyX1jvqjY5rH09b93ArBJ0x2CtkSzPx4XpCQZa+L3ibDWPariTaqBCCR2aAE2hPhaF2vbkSwe+GYaKGuaQZ6wQXvd0K3z+NQ2gaPVf9Y2J1wzOBRBOAewKGToSicJVupN8ZnFUrdl5hA92JE5Td5YykrW9LDqy+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BL3PR02MB7938.namprd02.prod.outlook.com (2603:10b6:208:355::20) by BL0PR02MB6530.namprd02.prod.outlook.com (2603:10b6:208:1c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.7; Thu, 6 Jan 2022 06:47:33 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da%6]) with mapi id 15.20.4867.009; Thu, 6 Jan 2022 06:47:33 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v2 3/5] libvhost-user: Simplify VHOST_USER_REM_MEM_REG Thread-Topic: [PATCH v2 3/5] libvhost-user: Simplify VHOST_USER_REM_MEM_REG Thread-Index: AQHYAslImWaDAIu9xEeLpLVwuoQw7Q== Date: Thu, 6 Jan 2022 06:47:33 +0000 Message-ID: <20220106064717.7477-4-raphael.norwitz@nutanix.com> References: <20220106064717.7477-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220106064717.7477-1-raphael.norwitz@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f430a195-4789-4361-2377-08d9d0e06b21 x-ms-traffictypediagnostic: BL0PR02MB6530:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GkCzXC2BShy331s79JCKXFkD0WZr+MvGQ4e2J0rft/sqqsG1RA5WNpYQF/MGhMDlpYnCxCvs1xGxRmoesmzDXJIzNbpfYVTJ9eIYuhD8+qTG/sljlyJJ4DYnUt+MPzsnv5bCQtpP6CYc96n19ym16Han48hobnCXqNOdscCvT7bNDi/WFLp/4I7ZxjcKRX2/K0VZB2cYZ7+6VTZcccNCp1OIZFWPEgB/5p2K4hIqhYQ+m2mILrSR1K+1C6d/ggIJYWZ88Jq1401LqtjzqA10p3zKfovzckfZl49ATO8rI7ibtQbrL53tbaOnmP9xqoEnq/KJUO93gA9bIOyh5D51g0pLlFuxpatQuP7o0zSITrk5RuJCDy9LGTZ19N3K21KFycqCpGeHWdcHeKWN7PqrJR3tkATKpKAEqfbSF3EBHAWkTJGz67iR/CHaEKQbzdH2/TBFQT040tliQV2f8QRFm/pwGS0UMoF1MoJ8X4CLCDLXkw14fh6qE+6HbtVhaYMo/B0nLHlzcI+U5z6+ftoDpY+DcMqy0RYkgZCfGbhr+xBzr1QcVmVbmlYDQa28PxXP1ojpur0Ua/Q4Xok1c1DlmeXyy/hBTLmXJcgCO5sHWr4dt+xFPQcXSROwLswXHyB8xAX7MqrpSmO+f/sQaJptH7V7V4+YzBaa3wozcQRUFwPHADhTY+L6yfcGwhFIVluWTyo7ipPMNUnRn6jp98YS9Q== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL3PR02MB7938.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6506007)(508600001)(66446008)(4326008)(76116006)(186003)(2906002)(316002)(122000001)(6512007)(66476007)(71200400001)(66556008)(66946007)(5660300002)(91956017)(64756008)(54906003)(6486002)(38070700005)(110136005)(44832011)(36756003)(83380400001)(1076003)(2616005)(38100700002)(86362001)(107886003)(8676002)(26005)(8936002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?E5oWJux5Jh9yGddWbD7Jm6J?= =?iso-8859-1?q?5wNA28Vzu52v4LNyiNgWs4bwH1H9sp4k8GAIOqyZTMFZyJpWJUmQMYK9x5xv?= =?iso-8859-1?q?TDDg+izvXfZQNzfJl24SEJ1v5lDbC8xhsRy+sOFw0F8e81oiz49zDmAmgTiO?= =?iso-8859-1?q?60M7ZGYw+TSNKJz9otkn+5BfuNDsFUMI47AgphtEuNGANPsborV7r9SftNSv?= =?iso-8859-1?q?G1qCsnPIxLD22aZOmSKBf8cT083rXQ6LwHSK0CqylGNPMnP9+A812uvqUotW?= =?iso-8859-1?q?bS/dnIUNm/BBuVGoJisSt/B/nXTx/TgA7Az9HcftpjSK4hLMFT5aqZrvm+Uh?= =?iso-8859-1?q?ET/yOpaY0vjC0jbCxGvYDtx/USUngn0Kry+fshIZ6gI4/5G6eRmxBSFyWGvk?= =?iso-8859-1?q?estcsvf+EaCdikj+x46jRV14GkldvN9u2EMAJ1bdVMQC8oIpNms101zSbRrw?= =?iso-8859-1?q?LQsg++8o7bLaATTzUY2oTTs75+jZp33lT9/THG+WFQDinAcMVv0RFyzFLY3d?= =?iso-8859-1?q?1FeX7npd5sGLHGLUZtgzGQRA8PuLnv1uo6QHNHWG/YarQGsbtLJfMPwJ0PIS?= =?iso-8859-1?q?FFSzX9TxaACNAcs3dIJSAo5CcbooJpsMSywvdmTjnd6XRcBoPiXASy522kQx?= =?iso-8859-1?q?xsZ/YbmLoY6MTb/ZAERWOlki3brLZrFmbjB/LJY9TLm6a3blSU6vlSWpy/j9?= =?iso-8859-1?q?PYLIb0IvwnXmjcDSJ7Q+v/o9MoQi7tY2ZeKev9rxrR2R1bjraBmKYDzc2yVl?= =?iso-8859-1?q?f/+MLmLrWdXhKBiLcUaOQ+sz4mCyvYJ8L2o3awuFAPdmpqcAH94AhW6veTW4?= =?iso-8859-1?q?nIgeEW8KFWleIjhaOwXYi0c5j6eUY7MG1mLlrQkY0h9IA5Q8qHuBihYXPGmG?= =?iso-8859-1?q?d+9K4Uz53T67vYTs2wK9aGdtxdgGSPlJVPwbDbAhEtGF+4TVwil5qLPxmSql?= =?iso-8859-1?q?m1o4lrtXk/jVeDPysxa9EhfwhAy93XTRk/P9aHyEBoVxApGQ+qu09DAJV+Q2?= =?iso-8859-1?q?2Lza3GqrBW0JP1bGqqVH7Az5cJ+pW6YMmWamURQGSp8hx1UnjS4E928hS6z+?= =?iso-8859-1?q?IGxPpGJjzLYv2kzjp5t9JtVN74Pt4mJ1XxL6kRUZfxTrUPv7kD2uyifFpV3Z?= =?iso-8859-1?q?KK02jCEi7uVg9TMzz0LxvabZc8tt0uMs16w01BaamFd+xvhbd8zkT0tSfDUO?= =?iso-8859-1?q?CSu86PYA9dW0AblHcHIUYX2LcBxUtl4S6m4xO4OWVo3vlrDZx0wMwYg0N/X+?= =?iso-8859-1?q?vZhdU35SmtN8t43/bcdunYwz4i1IPsDH592OfV4Ao2ydKwg3Il7R6ThfRxu4?= =?iso-8859-1?q?GLlVuu1PIX6W8MguUXcyxbck4DG0zdZ314zpBsisNq841USvkAZ3wRdVbGfx?= =?iso-8859-1?q?6ndzonwD/HQOz5Q3GoFLaPrUco5/1Vxs6D4E/5vjau6cRBvTb/8sYude7XKQ?= =?iso-8859-1?q?o448L1gDWr85UEx2H0/lDWXxDUWbfGqWiGUcYGZirwuJOgoqWKj+/mRBKSyd?= =?iso-8859-1?q?ruAseqL9/WoMEPWOK7c8a6gABmb8hQMa5c0x+tr2K6o8oAimjUrgBL0+gQ9T?= =?iso-8859-1?q?tHpBsMaSKFj35zZwH0Xj2vQ9yw01xwIyxZMAkujiXmj6sVziUjKcTRJ9O7J8?= =?iso-8859-1?q?k5/B7xLMirkb8KwBXpVyEkGgkFz9Do37yIJwCwLuuLrzVsHGsr1gqxOTOw5h?= =?iso-8859-1?q?dZUOcsjsaSCBI99N7EkpOT7ER6VXhbLJLje+U+bOf9Jhp1mgcHqYBIzGotMq?= =?iso-8859-1?q?EJpc=3D?= MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL3PR02MB7938.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f430a195-4789-4361-2377-08d9d0e06b21 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2022 06:47:33.7596 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: cHEKnzoFvwD09XeVC0oUUk3phd++SAfvroTvXYeUTrPSWdqUuYCxth6/LnRtw6yVQB1SEW4xeeeDQ7sxiStWvsDhKygS1mQl1NY98rhuBwo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB6530 X-Proofpoint-GUID: h5e3Lsygg2uWh2Kf1J5bc_KliICcavY1 X-Proofpoint-ORIG-GUID: h5e3Lsygg2uWh2Kf1J5bc_KliICcavY1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-06_02,2022-01-04_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=raphael.norwitz@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.372, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: "raphael.s.norwitz@gmail.com" , "qemu-devel@nongnu.org" , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's avoid having to manually copy all elements. Copy only the ones necessary to close the hole and perform the operation in-place without a second array. Signed-off-by: David Hildenbrand Signed-off-by: Raphael Norwitz Reviewed-by: Stefan Hajnoczi --- subprojects/libvhost-user/libvhost-user.c | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index d61285e991..77ddc96ddf 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -802,10 +802,8 @@ static inline bool reg_equal(VuDevRegion *vudev_reg, static bool vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { - int i, j; - bool found = false; - VuDevRegion shadow_regions[VHOST_USER_MAX_RAM_SLOTS] = {}; VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m; + int i; if (vmsg->fd_num != 1 || vmsg->size != sizeof(vmsg->payload.memreg)) { @@ -823,28 +821,28 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { DPRINT(" mmap_offset 0x%016"PRIx64"\n", msg_region->mmap_offset); - for (i = 0, j = 0; i < dev->nregions; i++) { - if (!reg_equal(&dev->regions[i], msg_region)) { - shadow_regions[j].gpa = dev->regions[i].gpa; - shadow_regions[j].size = dev->regions[i].size; - shadow_regions[j].qva = dev->regions[i].qva; - shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; - shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; - j++; - } else { - found = true; + for (i = 0; i < dev->nregions; i++) { + if (reg_equal(&dev->regions[i], msg_region)) { VuDevRegion *r = &dev->regions[i]; void *m = (void *) (uintptr_t) r->mmap_addr; if (m) { munmap(m, r->size + r->mmap_offset); } + + break; } } - if (found) { - memcpy(dev->regions, shadow_regions, - sizeof(VuDevRegion) * VHOST_USER_MAX_RAM_SLOTS); + if (i < dev->nregions) { + /* + * Shift all affected entries by 1 to close the hole at index i and + * zero out the last entry. + */ + memmove(dev->regions + i, dev->regions + i + 1, + sizeof(VuDevRegion) * (dev->nregions - i - 1)); + memset(dev->regions + dev->nregions - 1, 0, + sizeof(VuDevRegion)); DPRINT("Successfully removed a region\n"); dev->nregions--; vmsg_set_reply_u64(vmsg, 0); From patchwork Thu Jan 6 06:47:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12705156 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 1662BC433EF for ; Thu, 6 Jan 2022 06:57:49 +0000 (UTC) Received: from localhost ([::1]:50158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Mia-0004vH-1J for qemu-devel@archiver.kernel.org; Thu, 06 Jan 2022 01:57:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYs-0001IZ-H0 for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:47 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:1098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYn-0003Uw-2P for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:43 -0500 Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 205N628a016432; Wed, 5 Jan 2022 22:47:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=MEZI3WWwaeRzhGLs5aY3IKOUbNaBKGQl8ojrvdWtvOA=; b=PS8dkQxDJWeUBfueYIFFN2rQSAmqyBAclzQGWQ0XoNZQ8bIVPx9txyT7rHjyER4v7Zul eHi0OO4yd1ANn68sDW1IHApTwEegU9f7UT+ParQbXNptTf0g8Axb53CF7tzBUOYR4VLi ZoTrCL/RQhdEp2JH/QZ5KL5yKp0MgUa1pHWtt51IMK0UemCM1X/DOZV+UayNcLnzn46D 9N2x+RVbP1U8DmB5aG3nLQCjCLF7o74W69D9sauoggMMND1y5iVXKCIB4ZzWutV6JBCc 8nYhvI8fgNXPQnHJdsme2QW4ee8ubwG7Wf+IlWPrX4DA4tLJM/V5+NnIhcaPLT6e6yyr sg== Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2047.outbound.protection.outlook.com [104.47.74.47]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ddmq0rjs8-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jan 2022 22:47:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QI1dFhzhfJ8AMkMKKCrf2IyVIr9spDq6c9efxW0WeoV3vAhnjEKu6mzuJZ9xiPa4dp2rF4pcOyj6+dmRTAmYmKR0hX8vkzYh2ZfFL9IgSBe3BQ4OCPG9GYCjjCqCPn/pe6WW3HxzpS5f5xYaYYeSznnqbb9cKXAmZrRZ1dXvxCJkaGxsanKqB1uyNfhT18x34PFA7zV/4ZlZC+auu6ndeGhzPQ57GBFOSGq6K1csb49Ddjv+A6ExLR7tGW5oE+IhQBDyyWd2ja6GZ5xcs5Djn3X8SD5UbW5Jizf7TKm0B/5uyOvVKf0Xh2mGAU9/z4snoV2pJYZhjCVtAjvGi4QD3A== 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=MEZI3WWwaeRzhGLs5aY3IKOUbNaBKGQl8ojrvdWtvOA=; b=hiWTHFokE7MotXS9WXtyHIxJmFIDvSxOiqQXIjaOGmmR30DeuZ+jf4GZGHQe8yA7jviSfMkJi388Fue9RtfbdwkLIGM3LDXriEx6BQScYkVfuv2V28pMHT+6mlpmrGGhB+m4GQSCHFROn1yLq1NKJcNvjboBcz+mzZe+ZRjk67eTT8EonqwrCApWZmomV4iT1ox/Qk17//lDz1cjak+cV422HhtJpiiWEccuylNJ2KFcrVbgETbQzMUsuY6fIR5bG3g+jBiX1XbnYJiwE9+AghqySn8JVoSmIJMANh2nS41AHfPhPywBPYXmMy1hA185LH4st00IUs1eBReoEdV/MA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BL3PR02MB7938.namprd02.prod.outlook.com (2603:10b6:208:355::20) by BL0PR02MB6530.namprd02.prod.outlook.com (2603:10b6:208:1c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.7; Thu, 6 Jan 2022 06:47:35 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da%6]) with mapi id 15.20.4867.009; Thu, 6 Jan 2022 06:47:35 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v2 4/5] libvhost-user: prevent over-running max RAM slots Thread-Topic: [PATCH v2 4/5] libvhost-user: prevent over-running max RAM slots Thread-Index: AQHYAslJrasaFPyjv0K0XNFW9OKltQ== Date: Thu, 6 Jan 2022 06:47:35 +0000 Message-ID: <20220106064717.7477-5-raphael.norwitz@nutanix.com> References: <20220106064717.7477-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220106064717.7477-1-raphael.norwitz@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ba1ae7a6-2685-4aa4-a0af-08d9d0e06c03 x-ms-traffictypediagnostic: BL0PR02MB6530:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:2733; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RzC4y1ognNOu+iS9MJRSZDZ3Cv3zXwqZ1KjaCu/SiMs3h9fuqFmTb60a/gDV0PTDoAUKv+F/QDJqxqSEh4BHpdAcLhrMgBkMBPJH8MmvgqeGbr0XtDD1Q1UGV7Bns5KIWBOLdsPsk0sNaYtH6zDbytw6ncOA/j5iJ97LvJuKgOJXjalMQwQVQdbvvq36TXw1Km2KpX+zRkhj/zW14BL+2vaujhEMwneRp9YiIrX4jF0e9ncHnBt6lygNBhG2HpTHjrOFKW6gRokYC2tfeK5ILT4Y4bL9ib0x5e22qyAghHZOACLWURBV6gUOq3Cmt39kWkMlppp3Hv2srXZfLr2nHDmOx+XWWjBzLyk1YBZyRw3y0owNHIz/s0H4sx8hVaeHIC4Dv39hKacNJiuV4qfHiBwpBlqUOqAKqYEXbd5uPRTDhseNJTv8bP1MKA1TSjVH37hsZMktb/MxeJyFCGdxjE5MTahHtclWRSPAxAtlHWYSn3XRoJoHbDfTZibOhLRu6ioL3TcUSQQD7kk39f1h3iA5E0KXNEhk35+JVlrIJ1YZidsEt4WS92IlfS7gs+pkLLqMyquWruIwaNZM3GRzKG5uLXj06PV/Zd4ZMFiXQgAtNsVRpfP7fUuxEJ+caKCCa+uhM+YpiS39G3DHTqFGEf0WjfJXSh+3qrM6rqlaTV/EgZlmK9iPnu7sJKcJ5vVIwecFKaiUzOkIEooIbxkkMQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL3PR02MB7938.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6506007)(508600001)(66446008)(4326008)(76116006)(186003)(2906002)(316002)(122000001)(6512007)(66476007)(71200400001)(66556008)(66946007)(5660300002)(91956017)(64756008)(54906003)(6486002)(38070700005)(110136005)(44832011)(36756003)(83380400001)(1076003)(2616005)(38100700002)(86362001)(107886003)(8676002)(26005)(8936002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?k8vm5GNXAv/JcUAV2SJVS5U?= =?iso-8859-1?q?EJBqxiFrpqBKsdXom+YsqjeNP4A4zWo6cx+E9eXU9h3UUwvB7ohCcg/pXato?= =?iso-8859-1?q?9ISOEukM1xyAq3c+aPoHZ4qGPYhzqx3Y/XyXP26FSHOOgZQOSmxw7ER1HT6/?= =?iso-8859-1?q?MI8uNAfd3ICY2bbxAi0yG8G3oUmMAq8RSagTE6ZzVRdyemV5QQA4NWB1r+Vr?= =?iso-8859-1?q?JIFcev/M08BDyP4CPVHiE0q32NImQfVZaIj9LpDxGjunOWTB8Yx/Xg4tnTcy?= =?iso-8859-1?q?1QHaaNeNnyjfY7d4LNzJulp3AwnopHjV9eMqahUE83cj3ZJnblxTFMan0hgQ?= =?iso-8859-1?q?ujzXbuAznyqmpw0/gGELW8FzVPZQDW+z/pJA5lrwTuhk/oQdqKW4DD4DkUmD?= =?iso-8859-1?q?zXCsYQK0uo3rcRNN0b62MEBTZrgmEYNjcFga+MzHk1GKETk0CfKS3zbMH9fA?= =?iso-8859-1?q?uTXS+FhV+MTfkUXAzxvKyzBGCbhGmj55272W143Xn0pN9G2pQL4uaKr+NrXt?= =?iso-8859-1?q?KL3YXWU0nOST+MbWlCyTOOYKZpn+oyGI+Yi+Q3Dv7C7WaxMGGtHkkHc84SUl?= =?iso-8859-1?q?DovvTE7Kb4kvVom2ngXZURul+JdqJa/MlhN40v+UUJUYSdX2zOydW10TGKfV?= =?iso-8859-1?q?Pbz+GSBnwvVWxtiyx2PIDNVRyaOepFENR4C5gaZ7Cszz9ThP/oZuhPlVHgxO?= =?iso-8859-1?q?o2VW1L/Yx6xON96U9+kzIEqS6djUHLb2QqkfLfyNVXol77ziVJQs9w92UmE0?= =?iso-8859-1?q?4GY9RGg7naZVl9zD6raQ4nniE9JYB3Y2RhjUSVmugvdPCe60SoDyrYa5Ifzr?= =?iso-8859-1?q?DLiyZRarstFGG+8a0MAL+v2f2jRWtieyNM1+w3xhXsJoHdjJ005a0E5LvMqa?= =?iso-8859-1?q?/2he2IKp3HaQP5oMTGQ7N/kWdR9MonATviDRFAYh8rRg17bLu5IxnqLlZ8Zz?= =?iso-8859-1?q?aU5ThfwAKQrc+xSXtRCR7kpWlRHwC5gf283pr/xx/HPajdwFXTPAwkHWRhi4?= =?iso-8859-1?q?rudaOtkiZxlvBrW1NvzIxnvX6Dq5XHeATtQt+9sUV1/q0pYbDyTGYHx/mhN+?= =?iso-8859-1?q?3MXtW4tY4nJ8Cr3VfhIyfotHOvLyxXsqMGnNzrLylcZ7yo6ppGg7aAjhFiNj?= =?iso-8859-1?q?hgyJcaiNJgfupl6YJXLTYUYXjj0QYWkijFaIDkEsyRPuvu4eadNp8bEg7VrM?= =?iso-8859-1?q?TZn4d0PIMVDAvlJHu6DeOMuRnxTR/Y1q5Ic8g30wF/eGOT0m+lWtv2uDQMPO?= =?iso-8859-1?q?a257Dv8UycJT5tYJ1LK/N3OhNl3lwFPe128VOIs7+yjy/bQIaC1vQ0DSjD55?= =?iso-8859-1?q?U4o7SJB1+KrZiC69VYEXJPMmtIlJbSwqBr5+ANs6DWKFQlzcCLNzhBspcbXj?= =?iso-8859-1?q?Jt1z5GD7+omN3nTOP1hAQe6dA539Xjj6i8nqy6zpILksdRE0WqNeY04UhzTg?= =?iso-8859-1?q?vw5+ieeZXWUxUc5RTIN1I/CPW6GnHCmhnFumRBMbUg4yLtmJhjgbwesOp3r/?= =?iso-8859-1?q?PMqU67P/2XNQD+rn9FED34M+w1f8pbCBqdUs2nGWP/HoeSog16dcUj1Gp9QB?= =?iso-8859-1?q?9pKqD3yqNWjkONS88YbjvMEiaxIfQuv5O0kZfTq4iV3UFEEURLy8+34bwk/X?= =?iso-8859-1?q?XmoEI6/aug2eaqsqTTYuYTV6QFCCfgwL+Qx6lEPOWZw/zACTAK1k6NLBhFsH?= =?iso-8859-1?q?VNaEW8Mi7QoP3Fhfe03kaVFsxLMgdvTfOz+Izibo8jL9qn4YnGf7+eyKtq8W?= =?iso-8859-1?q?y6dc=3D?= MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL3PR02MB7938.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba1ae7a6-2685-4aa4-a0af-08d9d0e06c03 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2022 06:47:35.2284 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Uz+jsgBm3WytbvA59QJMb2VLGcFNzifcZgtTiLmlFEjMqvUhMSijqpwcu8AxXVYPHWPN32QHLsU5ZDQZQgzVOl1kXQz/zcCddvTIwS9zmKI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB6530 X-Proofpoint-GUID: N4uW55kKUwVJOOv5Hg74LTrYFJw63MDG X-Proofpoint-ORIG-GUID: N4uW55kKUwVJOOv5Hg74LTrYFJw63MDG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-06_02,2022-01-04_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=raphael.norwitz@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.372, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: "raphael.s.norwitz@gmail.com" , "qemu-devel@nongnu.org" , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS support was added to libvhost-user, no guardrails were added to protect against QEMU attempting to hot-add too many RAM slots to a VM with a libvhost-user based backed attached. This change adds the missing error handling by introducing a check on the number of RAM slots the device has available before proceeding to process the VHOST_USER_ADD_MEM_REG message. Suggested-by: Stefan Hajnoczi Signed-off-by: Raphael Norwitz Reviewed-by: David Hildenbrand Reviewed-by: Stefan Hajnoczi --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 77ddc96ddf..0fe3aa155b 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -690,6 +690,11 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VuDevRegion *dev_region = &dev->regions[dev->nregions]; void *mmap_addr; + if (dev->nregions == VHOST_USER_MAX_RAM_SLOTS) { + vu_panic(dev, "No free ram slots available"); + return false; + } + if (vmsg->fd_num != 1 || vmsg->size != sizeof(vmsg->payload.memreg)) { vu_panic(dev, "VHOST_USER_REM_MEM_REG received multiple regions"); From patchwork Thu Jan 6 06:47:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12705166 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 926D9C433F5 for ; Thu, 6 Jan 2022 07:02:20 +0000 (UTC) Received: from localhost ([::1]:57118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Mmx-0001C5-9u for qemu-devel@archiver.kernel.org; Thu, 06 Jan 2022 02:02:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYs-0001IY-Hl for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:47 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:31656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MYn-0003V1-PE for qemu-devel@nongnu.org; Thu, 06 Jan 2022 01:47:44 -0500 Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 205N5d7l019176; Wed, 5 Jan 2022 22:47:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=ZrTQuP1eHTblEOoT+tEM5kuaqxctxCDHBQ9CDJqOh44=; b=PPJxCig71k7pdQmpum/fUWIAHxZ2ZjgZgqJfpcRGtcZQ8OWRtbxCB/T/1esAvCYY9o6C GwRfrowJMIFYS6YdVvE5NfxwX1Wb6GWuJ2PfPeZ2opScZOsw4N6fF95pddgCBkrSHVUJ /3FsKyHxI3x8iFMEK+sGdRYKSWZXa+n+j8RSpVO0O2vvJw2KOktAgEvjMtgjghltU2qv OUIg3onG4a73V0ulMfi5nRQM/atYK4iXHV6TnRTQsj2do/lK25ejdlLLNEG8GspGyE5X vqzozjgS5Dz+jKJ+zfzg2YmpftyoNzSL8Qlf7IKvIzjroAbuR6Lnfi78dIPQVCVFrBxI bw== Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2045.outbound.protection.outlook.com [104.47.74.45]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ddmq00jfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jan 2022 22:47:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q8aQQRyDnZd9STGQviU1Qrq87VPPVm4lad5dXmMFwJCbxXKLL+qTIM+87Iaw7JJNGGeAyl08NQ6BkbgqERqpRRkdQJQ+u2YcQvX+6B0GPdhLcwPNMowLesO22yx/F50uwm+DocD3JjCT4DUYzcAUsdKRmm8Yx0tU8Qp3vrFHpCHBTCqM3iLaG/xFu6EH/JebFQ2x5+U4XsKNCkfSfGQuu5JJXIXU3CZwKRlqY8tjtkzjXW+k51Vp+xwkdS90bU/kmhdi+ObQmBGCPAO47FRDRD87VmZD383Pj91ZLBT0tqH8RkOTq8MEcBUxarCdW4UuXOMbNEJPVjDSNJfgL8PrSw== 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=ZrTQuP1eHTblEOoT+tEM5kuaqxctxCDHBQ9CDJqOh44=; b=QEFKi1qAagCwr8jJaSZuD7lZ9/70Ckweq+9uJbVMF4KSg3tVFMKxay7G5aHtgaUWHS39Evf/PalZHK+ndL1IX2hZuuwLUqBbeeJojn3tLQjjtaVxioDjHjQ/rvY/b9GhBdaobhdiTjnKSBk8dctVyO4AhCxgO4tSKjMnoNkd806OWhV5qGZQxAYQTJzlhUvCw1bNMEnNC/BbLdKi/8X4pCpkUkm5WO85dLBOJUeT6igaUFiK8BxkvK9F4gBGB7NDOA7BlCls8sHJTfwbp71QM+NxH1wwHr4SfUlWq5rwM5xDUk8WjRlK/cpe9euUrpsSs9bvkCw+1dZ1+C4JWatw8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BL3PR02MB7938.namprd02.prod.outlook.com (2603:10b6:208:355::20) by BL0PR02MB6530.namprd02.prod.outlook.com (2603:10b6:208:1c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.7; Thu, 6 Jan 2022 06:47:36 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::3c2f:b2dd:a0b5:74da%6]) with mapi id 15.20.4867.009; Thu, 6 Jan 2022 06:47:36 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v2 5/5] libvhost-user: handle removal of identical regions Thread-Topic: [PATCH v2 5/5] libvhost-user: handle removal of identical regions Thread-Index: AQHYAslKMYrBF8S8f06BB/viZEFlKA== Date: Thu, 6 Jan 2022 06:47:36 +0000 Message-ID: <20220106064717.7477-6-raphael.norwitz@nutanix.com> References: <20220106064717.7477-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220106064717.7477-1-raphael.norwitz@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 03b978db-8063-40c0-7a50-08d9d0e06cc2 x-ms-traffictypediagnostic: BL0PR02MB6530:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Pw5pouep6/AOUedVSglUWzaVqpS+Ed6kMsxGeBh+uMJMyMpCZhenBrNp3w9eEUE4JbjbTWrchlrxo+KgUUVg1sEOGpFuJXNttuD27pRYETpNtyiLAkVvF2PpzKkOeV98D4gIsQpUXM++QOjnHO8M3x4oHMaerIi5yxZpWdgwP3XR3WhHZkNyUFHZYX5PDciBsOeWFNGR8IeYLlmmGP9URvNEkFmR31fR27FTx1Xwe3Sr06zP6647jPgOtn7A1+dmYb2xweUhgZNuVwyPqa+UGJjQyF6hmUGN49CXGlcMfgLoJ8fVWSsgPA/S2vDvHYCMGhw+BrqRMfwbagQPm1W9IezxVHVde7BesedlMaYcz8Oehm5DRORhegN3yRXVwmhmclJ5mcVAfkJ69AzCnXuogZ4Ussltievn0dY18cf34NMXveAraiNWssYw0vopi71SdK9GDa3p1HjuFhVXGrYzIKUc1sMiRWiSPGPKrevULDsiTu/aJyDY/SSo0PX/gNd930JA0C96xblm7Rv7z5eqV1elIv+Apto2pJypYamJwMMur1K4PWWQ5QJCsq3feokuh6GnHzXxhlHkn6m8oHY0d9P5MoVR5zT75GWk0H8b38Wp0Rti6ZMMIV9yxE88OygW4wdpZmr451wHKDv5ioVjVsZ/3PIkp8WMU1thrdTQGm/OvmQG1rZ+ekVRCysKLohGqnaEzDHPnCg3Nn/3XiveFA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL3PR02MB7938.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6506007)(508600001)(66446008)(4326008)(76116006)(186003)(2906002)(316002)(122000001)(6512007)(66476007)(71200400001)(66556008)(66946007)(5660300002)(91956017)(64756008)(54906003)(6486002)(38070700005)(110136005)(44832011)(36756003)(83380400001)(1076003)(2616005)(38100700002)(86362001)(107886003)(8676002)(26005)(8936002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?fXUa9lvxLIUS/TFyyWskE1t?= =?iso-8859-1?q?ODQEshw1n3W8DyLf/9nj7An3yx38ujyO04rz+/YaYXbR9KHdvzPiu2qQseT8?= =?iso-8859-1?q?RR4geepgCcEXL2NPmKoRoqoCB3GrGlNo/MVAY8dWTRvxUoJdbwjerkowZAsT?= =?iso-8859-1?q?63QWvD53Lar9gQkq0t//LUosIzeSCcapegcOX5JGF1IyTAz2C0MESUm4yDCs?= =?iso-8859-1?q?DqWf3nfQ97P16IylbwLBjAfWiVnFQz7KCxIGrj4Vu3ogiFmaiNbIgXonumSw?= =?iso-8859-1?q?JZsyOBOS6/boc53tks72owRFXE12OP+GwWSasm8ZUErHoAXoGy8immSpkt92?= =?iso-8859-1?q?kNNza8+jwtoOtXb5QjvI1eEFx0/sc6fG82RpKvcG/QqTW8SSycGRdhMGzMhc?= =?iso-8859-1?q?E2h3wz0jI+NQctlRhmWS6Kl0J5hN8+qjw2ogKeEdcBL+SdQskr1wv59N8s3c?= =?iso-8859-1?q?sa7ED+AX1ekR0v+kpDAhKLHnzTbmP27N4p7s4hHajn3G6NhdTsbW0AFhA2Vi?= =?iso-8859-1?q?d5hnjJW22bs+vpe1Sa2NC9PBK/Dl1JCNEqDnsADnIah1f+659nyKDKcswOcF?= =?iso-8859-1?q?ww30iTNWKRQtW93BHnyNtuCVRJr9KaSWothvCbFsotj9FiETZC5jeXemYdGO?= =?iso-8859-1?q?JkXhTxD6jyAjPOYIuCG/iiumuxrsLLCapZwvhKilDY9hsOd+uLF8UewPD91m?= =?iso-8859-1?q?8UlJLuaLg31RST04a9wfNh5zHvB18bCulEmvqObL0NmaAe5t6T9T/JYQbrJs?= =?iso-8859-1?q?idvNcVviiNwdanxwz+Z6awChbdIUNPwDmGC8QsCl5WD5XKW7XWeRq9yz/9IH?= =?iso-8859-1?q?sy6NrmN3StA8k94eHvvSLvr4++enQOvlulxwMefy5dyBnd6WtyNavP4Z8Fs0?= =?iso-8859-1?q?RYxOuFQ8W8EHXnh21aGPw74j0vOZWb73JE7i51ZL3XeQ4o0SxEv9WpJDSpa5?= =?iso-8859-1?q?OFC7LW2kf235QDc5XUIhh+p/Mf7oSAxw4moOG6PSYrVP/6a8j9EwbaBHyaqF?= =?iso-8859-1?q?KJBQ5Ndjjp/5sJn0lWES8V1UHiRXWICrJVqoTk4z11WhQa1K69JisAs6DDca?= =?iso-8859-1?q?q9SLGoZw99LSQUMX7w+b7VgodsAUEQrc9B060dPCD9Rx7xMLJ5csRD6wddrl?= =?iso-8859-1?q?5eyU3i5PTxHjM2yHkZA2obbeJz8X4sfqSS5LnLZ5wHt22Y77FkyvhJ69F+Wu?= =?iso-8859-1?q?OB1Ey1ZpAlZRAcv+HQ/n63Rpyj2F6u/dMtD2mJLA0fiKM0M6Cq07OZV/mXTi?= =?iso-8859-1?q?pORxjK53zjJ0YESFnMDsi0DbuGMrE7//vx+SL/3u7+ueCVtvuljemgiDSRfR?= =?iso-8859-1?q?jwckd7AAM3EP6AsD13nw+lEPUvQXGW4nQufb8YMkU7p9s52tuoivUCLteBoR?= =?iso-8859-1?q?DqoSJqtHV9HAy4++8X1igXh3wyizmMk0kIKIMEGz4n3sIOty9CaepnW6ihfq?= =?iso-8859-1?q?6avvMHGvfauEdFbd/2jk88EuaRHAuTu4lB+2uAjFl6GngYhjlVFfmtSr1kl0?= =?iso-8859-1?q?VNHur79h4fO4ipXn1HE2g5eGfkuEQl9KULkZqcDdqJVixMonIp9OlEMtgjpG?= =?iso-8859-1?q?9Fw6QFZUw9aRFP/NchRAGdUfDweYbcykRThexZ3wy2bNOsKgxxsyN+N2jh+z?= =?iso-8859-1?q?U3V6O8yj2ohxdY2fC9RD3h13WbNNDa/Qjor4H4wdMr1tZspTIIaiEKYFQJBo?= =?iso-8859-1?q?OmuB9PdWQAMd7yY4G1cJdqHao+HwvIKjHJVhemnqrbkbaJGdr01WFmiV2TQe?= =?iso-8859-1?q?HANk=3D?= MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL3PR02MB7938.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03b978db-8063-40c0-7a50-08d9d0e06cc2 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2022 06:47:36.4947 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tHMYcmLKnxLV8fDNZPRrTza7mm0WkOs8pcLIiXFsBCL//6CzlDptRCtNxTC3CM5j4O0pGuEJP3V9P4kRxGE8g5a2OgC4XZW9AwyxBV+cfgs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB6530 X-Proofpoint-GUID: nS8F8BA3yL98RDbFgxyETmujc271kkmj X-Proofpoint-ORIG-GUID: nS8F8BA3yL98RDbFgxyETmujc271kkmj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-06_02,2022-01-04_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=raphael.norwitz@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.372, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: "raphael.s.norwitz@gmail.com" , "qemu-devel@nongnu.org" , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Today if QEMU (or any other VMM) has sent multiple copies of the same region to a libvhost-user based backend and then attempts to remove the region, only one instance of the region will be removed, leaving stale copies of the region in dev->regions[]. This change resolves this by having vu_rem_mem_reg() iterate through all regions in dev->regions[] and delete all matching regions. Suggested-by: Stefan Hajnoczi Signed-off-by: Raphael Norwitz Reviewed-by: Stefan Hajnoczi --- subprojects/libvhost-user/libvhost-user.c | 26 ++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 0fe3aa155b..14482484d3 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -809,6 +809,7 @@ static bool vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m; int i; + bool found = false; if (vmsg->fd_num != 1 || vmsg->size != sizeof(vmsg->payload.memreg)) { @@ -835,21 +836,22 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { munmap(m, r->size + r->mmap_offset); } - break; + /* + * Shift all affected entries by 1 to close the hole at index i and + * zero out the last entry. + */ + memmove(dev->regions + i, dev->regions + i + 1, + sizeof(VuDevRegion) * (dev->nregions - i - 1)); + memset(dev->regions + dev->nregions - 1, 0, sizeof(VuDevRegion)); + DPRINT("Successfully removed a region\n"); + dev->nregions--; + i--; + + found = true; } } - if (i < dev->nregions) { - /* - * Shift all affected entries by 1 to close the hole at index i and - * zero out the last entry. - */ - memmove(dev->regions + i, dev->regions + i + 1, - sizeof(VuDevRegion) * (dev->nregions - i - 1)); - memset(dev->regions + dev->nregions - 1, 0, - sizeof(VuDevRegion)); - DPRINT("Successfully removed a region\n"); - dev->nregions--; + if (found) { vmsg_set_reply_u64(vmsg, 0); } else { vu_panic(dev, "Specified region not found\n");