From patchwork Wed Dec 15 22:29:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12679641 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 1748AC433EF for ; Wed, 15 Dec 2021 22:32:28 +0000 (UTC) Received: from localhost ([::1]:57600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxcp1-0005sR-GX for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 17:32:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmZ-0003Au-HZ for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:55 -0500 Received: from mx0b-002c1b01.pphosted.com ([148.163.155.12]:24610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmX-0006GU-EL for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:54 -0500 Received: from pps.filterd (m0127844.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BFJxfxs001564; Wed, 15 Dec 2021 14:29:50 -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=nuSsZrALwAsYsylkfcJhbLBPgLPDA6grM0nZdedhyd4=; b=ZE0TdU70Ru7yivNfH09ZGelOewQByWNz4X8SJsP89MahOKk4ka82PoDsaoDkrXoRIe48 3hLaDF+7+XpL3PhBsp9SSGsren6rvGNU9RKy996cuL5LlKTRWoUDTrkFuIJeRVBi5HlN TRp2xKPgCVly+6dR+RK2SBgy7i6lxSsmnfB99eztuBn8zOlACsfp9xLTCq7Uzgmf6iYo vsPVl8DozSrPaJS6ur0m7stkDFA2ucYk138Tom4kEkSDYwIY96D2Wbqh69s5v35cLgOA nZrRkAb0RUB8cwcg+UivEgW05XztoIFNVzjWhl5bJEtMlkFdtM1eNSyVh+UGOxzh2Jnx fQ== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2175.outbound.protection.outlook.com [104.47.59.175]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3cy9rghyng-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Dec 2021 14:29:50 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iyvV1inZk75kSAwcDaVLlKfzJT2/rL5BlFxNTL3S4TxD+UtVzTz6Vn8MhvVSt9S3phwEizSienMEISFDy7Xhu6lBoOPN6TIeQf41Ufzp9HHKqMZAXW+I+IdbM2f71WVZU8Mrq3AXUORCAKpWDWMkKhBra/N5t1I2Eqc2/+rnGoMgSYEiY8Kz3IaLe6kEkED5OQ9rN81zdexo3nWxtRLqXgnjPEW9mR5wy8bQEmHOfVzFOKSEOiwqiJbSdM9V/4QqITKxpKAXq4vw0x+HSmO/KVu4xdYZStAcmlCLOdLdUSFIg+n8+80AbhVuRm4zAN2tvUTlV/904i1GfMaHQ2teGA== 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=nuSsZrALwAsYsylkfcJhbLBPgLPDA6grM0nZdedhyd4=; b=UEVhmSOMdm+l4gwe7resW/6Zpq/3YUrcAyz6AycQkbfrxGwYamEgg55S5krDQFIYZztK2s7ZejU6nNXZsXySWDnQscZkTxa1Aq+1Y9cFrNyic1sVusX5L7+EK3fhQoq9jSbsLhv/8nr6BERaGN7cJ+Bn/jZui2CvTpPhakw1ooRR6v7nK9Z7wAYWShzrm44qYrQAgi4wd1TkzEldwS88RdfGOoHFBUdY4Shv0No8ib2s1gttswWL24haVEvrlHxpTnGeYidzAw+RsFdK/UX4DtpD/jOfZs4biErLEIyafSh9GKgyEqFL/jqJ4T+8eNRA0nOMdulUwltopOdiwctyuA== 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 BL0PR02MB5457.namprd02.prod.outlook.com (2603:10b6:208:87::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Wed, 15 Dec 2021 22:29:49 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af%8]) with mapi id 15.20.4778.016; Wed, 15 Dec 2021 22:29:49 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [RFC 1/5] libvhost-user: Add vu_rem_mem_reg input validation Thread-Topic: [RFC 1/5] libvhost-user: Add vu_rem_mem_reg input validation Thread-Index: AQHX8gNFcX5r9V9SQEi2GWHMy1c9eg== Date: Wed, 15 Dec 2021 22:29:48 +0000 Message-ID: <20211215222939.24738-2-raphael.norwitz@nutanix.com> References: <20211215222939.24738-1-raphael.norwitz@nutanix.com> In-Reply-To: <20211215222939.24738-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: a6e175b5-7f4d-4968-007a-08d9c01a67a3 x-ms-traffictypediagnostic: BL0PR02MB5457: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: x1u8cfWtNb3YE6nM5NwXxW6aQ0wBL/O6zLsHfXlMq74D8p2INrF4qBKTkuHVH/iRN9gv/Zfwhj14fz1fTn0UjaFoNPCgxiZNjJnTnDZv5yuqDWtZ8qj3Tgtok9DMjzLoiDznNoP7+hMp9T0T0+5r6qkRNiRMiVKKwnMg1ygAXrxDoGDfmnHxyMuRj/YWCda2Jj/uzK4qvsLL703SafHmKSxOBpe0hxq9TkZ6YEJnqcP7lUtrRMMG705+965N3X5ynHPelrInM1jUdTfcjkBd8/o0FFhDnbSL5pZlOHoSULU+lxl4nmslt9cpWYtEBgL0MRc7nCCBqU3jT8uBEDBUiZP2akrFR1Z29+Lf9zXEytfDQG0YT+pai4aBxmzul0m/kKTt7mD0m2ADUHhpk8OWEboCDC9aQbCREXjQ3enwmLKg96ZPOD3896gTEEjftcCb7tSDJBVlYjjWV5dRe6HoMClabJfcwWIjd1IXAmVOlkydRFiLFXx4O+BAPPRI2xQ/k/vBqqxQT1E77iGimcFmHaTjN8qRU2SroJGeB4NGFaBJPqn3ybvx7qYGlMdmt1PZPqJXxgLLlFIKCFz/BG8i/w3Pbw98/nMvgo1Ee+hXML1/TdNs5pgBMzm60Isf35v8nxhAZ6ZrF7md68SBbAZh+VXyyndaynmTGqB8vLZ27wASE42hbqH5Zqpq582RQ1uPTiaC2ifMPGWfpTKc9zBDPA== 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)(2906002)(8936002)(6506007)(8676002)(26005)(1076003)(107886003)(2616005)(316002)(110136005)(122000001)(54906003)(5660300002)(38100700002)(86362001)(38070700005)(66946007)(186003)(4744005)(44832011)(36756003)(66446008)(4326008)(64756008)(66476007)(76116006)(91956017)(6512007)(66556008)(71200400001)(6486002)(508600001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?Ao/6giGFOO/NRQIG7N/3am+?= =?iso-8859-1?q?2f5EsgdeEtqX8fZGdmdgjMeRQyyTlu0purySE/cb97wGmQzC32hqJvHju3p4?= =?iso-8859-1?q?Fz0iTx5gdvQKwu8h0b85oTlFQ6w/3sZ9IHMsGCGovRaNgPjMDgrRzRnS08yD?= =?iso-8859-1?q?sy04sfcZcYRLvOOjMRdL4llSrawDV2dAjL3hxMwgexXrZndw5EBHE7mX2j7y?= =?iso-8859-1?q?KE1Hiz2p1brO4X65TrhcxB6ILmSPJ39yWSrFERP+7AsEQYSIHrgJ3PnWOpDK?= =?iso-8859-1?q?4tLo9ovozB36m7WLzxxn/2QXYJb66cZKhI7hEzVFT3/28Iw+ZrIq2UjhHkwZ?= =?iso-8859-1?q?bCo5Jbl24QA6Toju1QRyMNJQscSHF8EZVNFQOC1i/HKgaIxkTr4lyvTi3VGI?= =?iso-8859-1?q?BjuYbh6MbhZrvFHuRvYX9DC8eFun+ScXO9SDfoAQvCJH7RGoVRzs6Vs3i9mL?= =?iso-8859-1?q?s81zL6ffb6dG462MfVNpv9cnArdAiKYblmNqhmq7DGJbVFdcYluf4MJI+Rol?= =?iso-8859-1?q?Ia5eTQosjlIkqzY7P2z/snrXMkmPBm2yLcpiABACQWlpuLEgLA8HG/A6Gp9j?= =?iso-8859-1?q?ewT9o4avoYnQos3YE/iN6vCnQtnMBeTqgMrAZ6+GRP7Vqbl8I9Lg+Ceol7hS?= =?iso-8859-1?q?MPdFe5TnqLtav1vWlF8Un2FtiszL36DvqRNbmciIaI5gYCEbpFcxkClPi208?= =?iso-8859-1?q?DkWkwRm2N8t+l05V2+jzqfayo0Z2RmAllv2BfwQZSUpc5b0xzeFhLZOOyt1z?= =?iso-8859-1?q?MbAbYV9Fgh7k3e36BSyEcEcD2EcP8gXOHM0gLJqmg2WndKHtBzlhG2uTCjPO?= =?iso-8859-1?q?Qof4AzI3qXEEV/WUuJuMqTMdXWERO1FXJ5dVjdCehgCcjAYr0F8ceOQ9zPFq?= =?iso-8859-1?q?64qBFc2TvEGBnle1grEaAX4t5gvs1nGvMjue024w7u45x4l+QgVsKzOunz4M?= =?iso-8859-1?q?LTSwK4HtVvFNjeB8B6lf/Gab6GeuibqHSYzqoC1ia9XgnoyBcS9KM/N4y74D?= =?iso-8859-1?q?bNVL12iShcut2Tu1kwT36omnSQL3MNpPgkOMLa9xctctFLZkKe4RMuc6GFHA?= =?iso-8859-1?q?sQJ2VT7qb6QCatOnAtfBkI9ibm0kRYCbcViQ8JO9mFEuTh3mYQENFFuoFuCS?= =?iso-8859-1?q?+vQzUwgrC6I2C6FuMCKBNq8dTWcEPJxJJzeNBK4hEyik+Xc2lpoBZJax65E/?= =?iso-8859-1?q?MFaY+YbJVGoiO/rdZbk36xNiEWWfmzaia8iQN+P70w2Bg/P9NQs4aOEjN+jo?= =?iso-8859-1?q?ik+BOZPlFD8z15B3Nb6z1I18nanxNse2BkZ2/iRrVoIkd38mU0P7YOPo8LHq?= =?iso-8859-1?q?MgUWdhe8LByM7R4LqcpLTmmAiUjbYF1JA4cdaUZrEpNwl25qqoKgNIaicpX+?= =?iso-8859-1?q?tOCRZNs/y1IJo35h6PFFzUQXe9EOAEicGBKeNQFokl0OHYh61NEBLQKvq6Ve?= =?iso-8859-1?q?wn4b1ONHlw3uxJBTJyAkZBKhHkbqtxVtArWK1q4dkLmtWOGkF7MXORg1ViSb?= =?iso-8859-1?q?M4tWQpVJVZf0YYJObs2BQAnfBeyN5L1ndPyfMJXJAQSw6E48JMD6WE//ivFu?= =?iso-8859-1?q?B416i1JLnBzSk+IeB0HqcHTUduU4JNZatHqeG/oD76IuI3dman4r83qJbF4B?= =?iso-8859-1?q?tp545gnt545P1e8cs+AuLCDC+UfFzBrkZMqkIstKpzrDw4GWhr4NGjOUM28w?= =?iso-8859-1?q?8+tFGO+QXPFDW1c5pSUhMJNuZJDNPVpUjGQIrVQ5xqoDowZQpX1cz7jBdcoS?= =?iso-8859-1?q?AtP0=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: a6e175b5-7f4d-4968-007a-08d9c01a67a3 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2021 22:29:48.8272 (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: mW+GRqA6yX5AVPhDMBXgsNJyz2+42knZ7gSly10mAkfcWIayRPdT4zghOYpPVAbbfTl9j3ThRwBMgcNzcUxCFNDUjCXlDoCrmBxMWJNhnLo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB5457 X-Proofpoint-ORIG-GUID: 9Qxs6JXegM89ZDS5xH5wGP4OERtka4cB X-Proofpoint-GUID: 9Qxs6JXegM89ZDS5xH5wGP4OERtka4cB 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=2021-12-15_13,2021-12-14_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.155.12; envelope-from=raphael.norwitz@nutanix.com; helo=mx0b-002c1b01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, 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 --- 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..573212a83b 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 true; + } + DPRINT("Removing region:\n"); DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", msg_region->guest_phys_addr); From patchwork Wed Dec 15 22:29:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12679645 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 E556BC4332F for ; Wed, 15 Dec 2021 22:32:30 +0000 (UTC) Received: from localhost ([::1]:57736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxcp4-00060I-0n for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 17:32:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmb-0003BJ-9a for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:57 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:58992) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmZ-0006Hi-8R for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:57 -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 1BFH5dmK008497; Wed, 15 Dec 2021 14:29:53 -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=PtGCuDxEckuBK3yvXOYSpj25gDw5Q+j+tkyOlF4kfyY=; b=2pJpVp/RF15U7C8t+cn5nTFAgYrbvgbI+XU/bdj77zpC30p5Sc9PIQPx2VJXhPxjdKEm eijY9Cd+lQgByh/v3DJNR7bHp5CxjCMKE0N1DJKUPcXbLC1HJTEUY9Giwi4YhAn3ybeD MThy4Ma2U7LY97c0FtEBxe7gkwoST9UgyRmtV1bOlRhYFMXCHB/TlTXz3k92K9raP+03 bU1ELXeSdW11xr2GS5GH2JPKYlEtbkmbF6qEZ8chCxy3xDoehHNiRP6EKZhvu1FbZ3M/ fQ5b+ndYXTxudhDXfqgIyZ9pAeVRbitXMURqXXYhp2VOGsFXn6wKaNPTu0rcJMByxp8A Jw== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3cxxf6393b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Dec 2021 14:29:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SvOZqoV94Ac7eZEhrElIXy+6VUNIOBN21nBkgz+OsZqfCgWWm4azz9VJX3ybu6YNWoltRjP1cS5gYmIwhp+hd5WekRm939P84rXwW+bFhY2z6++5IJLHs0MSvbO+IS1F7ve650ivnNPteMvGkN7ljXqcYDo6k0yE5VTZDxQrtGFtnGPQLEyMn1eDY0KXFL15bY5iw7uAE+iZRhrtFAWtApdwfXfDwAnSsNs6P3hAC/abpSVn+BlFc6hh38zunRrKcmKDxMi9oZuL1mMpFF49mERq2X840jq+bArdDs0BUPn4jiXf65nf0/px8b/hW2JjspqLxFb021tZlITuWocVEQ== 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=PtGCuDxEckuBK3yvXOYSpj25gDw5Q+j+tkyOlF4kfyY=; b=ZGpUCbBgg7Nc6AAzeGDfceFd5eZIfexLdUgVuzYir+tBrY2uXEFamh9qbTR7MT+Lf/IU7eVrm6s+JMzJzI4I4Mkbds3rkQGOatjTuY2ioBla/q5U7NNzNwBcehdrlnwh2Rz8yXpvrAH1saGdWUnSQowdf08PeIXwflBNpKL/Z6Fp7rsGyTioF3dfRx+V4ftF8mit+Gwm8o2uHkkso3BOpbY11t14tUixPsxUFt9t1JwKVP2tzny7KYE5YRq9MW8pLOrK1ddPhObuDNP+/TzJrffpPQvYHr3a5BBiJcJEBBd1+1onn+4eizcpzYfLoPKToyD0oXDJMagHQ4Vz5pR2lg== 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 BL0PR02MB5457.namprd02.prod.outlook.com (2603:10b6:208:87::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Wed, 15 Dec 2021 22:29:51 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af%8]) with mapi id 15.20.4778.016; Wed, 15 Dec 2021 22:29:51 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [RFC 2/5] libvhost-user: Add vu_add_mem_reg input validation Thread-Topic: [RFC 2/5] libvhost-user: Add vu_add_mem_reg input validation Thread-Index: AQHX8gNGk6f5/sQJ8Ue54jIOt+owBw== Date: Wed, 15 Dec 2021 22:29:51 +0000 Message-ID: <20211215222939.24738-3-raphael.norwitz@nutanix.com> References: <20211215222939.24738-1-raphael.norwitz@nutanix.com> In-Reply-To: <20211215222939.24738-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: b17b2e54-ab69-4ce3-9dac-08d9c01a6933 x-ms-traffictypediagnostic: BL0PR02MB5457: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: +/tU3TYNBkUCwGzdJL3sictKPF/UDtgxs/paHL3N+MNHG4i1AE5vPSELU2fcRObZaOkL4U9rCgjJ5LIZinSIs+RzIiF0PTjO3yeRUNTpLJ5cSsOlNxb0r27PjC+SbfETWvr4p1unxreHVcZ1zDyZMGBRRlu2E6JOsY7Pf9fBxfL9BrhqjuqLMXZ3Tq63W/tDo1QRNRVqe5zCxezoJPvdL3NbLO248taBUqqzCxJtPnl0RF7Wl58ksqlBb4GRRhoOThw3Mao41euNjoRQUteD710eejSqATZvmNW9yVa2hepE2G6tRXog5XOB9lL/70zsPbs652Me6kfJybIEpfnXH7XZ8By0Q7uufvcKm2jfQdrsFSr/YSWgvU24ltzAjXfRPsOKL4W7GEJTgYloaNkQGd2p4A3SvjicUbZPbPq7o9hyGonlOrrPBCrZY4dGRXNyskb5s1+cadIP+aL7Dtud2oVsXzHoqCiH9et4g0N2GZqFvAjowAuJ9Qd0iatCRsl/kexRm2FP34t9tWi/3KyWqW8FLNkvl0uzu+7+5pB00P0otgMED8mQee2WfciYKdDGJno+wuX8LlQo5/od2n0bnqvtmFavnS0cypFtnD+lKMGjtwc9S1VPjKSZr0bXDf92fY4/vwsl+hSwC9HoQWmFxS+tSu0f7DralKr1oUaGNsgP09FxQqjFlfiogL/f9Q2zKG+zfBQue1p4ZeUgJd6uKA== 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)(2906002)(8936002)(6506007)(8676002)(26005)(1076003)(107886003)(2616005)(316002)(110136005)(122000001)(54906003)(5660300002)(38100700002)(86362001)(38070700005)(66946007)(186003)(4744005)(44832011)(36756003)(66446008)(4326008)(64756008)(66476007)(76116006)(91956017)(6512007)(66556008)(71200400001)(6486002)(508600001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?y91f1m+zcW5UOaE017oshSp?= =?iso-8859-1?q?qTGUnPJpFbFYtZ4X1YrFfKpVmH4RvuGj7h8ugQr8ln/gzwxf6bCNRtHInRtn?= =?iso-8859-1?q?Yl2SN22OXYvhnghX9I3czJSZWm3p9w/hTdQFRGlXVGHbudBwZmBaC82n8kUB?= =?iso-8859-1?q?+3DVicGfhRAA9P+X8qUtXP8PTA2jeTSl9zhr7JW/srkcGKdYF5sF2sN54omp?= =?iso-8859-1?q?wf7t0UHbXX9el+ljiWLizFSqVMlIOddWRuLVegxzmezPMsMunzu4VcIOGwoR?= =?iso-8859-1?q?a4ijQvhKVctfMsyQ5USg31sNqh3W6D8smjng/XJETNgHtLhd48y9uU980ywG?= =?iso-8859-1?q?KcKE/xdxalt8olC1KDzqawBhg4LioyPhl9KARXtpwJy8SnF+3jJUb5vQCqvp?= =?iso-8859-1?q?KtUMEvmo5KrSxPFYK1SKMCe4WZT8hmhqYNnW6DqsZJVmb5s87MWcrotfmFt6?= =?iso-8859-1?q?sYq0t3ucOhPI4msOzuyjd6Np6A59Qyb7IRDoUgMCSUzyaNBLClkn52vf7F76?= =?iso-8859-1?q?zxLwv+U0IojKzN4pyQOzZ2NHL3JwoclNnumkHLjmH+0JiXKxgPKWbnsBFVeB?= =?iso-8859-1?q?GqqSPBmgKN4N8QJCXvoYEQ3FuOfnFOVJS59VkgNmR4vZhphJazHM3l5GYYcX?= =?iso-8859-1?q?GxHrLm5rtkdRChXPtHPmCpt+xVy6k/j5OHbHL+qPcuMSm6BiYNcyDqz5qmHl?= =?iso-8859-1?q?Z51I6yz/Unt/XZK6Wyu8HxT1PRIj38V/YAnzYYWA/jyR384ZofnoM8qTdMTR?= =?iso-8859-1?q?qp0JMeoxxmS2UfQIjoZ+UN6FNEvanYeg+OUaM5PiCyGvoLsTAR7zguL9lgT9?= =?iso-8859-1?q?ZwBcMOIYQ0avdxfsdMNlDr4Zn9WfBgdtusCepevmKMnj9xynxGBpykzwIKQl?= =?iso-8859-1?q?UKAxsK1ZIJd4qfeT6DMgGIHt0a60EvRW2OKpBTNWUUrXBfaB2o+aoM399Igp?= =?iso-8859-1?q?gXNlZgkig6vVVKVHoZiMuHMmG6F2SsytY9v46C6gR8CuBrmBrQLbIMWnVlc4?= =?iso-8859-1?q?rVLehGgiTX78oqG2I5pIU1phOiuyo1Ra0xmvjSXiZ/OOM7Pzms5ryiybHgD1?= =?iso-8859-1?q?NmEn0cH2XpRMLBMLPJm3npbiKJvUwsGpgucgWyIKDGR7MdKgo0L6eJvztl9X?= =?iso-8859-1?q?g6XWeGF8RbImlYHR12cGYiNe70AViYsMDL4pJMLH0/NlU3pkMCelyl1W5BwL?= =?iso-8859-1?q?fX8p1lVMUUzcyqTUrApqylxqPqB1Ek3Kez7/to6bXOXzKA58wErXs3rYTdPA?= =?iso-8859-1?q?L/KymElG5/AYMDrBf5aI1upfUD7VP9whQqdb3DmT1ZHyqFhqeaxfJgww20oy?= =?iso-8859-1?q?UI4p1esk7iz285D5tI/uOFoUidKoQMgFDVF1k1llQOIVJlQNmrVwhY9xPn3q?= =?iso-8859-1?q?+e0TlEk3WJsrV1DXE2fomQ7d+s28I1DOyQBv3yzBizpnhtoNFF8T/orfrCGJ?= =?iso-8859-1?q?4luGP/gUpYB6enaUuJjAfQ3Kz2Sfp/e/bWZG8n4RjyFeJBjfsIbUkM00DMzv?= =?iso-8859-1?q?nYbOJis8CMoHAItY48ak+sN/a/rvlx7Hc0rF6tg19sdbjxJwlVj/RvitfWTs?= =?iso-8859-1?q?JAjtkKRIKGeyofNWVDGZG/r44ky1zNjeD20/QD3cVeeK0HVdk6rbdlN0/La1?= =?iso-8859-1?q?f6M3O3ivhOjLceIqm+5U9isK6I+vzTHtB4Rs3yh1K+xqNvQDnUgmkBWIIoiO?= =?iso-8859-1?q?mZsPXjmJqsFXmNHZZ0gqicpGesOmyJUkv4SCmWyg7gYdFUmv0gg4oMn1Azh0?= =?iso-8859-1?q?cyto=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: b17b2e54-ab69-4ce3-9dac-08d9c01a6933 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2021 22:29:51.4825 (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: JqtvyHq0sP7Bw8c0SGfDwIunvUbLwwc0GQBOhRMvEu9ZpcdPKJkhgv2DZ1BnC+QM4ArSl5nMtWR3P04a96cX++qcjqeM0R0vMqs44f4h+yw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB5457 X-Proofpoint-ORIG-GUID: hZM6CoT45_Jw9tLeWm75MtGo6A9z-AC1 X-Proofpoint-GUID: hZM6CoT45_Jw9tLeWm75MtGo6A9z-AC1 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=2021-12-15_13,2021-12-14_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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-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: , 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 --- 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 573212a83b..80ef335254 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 true; + } + /* * 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 Wed Dec 15 22:29:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12679651 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 53077C433F5 for ; Wed, 15 Dec 2021 22:34:52 +0000 (UTC) Received: from localhost ([::1]:36196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxcrL-00029s-BU for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 17:34:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmb-0003BA-19 for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:57 -0500 Received: from mx0b-002c1b01.pphosted.com ([148.163.155.12]:63560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmZ-0006Hq-Dl for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:56 -0500 Received: from pps.filterd (m0127843.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BFGW9bW007586; Wed, 15 Dec 2021 14:29:54 -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=qhcx8BoK9lmuw0eXEwdgVNzflU8yIUAE9P0MuTf2HwU=; b=MytN0SD0O61+snYS+6Gzhg7EifovgbfvmIt0Rh1sOHGHUX21GiP5WL17FqWsHsek2Nt8 b96Bcr6wzhP0HX7hakkN1GYSMdZe899KbWhzE6PO2zLmyzvEwoc3CFRudH9XCExGqL0o Acjf6QA1f2MZq4GDLYhngNATsPwcjDNOiHUiqKG6lQ22mPdXB5+ui+lFV2fJpZI7i3C2 YvXgENX/i9CvMhWF0ck/6dLYu/PvCT4fn1ADTUVK4jIoAZuYVVoNvq3ZzwRiLenITHUD 7zRTQEfLvS7IS24vDM5P4ASpN+L+2ZF1Lkq4zSKCAA3MC1HQ1YHd81FgYJLJz5wJIKJx iA== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3cxxfekbwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Dec 2021 14:29:54 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MkoIcGJOaYQG5st2hYqtcQZR3Dk6uDpipmvwTKQx6TYy1qSEs/Npl128TNBo3E1g16zHyitoNPSMbv1bgF66AW99WYuhZfsMwsw90PW4DbckJC2Q2L1VlB4m7NiUOdYeVDSn4Ez9MCX1Pk2qF6whyR2dMNYDhy9PanwI7Bl82tMtePIB8Zi2JnZzNvCZIfweWxZvinu/b690DrL8iVZj5TKyPvkkmfvsnHfbGpSb79XiZ5qke+k1D0avAhNVZxeZFIA6VJG8F5MRoEYPPr4SAJ6cJvL/6X7ZQ/y4Avr/gsO5yLkyIsbHupoA3TkTtgvZPax3voMwVm+KKhhn6KN+YA== 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=qhcx8BoK9lmuw0eXEwdgVNzflU8yIUAE9P0MuTf2HwU=; b=Ki3Mt2wrZ205mVKhqa/iDVYlk6RXKuBaMnaGa5vaff/WXwcn6ylcZnsnJ7KskTqpz/VUJf216Tu/SWfykMVwwOko8929+AISC6ieaKAmuUilg60b9S7AWjxLilr+L8EAmqu03peO0q6Hthqy+TRfiXS+z6DdwmvqJ9wOkFcwlyKP7B3hwF1hvyVaAQqkza0yRljc+LRPGjcyQ4fuUEeZUriQxqyR+6cqlYpUVsdhnGaS9lPj+XImpnx5VKZ/uZt2fWswO/0EoYRulkBiU2syidbLvK9AX6hnEfZ2n+mw+oJG41xNb9JnnX1CC5D6XjKbh43lwLeVmYGSW/Z/biORCg== 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 BL0PR02MB5457.namprd02.prod.outlook.com (2603:10b6:208:87::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Wed, 15 Dec 2021 22:29:52 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af%8]) with mapi id 15.20.4778.016; Wed, 15 Dec 2021 22:29:52 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [RFC 3/5] libvhost-user: Simplify VHOST_USER_REM_MEM_REG Thread-Topic: [RFC 3/5] libvhost-user: Simplify VHOST_USER_REM_MEM_REG Thread-Index: AQHX8gNHlUw1xJAqnEqojXP1AFe1/A== Date: Wed, 15 Dec 2021 22:29:52 +0000 Message-ID: <20211215222939.24738-4-raphael.norwitz@nutanix.com> References: <20211215222939.24738-1-raphael.norwitz@nutanix.com> In-Reply-To: <20211215222939.24738-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: da4bfda7-fcec-4a23-bbbc-08d9c01a69fe x-ms-traffictypediagnostic: BL0PR02MB5457: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: xSi5OmN/BxwWb2qtxznO/dXCNiNF7t43eMYY2cUGhC4gJSyccG3GzOwQPvJYtKpP1x42j+zJVh/HzhOAEOv2lzAYsEJGtuY6aDkfyrkYsL/N5WkMK7xDGo53m7uOAK5Vb9y7psGfbGzfS7kIOj7xG9Hdo/YdxRyxrAVJNmGkxWoCVVfkhk/1TgWgZaRcJA48tZN/HsBi8hMMLwv9ygw+vDwb83MC48O1ZJL86ELhNZXwj/n3hgUfLajKo+B+QAZT5o/d8OUWQHcr+vLRtKdYLFhOxOkiZTQRG6sjTdUYgsgbzbFbFz5kIxVrKU9EORAKhT8zLLVVdtmw7nwVcq/ytMeR4oRhs8XGxn9jbRqn6thOl2vGe+POvEB8Yj1dtYBbDuIsCjTDgVZqCzNxRTCMKu07ctYKOiy+PXwhCthUzIRWftUmctorUwVS2h7/oNEB3RzTl1XQJmOwvnYu//2jJAb6m6QhSUdnufO5AnJl8aj3Wg+AR5aZjwcLZ8vWny1Py7IqxH5mxGrL3Q1bzG8hAjXhsQbIGHYraK4bkO+fquDrcXcFQOzL0NrQ57MKsSo4EKA2zXv5udh+mbUhbsrUU7U8tUuAxLO6xrMGVN/MFBmZZNm9+1ClX+t8Evfx/97QsSqSyhi9jlcVuW45WoRcWzjErwYfpfhOd66re/mCtWSTlGdh8blWH8qUfByIfZPzuJkzSZiS9VWQ0oq+dSL7hw== 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)(83380400001)(2906002)(8936002)(6506007)(8676002)(26005)(1076003)(107886003)(2616005)(316002)(110136005)(122000001)(54906003)(5660300002)(38100700002)(86362001)(38070700005)(66946007)(186003)(44832011)(36756003)(66446008)(4326008)(64756008)(66476007)(76116006)(91956017)(6512007)(66556008)(71200400001)(6486002)(508600001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?3seUGljoppGcpYEijANYw2v?= =?iso-8859-1?q?j8FXUQ5C0t6ZIk2i+mgXVzEos+i4NPStMUGktwUFnM23QRWcvzZQ8wsmFJmT?= =?iso-8859-1?q?IcNa4tDrbS/qGAG5JY+S+JSqsK4sJ00WBZmhg/Qg4g2cC4rHKgKzHwUrp11b?= =?iso-8859-1?q?m37IHRyOzsKyksqIMoJuGZlrwhs9PIcCs6x08FwnsW94IHDkt3WMLHPVQE8y?= =?iso-8859-1?q?o3H29vTxlwtz9xvkVR9nju3v4AeHik1uDB0DUxPc2r2GdeFOyBhlBaIfebaG?= =?iso-8859-1?q?8xa2KwToUZu295POoPc+bMsLvL91OmpPu7jbH2ubOAnqSqNGJiDA8/SmPFLi?= =?iso-8859-1?q?leGjfrcmLw8JI6BygsmdiQI9ubiU6Q/LOsGL53R8/zvQIdnc8sYwK+KfkOds?= =?iso-8859-1?q?5dY/hYiBA6JhnWl+Ol5N4kykeZyf4kmSClLkvjM1fUDF+bADCrvsE6PpdT91?= =?iso-8859-1?q?x/RXrSy1Jiy/6hx3Giwk+fGD9Gfmn8SR0tBaf3oF5e5A7wmVLrYFkM+fXBOj?= =?iso-8859-1?q?M7I0HyMh8JRZ1SuOiYyCfufGhj59xlNuL4mW5UXqCW2R9FATjZ1JcTxkwBFQ?= =?iso-8859-1?q?oKiFGqdQMEmfiyuS9720QxUZRfakPUXtViFQLPEEdyo2n525f+qbs6BEsZy/?= =?iso-8859-1?q?EJvVC2xMsB9QjmWrlP3e0LEAN+4DStVfid8hyuR1m6TIaFzWGKkIyVoex4vQ?= =?iso-8859-1?q?NJiTThmmNqwVTN6hlRMs2ssVfZg2Njj5Xtzfp4RNb9151jVTDV4WerE+VbNx?= =?iso-8859-1?q?gIGL5oaEHGrjApxdrmMrLeH0bxDsHUdRxP+N8N5djFxNHBoPq5zUEnuD2+Yq?= =?iso-8859-1?q?wDuWdq7NKhULPg8X9RoZJmeFecCCY+5DaN6zHNVyVtYPRY4lYP6od3cVMwGp?= =?iso-8859-1?q?LU7PGC7ejCFK7F5C/pN5hgigQEzDwpFJspxl0cxt/cJJMJzz6uDhTPyovdYG?= =?iso-8859-1?q?QRWbmzNVxIuFfHP6Ritj/Q9BzSL2LngRT3jvVDIwLUYZMf2TmaCFViLg6loN?= =?iso-8859-1?q?IMBbhXuoyEzCFJshJNHCcWk/7nB11qQUIWDnzuNuUyZsI8rUp9ny79maXyCE?= =?iso-8859-1?q?RuuFFQFOgPOZpVRNEYKZpbjOPOkRDO2MM/jTQlP6zN3qJHqXcG68BVHbZGSQ?= =?iso-8859-1?q?ftj0flL+T2HdynYoosxFPB+Sio5F7tDdTgN37SZwWcLUpBwIpAqft6tKwHKz?= =?iso-8859-1?q?2nCiA0dOrd+fz6E+JS5Y5VSasdAWzYakTz6+JQ5pqVkw7xMmVU7ziexQ2kbq?= =?iso-8859-1?q?ub8M2vkOIUBJHbdXKWM10fYde6YK/bXW9MXayYzxShs8G0wIasM4O0WjW1RR?= =?iso-8859-1?q?ZfM9l2K+ialL2fn9oTziv78cbCpxdZulG0kPeJ7155q4UqWl2nUjMrd2x1hm?= =?iso-8859-1?q?IiZyL7aLYdILRRtc5X9h5tacRSxQPQxNWAX05NheWEPuEPMmzvlSohzfRQfJ?= =?iso-8859-1?q?ubj6fmCvxcpQGcyDPhcVEgLSWM22obzTWEcq4gEo4CWiykhQv5uq2X3c9kur?= =?iso-8859-1?q?p5YU/l6DPQFPlUyGEdk0xZqz0bf7Jy8UkFSsz4r2giXZmesmXW7yJAeja17c?= =?iso-8859-1?q?f2doIuY1O7ByTNGfNvnspGQSc9w/UEi6Ih0yx2r5T2AYy7f431CsXPKmDcWH?= =?iso-8859-1?q?KmIOGvQsgLToRP/WnqnEh4V2A/Tt3HnUxLNw/+GDkiQrRNEbzDiBcJoNtwXN?= =?iso-8859-1?q?dXQFW+zrP/DCmqto2R3ay5863tatg8lpT6T3Ift5tdy2ckm/pHh8sblpEBOv?= =?iso-8859-1?q?lXHw=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: da4bfda7-fcec-4a23-bbbc-08d9c01a69fe X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2021 22:29:52.8565 (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: IyO1p+lM9KGaIrAactav0kyJEfjRfKCKM3OAi6Au4QedklyDu7W8YJLh3r5wG/dplnWc8nG3gl896Q+BdZllzocKAe1O69C4NT1bFfOAIVI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB5457 X-Proofpoint-GUID: 3YuagzchPUe1_2DxoQVc6aCVXex2Cf7L X-Proofpoint-ORIG-GUID: 3YuagzchPUe1_2DxoQVc6aCVXex2Cf7L 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=2021-12-15_13,2021-12-14_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.155.12; envelope-from=raphael.norwitz@nutanix.com; helo=mx0b-002c1b01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, 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 80ef335254..714cc7e08b 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 Wed Dec 15 22:29:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12679649 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 6321EC433EF for ; Wed, 15 Dec 2021 22:34:51 +0000 (UTC) Received: from localhost ([::1]:36198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxcrK-00029t-BR for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 17:34:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmc-0003FN-WE for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:59 -0500 Received: from mx0b-002c1b01.pphosted.com ([148.163.155.12]:51928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmb-0006IA-Eh for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:29:58 -0500 Received: from pps.filterd (m0127842.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BFIIB8f015985; Wed, 15 Dec 2021 14:29:56 -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=DRnTi+hD3E/W+a5jt/ix5aSP1scxtVGeQfv7uJYY7P4=; b=jhKsAC9P1WA5xs8Vpc6dRGJSy3ohfmhhDnlKvchpULy6E54rxcFFUar0WAdQ3CWHm0Z1 8TrS6MfI+MGPyjZ4ghg/qJk9jhS+/OdcHZYgGDm5aEVys7db6rrkV7uxf17pdvnWI1hb Z45WdyrzF0q2qgTD5+6JGm686kScr1Flj+0yym3plSXrkf1J00/sbidapXe3NBzRv8cC tzQrw33bT4MACEaqqSjEFXshIjDyofsqyrlwfXiRlvXPwWkvuWKres9iOyxLT8/cK5/9 I/4D3slTqgJid6z6RcTCHE4Wlvz2fec8ez82DFQO11pflZof8EeHjk1PnmCnC/PVP6jx YQ== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3cxyjak44x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Dec 2021 14:29:55 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ylfl9Pr8G59XJ9tOcb63+sPcKs9LNZ+djnYsL2rgM7KsI6CS9ubluQ6n00TXBCOOdnLlAV8O6Is+EZsiWYo4Zn4BsfyCedo/VxrKeIKvSZYyz1eaexj2XYAxoX4EYYCBYIzSGFQsDMyMBOv4aeu0lrpbB2LN6A7XNigWDnE/Vd0Inymc0TdYyNeyMUs+DZaz2qv2jQr669d7i5L/r6LswQcAeMs1AkOFt3tOhQUOjpkcTj014IiGEu55XxCNesMUEiuIBQLaA8cQxiE3pSm3TuLqOVZzblwEXXpILvLEMH4gVWU992BEYWRiVh5axl8wlwwQt++TSdGfQE0/VBRR9Q== 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=DRnTi+hD3E/W+a5jt/ix5aSP1scxtVGeQfv7uJYY7P4=; b=PojVSibEdcnbKz1ebBjnAl6VhXPiMVljwh7lou6SY+XDCQm4+FmpJ63D7xAwSs2XB7k1Rv5RXhHC8eHXVzUMFG+VLO2JwLESxwsB61wpkLSAWOmJ1VqozTv1GnBrQIFI7rORcvbT6z646nnX7pdx/5sflwds/VkWMe6GY7V+nV/ssEii6H0CnWr3jzqDMdiHRPR3dTq1Wggbky/ROOuveYc0QiVacQS21PWX5gjo6Io1EoCbBYN4u1gDd10QWTGyFN5brqf3Osr2tyOW5wqpb4G1chHdvqxLBkzTuhltAVEHxGTi3jSvG1Mr1VJIJ+p3sh6ZSaRrMQKQkYWUI5T9jw== 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 BL0PR02MB5457.namprd02.prod.outlook.com (2603:10b6:208:87::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Wed, 15 Dec 2021 22:29:54 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af%8]) with mapi id 15.20.4778.016; Wed, 15 Dec 2021 22:29:54 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [RFC 4/5] libvhost-user: prevent over-running max RAM slots Thread-Topic: [RFC 4/5] libvhost-user: prevent over-running max RAM slots Thread-Index: AQHX8gNI53k9Bg5QmEieESPv2JrCRw== Date: Wed, 15 Dec 2021 22:29:54 +0000 Message-ID: <20211215222939.24738-5-raphael.norwitz@nutanix.com> References: <20211215222939.24738-1-raphael.norwitz@nutanix.com> In-Reply-To: <20211215222939.24738-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: 85e522b5-dd2e-4b4c-a455-08d9c01a6af8 x-ms-traffictypediagnostic: BL0PR02MB5457: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: 8kgYyxImiaYVa1wVEMWCWn3J6HY42bxW00m0Y+6KiH2lwTbQO1dCEJNkAFTGY/kkbAQp3iBZAD57HU38rIXlBWbQVTJqTbn3WUTDv14WGe+5jxn55gOrvzNIlrtNrJidrI/qfL0okapeK4sHkr5NjemotrJvGmATcddpG8Il28/W7gpVyiHmHMFPcrluSTckE0VtEW/5+ztgJ836TKLXzy3gU1mIMJ5EQbP/Pizf+kaNP368RsBI7SNo/W8Q17tVT3G1ett9DJVMMWlvS1TISFgjySQoctMYVeKPnEX4EmZx8GdK8Op/QXSKihaYNvArCnDIj4tYiR3RUtiA27jLgu9GqyqwQpP/ZtvbBjrW55ifqJhrsZq3sjoFLAx7Wq3FH7vPPIaf69Vsxo2mjDLnLjuzPGJi3SrWzd/A9zF9Njqsf37Hxz0sZUcFhcIyQE2rb8ZY/QTm+ijlPFErHBLqPjoIHgUpv4eIUQdIBa4PfYOu53A7CoEZkEyxzvqh1TP3E9gKREaI9t/qXCGtLL7lgBGWYzFJK1+wqlRd/2kyPINFa1LvxuCvHERSfPTKsKFiJE4lRyftCGvoM+70ZTOTqu+48m+YxfGLQKl/HiQLsjdcRSr/2wb309GiU7NktxX91//2V6nceRXAOjOUI+vfg1tfAIYaBLs0NGzq/+LPS3xb7DIcFMNbQ+28ZkXzlvjvJZgvCvganDCXUHblzQvPzA== 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)(83380400001)(2906002)(8936002)(6506007)(8676002)(26005)(1076003)(107886003)(2616005)(316002)(110136005)(122000001)(54906003)(5660300002)(38100700002)(86362001)(38070700005)(66946007)(186003)(44832011)(36756003)(66446008)(4326008)(64756008)(66476007)(76116006)(91956017)(6512007)(66556008)(71200400001)(6486002)(508600001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?96zjDwAxBnfc+miFQoHUs8q?= =?iso-8859-1?q?W+9BZ1ZhWUJj323UObmRwf1FZtPvKGhugdMx7jfrBv56aduQ6H5HxWXrFcg/?= =?iso-8859-1?q?Kq0iolllKl0gI3v8BT/JBWFJlbm0SJXxli7x1KByCp2iQjjyli5VM8pQFagr?= =?iso-8859-1?q?AadZhQNaPwa0BAk2H2ZuCy/wMTdfUvfVHYkBTx+4Y+OalechaIdu2NO9UkqZ?= =?iso-8859-1?q?1k09a7+lmUeRhK3lCfz14NRXHmOkWY9aP8pH1csaZqKIeGLI6vT4ejV9/Z2g?= =?iso-8859-1?q?vAVrkE2+d5qHKw8eBPSoVgImqiaz+549qECDctpUD+Kp9Y+8ufXMzfbiJlAg?= =?iso-8859-1?q?5az3SMrVRM+n34aKHF2xQEPj56TCPND/v9M+PYTCS3FkFkc5S93zgV0VAdMc?= =?iso-8859-1?q?pttlPSNC/ZoYNawPRJfZW7gKzfi0fa64YbPKgU4a3YwroAaRGhAeUTsorP+2?= =?iso-8859-1?q?5HJrygunnMDCKG3jf/112K8yJGDCc4eqATruW/LgjCr1FAzEXFr9NfqZ+YmA?= =?iso-8859-1?q?O3LjB+P+jD27rsO7J7mWxHE85rbfQZqYV8EBTTo9aWkSNZ9/c1IPS+7VKAbj?= =?iso-8859-1?q?VRGknsgNyCneVyaUCBM3lDIk+9yB83zGFyLSAxSUUD4yGCE64HJWtFjnUZ19?= =?iso-8859-1?q?H1EoACZfjv+croz+C1ojyvbkNAydbcJRS5Qxhydqdk5lb8Hu0DIa0pF8A03o?= =?iso-8859-1?q?6n7S3uAsk9dV4STY5Q7WB5GIjRAeJRuOuzGAeFGa+7jn6aV4/d1XhAzCqvXp?= =?iso-8859-1?q?zwVY+tM+tEUy0F0YNSUusEnJGiSQ/JGo/ZXishFBv99eFS4neoBPBkq67qlY?= =?iso-8859-1?q?X0o/miBxfCXhtlWpXUfujG3K54n9Bnat+DQqds0jU+Prz9PRbVpUr599HUHE?= =?iso-8859-1?q?uzDliDMUIpHy9iehlhzMzS1xP4zURBi/iPjIpMqOHTDptZTkLE41ZomGrWsG?= =?iso-8859-1?q?+YdjEcpHV0RXzlrgNUTI8iqb/AND2Y6d0er8H8SzUsotYQRgBruc3+/U6/5B?= =?iso-8859-1?q?e8m/iQIqN0CnYuOOL4r8FzNQ68lmo+Krk6RZPHn5MifhBXLdRE8/25V1jdXQ?= =?iso-8859-1?q?MOYprcE4KubDIc/uDl5i35eDxQb/oMvHJebCRIZU9YN265Bu/iUwunsc7/CE?= =?iso-8859-1?q?Ea6HIyr+LBKtMsft3aSCEKmBXZuVXCxvD6VhhBrs/RXX+oygKLq41inRTcqJ?= =?iso-8859-1?q?0tnmfIrl1NHQUX5yoi08N15ifiDj+Z6KeKbsWCfI4AQ14G5BqnT34KytaE96?= =?iso-8859-1?q?m620Fa40PpLzVo4F1j+F3dhC0F9NBOviyAXzUlwjJh1ejASDLYjAAh04e+GN?= =?iso-8859-1?q?7XjMUYwbJKdMRWWTXNFyKUz8McBx6e+pSgRXS+peUjK2/JwwEtpNkRX7uqWJ?= =?iso-8859-1?q?iLh2ykJFQsoKDLBVLJET9YErqWTEWz6JOAh4/53NfBtFjJXtn25lrjoDsmON?= =?iso-8859-1?q?RL+yUpdEq3uurqJkEU8KEEv17BhxYLO6sJInH3myHxp2YvbYkaAMMZSOKMph?= =?iso-8859-1?q?65IH1fq3rEVNpgBpKDbpT8T29ju8zd1v3pf9w2crwcLTfpPiU+GfH49hTKon?= =?iso-8859-1?q?2q0F4FyOAEqamzhyvQrGWM+t5m+MkYH9Dn/dY5Gyz/5YNkqYT6J6/kv/83No?= =?iso-8859-1?q?4Z7+3xZ9N2aesURF8OZynMjKJgQAzBpX1c684xKVydomwVLLnQK4JKsIwcLp?= =?iso-8859-1?q?fpkUBa/dY0wgd6dy0XLucFeiPgYRX08rI4TxQ8BB2kG+m3pEn4XO0jgpdNsE?= =?iso-8859-1?q?D7aA=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: 85e522b5-dd2e-4b4c-a455-08d9c01a6af8 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2021 22:29:54.4694 (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: 2Zqxzs5cLlNQQKAYrIxq6v0b1s2xaYjMOZSyrdpcoDJgY2Pw6QZO1ZAX8aQejkInO/I/rPSa0BZnq308LW/AyoiUrzZRQfWXgX3bqcLo7As= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB5457 X-Proofpoint-GUID: T1N_RgN1rAqBeDWigQUrj14CHv0NE1uP X-Proofpoint-ORIG-GUID: T1N_RgN1rAqBeDWigQUrj14CHv0NE1uP 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=2021-12-15_13,2021-12-14_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.155.12; envelope-from=raphael.norwitz@nutanix.com; helo=mx0b-002c1b01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, 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 --- 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 714cc7e08b..74a9980194 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 true; + } + if (vmsg->fd_num != 1 || vmsg->size != sizeof(vmsg->payload.memreg)) { vu_panic(dev, "VHOST_USER_REM_MEM_REG received multiple regions"); From patchwork Wed Dec 15 22:29:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12679647 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 5488CC433F5 for ; Wed, 15 Dec 2021 22:32:47 +0000 (UTC) Received: from localhost ([::1]:57996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxcpK-0006C1-ES for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 17:32:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmp-0003M2-Cw for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:30:11 -0500 Received: from mx0b-002c1b01.pphosted.com ([148.163.155.12]:11932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxcmc-0006Ie-JU for qemu-devel@nongnu.org; Wed, 15 Dec 2021 17:30:03 -0500 Received: from pps.filterd (m0127843.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BFGW9bX007586; Wed, 15 Dec 2021 14:29:57 -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=T65VD3UfjuYQXE+Opa0TFYmDscjGWwVbqXvUdg822Fc=; b=d6W2ylYCHMUkaBW77Ur/9CPmsjI4sKKm2Zw2uKj1R1K7v88lGBK6Ba+o5iYr2GTXwWet vlgx0L1IA0yRD9r5iDAhmjX78mpJdJiW+o1DNrNkDDOOJqy2Ae08ub9ic/xUW36cLIQU E64Wzg1ewZ7f203wf0lnwHHmInBJQDxasZbslxWOyhAr4wO7Il8Jfd+Nbyo1IhVU42Dc x7v3dXwdXJhiPdHAUL613SATOJDn6rtjNpysFNMaxLWaa+TUoO+tb1IAoEAzbdc03x/2 lauBxWd7b1W0AOSJrfwmAUqoJt6XhuOE7rXpry3RJJymBS6Atf8NZS7++7v9ChPw80Q1 wA== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3cxxfekbwk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Dec 2021 14:29:57 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kanRburXAy7jbcXWpzNyp36Q7EUk0iz2b5QQTDnTwZrBk82RwJXKb+hGtTYwGgARD4zlyoIYI0h5VC9Kt+feUJbTwjdYNZ3FRS4NwvDkVMKoubPMEIvUNf6lGMJXiRl55RKRyXRgVDm41epn3HGtfRLijPF0XplDjO+C9xj1gl5B9vZrRPY9DdnrDVNHHQ1upMrNlI8DI6btTilwTcg0mnKYpgbB/voX/PrWlZTJw2NH0HmrP+WOGTmPlw1RHZUUYpKeKsOPsWEiw9QUP/6s5SixPx2wpD7JA8/FbbpcpyI7iSqYoDb0HQxqDqtU+/Xh1kHmw6Ar3vH1kJo+JSl0wQ== 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=T65VD3UfjuYQXE+Opa0TFYmDscjGWwVbqXvUdg822Fc=; b=RdVv56PFiEWOAUucjKjMiPHHLQRlHfxQFrP8MhH21dBkcweznJVIyixBZGBGOX8CCJY4ZqJ7nR423NdeBl7f1ogCTlEqMgkft7ita927K+nlBsMiItYde42CT5ef5WNWwt28sqWsaOOivq3KGDZY1sE2vdHfJApYNAnDfciIE8Mmu400s5c9Ew9b8WENCUJQoajkY689+37JhIuNK/DCo0c9UIgLOLeqrYSf5ElAdk1N/DXyDmKSoz7hGkEhKaIYwSNnJ9q9dhI8ty0TO8luageK2z2lbRx0D4mKsMHn1gs1utkOekFMXrF8udjMdFzmRYgBd2EEtuq5RJvBX8pj8w== 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 BL0PR02MB5457.namprd02.prod.outlook.com (2603:10b6:208:87::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Wed, 15 Dec 2021 22:29:56 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::25f1:c1cf:5f90:35af%8]) with mapi id 15.20.4778.016; Wed, 15 Dec 2021 22:29:56 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [RFC 5/5] libvhost-user: handle removal of identical regions Thread-Topic: [RFC 5/5] libvhost-user: handle removal of identical regions Thread-Index: AQHX8gNJEQPpKFdBa0aQg0lnFIf3ow== Date: Wed, 15 Dec 2021 22:29:55 +0000 Message-ID: <20211215222939.24738-6-raphael.norwitz@nutanix.com> References: <20211215222939.24738-1-raphael.norwitz@nutanix.com> In-Reply-To: <20211215222939.24738-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: 6b0d60b8-66e3-40b0-f75b-08d9c01a6be3 x-ms-traffictypediagnostic: BL0PR02MB5457: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: aXJ2hdDtST1rR1kjvWtR7Jo27L7TvubUrMn72YWlJ9fTY1nk9upCrS7MGfB06yF2su/THbmv9UZC92uC4CIeSdBFTKP/TreTk9DeVkTKS9SD9H/UuxVvwTItNw66MQ5YqYGg5N7sOY5a8S179cUPf+qV9ABIoMPyfkxW/CfpvYIFY5Vz7uKJ/Ej1HVUufUpC64Ittk16JeOJip0BMfe/h8grK+V77mBRJxWCTHh2vZWSxrHuRQl6fat/U8k9nLz3ERibKYciDujHJKGvHseI8tJ4ERo0jMIoUxOYjHpegPafklL1WcYJsZKsNVJfDydTuZOPgaXAM3yEGfCojnoxE5m1fJ7X9YkD0fAkKH95InGe/XiLB5NYNGsPMbhkbzHFsnlIUE6zE6z6psPswhtNJmheXa1yVWQtnbjSiJ5k+iID8aYFUqkZHIOFErL3dubwE5g1FWRVGJuR9IdlywkTf+qVQxu8VvmVvPFkpaPvYvXIH+Auh0D6F6Yf3f8Sso8IvKqekAjEy+VUtkNhSopQrr/lStxqvvK7Ymmy4AiQ+H5f4q0PbSBn2ReAbmXw8AvJebdzD5/6ykx513UMWUFHLWgIW9wMc58M88DK64mJ7fMF4oLjzWDA16p1xGWPfowZFqa+KtjcfMsvzg4H+WquToNy3kW4cmP6EYci+xEnxrITWK6/gZnvodjsNJw/85muYSyym1pF+JXpuhUBJnovtg== 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)(83380400001)(2906002)(8936002)(6506007)(8676002)(26005)(1076003)(107886003)(2616005)(316002)(110136005)(122000001)(54906003)(5660300002)(38100700002)(86362001)(38070700005)(66946007)(186003)(44832011)(36756003)(66446008)(4326008)(64756008)(66476007)(76116006)(91956017)(6512007)(66556008)(71200400001)(6486002)(508600001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?NHvAiFxP1O7r6a7i7B3FooN?= =?iso-8859-1?q?PMwSWA21GFLEn2dMggx7TBjpyYajqC1LK/hu6tDGL04Mb1bWTn9N0m+4KAEs?= =?iso-8859-1?q?PpY1X+uJINy3uKiYJ5EPtloOAAXAppABU3MTWfU+tFK4Wnu11p9stbQimL3u?= =?iso-8859-1?q?1AowEwEvSzWIAsTe2jjn+BOjnMYZdX9OLyMLL8YcmN2VDQUH+F/nX0pAyjDL?= =?iso-8859-1?q?rfMTCdkQcxSPbga9kUpZOfEOi8AOv1dJCYK0cG/9xmYkBK2LtdGVjWcu1+yy?= =?iso-8859-1?q?+AN0Vg0/NHd8wM3bEGz9K9+HP97BISf9Rhm4w5U91iOO6hQ91vG7QBrqlz7N?= =?iso-8859-1?q?hJPb/XyBXSmfRDFZLDwVRMNWtgeiOeS6Q0CYb7oEbSf6yi7X8AEePpAmkLKs?= =?iso-8859-1?q?sFKwgQLg4WKCzqXGFeeuy6JSMWmxC+Znf0IEO8PCFvgC19F6vyPtniX3OAxA?= =?iso-8859-1?q?BH4muy3o6n3R+7wx3TvsL8SyYqGA6voM2Mc9ZHf69tW/9hvY9pXhiwRWouTC?= =?iso-8859-1?q?FGllNukXaqBaTuENKHBAr1o8hq5Q1vJnq392+C7KpmcWC3c2BToqOQPXqS5c?= =?iso-8859-1?q?pBCjJhKl73MvHKYNo7GIKHC/NuUhZMY5KvTwTXXbwd34XTkocfpRRlDCyDLB?= =?iso-8859-1?q?uU9z/gvytOtDENbdt/dm1sWZ/6BouB+6Tr9QVLQfpnTtqa0OPPwqCV9hxV6Q?= =?iso-8859-1?q?l0prhhp0sUo5lK+PudKWiyN6XQlPIeR02MMrSfEMUXZ9BgYlIjnL3Hey/R86?= =?iso-8859-1?q?jpn2MBraE89lF90GNVOu4WuGKN1cWrkMRyHD2BbVOwocbOwjoCywP87Y84j1?= =?iso-8859-1?q?KwCQwNsgE3jP4HngjC+iwZ3sCU2SXm4sEJrjgX3wFlRpiY6HLzyVHCmoaL7T?= =?iso-8859-1?q?30Oo1LtKDBSm3z1i5xh2gj2zMY5sA2dZ+bmTHnEDF007Lrvyil/co8tbJIeJ?= =?iso-8859-1?q?OUreG6zBr9qZ30/UVIfRKyy8GpLBpYY6fbamFDxoA8Q7WVqd6srtaXovisu/?= =?iso-8859-1?q?shGR8jRU14+uRZBBG8CUFxmmJkmDv6kViEiWnOw4hv1I4OBuIQ3TuSLFIhkG?= =?iso-8859-1?q?H0XO4x4DTTKh5PjaHhDZJR82yp6bDSGreD/Tbo8gfliIb5Y8Hm4zL6Kb/C42?= =?iso-8859-1?q?47jLw8UAteaWuqiOPu5mg+2iLoONx5FOuhued/zUPzMj2e4juWUks3z7hP2J?= =?iso-8859-1?q?vOoUYB7yjE76ADHP2HviKdVYsc8VaEskmqhtjMWqQm02yfxgrNUHxsdx2Cxp?= =?iso-8859-1?q?GrioKnvG4EMdJWsNuL45SQPrviMXsaOtVqouh68ww2YtDMAjsgvFWWUekJQ+?= =?iso-8859-1?q?DZVi7nSxpJu9c5pPAS13OHZB3OMn2NJZUS11djfQTW8W89wSO19ocgOHSLwj?= =?iso-8859-1?q?dzU7hQNCx04J7RtaVZwU1C4EkKdKEs/vsTmDqo1RODCYjN1Y0n3lu+0ET7yg?= =?iso-8859-1?q?VaZbH1XXz27ieks5k/dJJJe24kkXedWwnd8IpBXLTEC3qs55cZ5DodSwIBIN?= =?iso-8859-1?q?M66AFhSfA0kXvUBUjaK3n0xTU7SXVJ/0GEAoq1F+lilLQiax2g3V2VLp3TXp?= =?iso-8859-1?q?5EthYDvT6G0VwlPByFZDIMDfJQycyU03BScrCScCdoQMqUrdtWzc6kP0Pk1V?= =?iso-8859-1?q?xoL63j7DMD5F7Q+baFEJkk9RLhFw1nw8uGCWIddAkBWk7Oy+BLJt6+8iFazn?= =?iso-8859-1?q?SijM5+VabO0nGOMRfd9LXJ4fqYWlMrkK8dW/RhrFuPplnOdUzWfQTgDmStqt?= =?iso-8859-1?q?PuBE=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: 6b0d60b8-66e3-40b0-f75b-08d9c01a6be3 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2021 22:29:56.0285 (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: dx4u/BS+qt03vOJSNuYtEtHjdj8KTFgj24aRDm0bvFusmzDBfNRmU0DUB6Jp3lO9Y55Gyi4/sWj7Sniq19H+Z6SqO10pYf3OvAo4kmKYrpA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB5457 X-Proofpoint-GUID: IKZK1-cG_8KgWlEWiSi0WZ2eA-_48-g7 X-Proofpoint-ORIG-GUID: IKZK1-cG_8KgWlEWiSi0WZ2eA-_48-g7 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=2021-12-15_13,2021-12-14_01,2021-12-02_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.155.12; envelope-from=raphael.norwitz@nutanix.com; helo=mx0b-002c1b01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, 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 --- subprojects/libvhost-user/libvhost-user.c | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 74a9980194..2f465a4f0e 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)) { @@ -831,25 +832,25 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VuDevRegion *r = &dev->regions[i]; void *m = (void *) (uintptr_t) r->mmap_addr; - if (m) { + if (m && !found) { 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--; + + 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");