From patchwork Mon Jan 17 04:12:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12714748 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 F101AC433F5 for ; Mon, 17 Jan 2022 04:21:55 +0000 (UTC) Received: from localhost ([::1]:35962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JWl-0002fV-0X for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:21:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNh-0006eB-EL for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:33 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:9588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNf-0003MC-DE for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:32 -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 20GJKdlr007012; Sun, 16 Jan 2022 20:12:26 -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=PrPEqpkJrUxgZcmBNVlhHwOUKrXUdCP3grhsT1Ye6zw=; b=GqacF2OuOvJpXuJb2S5G/fxRMIkGOCCTKOzfCM1KALBdy4z82YwFqOvkgoNPYCQyq4vM NXV55V8pHDGwGDKI8zOdTlMQMLLj1Qd8YyCdzgGi4pSpskiaYYaTrPnkqBg9HP9xZDEs zaQFIgp245bFuihhQnL0px/ewVaYN3lEZeThADfQ9JuDQLwgeEiRs96sg4HPHOP/jWFA JCrmb7cZ08E/ywI0e9mYwtXiwOBV4sSSv+7hfvK4MpR9WkHTPdA/3hr+zsb2VN46sJ1u +jFStKRbfRNrDxWt4UVX0NgHCCBgdMo4Gh/5+/FOf0ujX5CdCCvVhs0/sQxX6agnPNV4 xA== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3dkufw2heu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:26 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iDv8RtD+8GIN/QOZXeGSmDuTv75uE1Dj3iFG6fVNduVgchDVk7LwJk/xNVGCSK314NOS0nf2cV73BaTrGMuiWPH9gOFT2HqQokkqsmaBM5FUpL6oTNQXkGRsPviZ+8lvrQMtJGwMyun/qw/0Le6W8SYi+7oBYfBo2l0H9c9p5vkb6RAcL+mWn2mIRHCXVMEhu6/QMFTQIM9PsDZWz/47ypLPjcUfISXMgUWixcvdgzrIeYRgaF1cjf3u5e81++fkOm4W0FP4maQhutROhp9CXmiESAX1wtpwOmzbcM3J6aUdJxJ3svkQo+O0hklWvfPHa7P63oeoWQIBIeh8MypIpg== 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=PrPEqpkJrUxgZcmBNVlhHwOUKrXUdCP3grhsT1Ye6zw=; b=XLAEiImGfAcn4KWNC5Kqk4RC4PERs6+jX5jYVWhqot7aSjrckspICoyWmyqp2Qj3YOlNmK51kp4NJvfKpzoySqwpPIYJpCSshRplWf6ITKBovezcZg6z8DLpxIkpGZdYNpjCDZ47Nix4FnXP9EUgs3n2hnIkdlApLL3MtgrIrQRPaezGBkUnyKbXbTSCJApIheyohmQbFVJeReJFZee3zVsIqD15aVSaf339skKZYdqkig3+nofASxS/ycOwsswfcf3qiHZVhASbOSQ1IOgGjPdfhQd7h68exqnjM+oYuOtekcfl1gXKZwkmuDPY0bwHQjwOyiAP+55o2oU1vUNzNg== 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 BL3PR02MB8018.namprd02.prod.outlook.com (2603:10b6:208:359::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 04:12:24 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75%5]) with mapi id 15.20.4888.013; Mon, 17 Jan 2022 04:12:24 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v3 1/6] libvhost-user: Add vu_rem_mem_reg input validation Thread-Topic: [PATCH v3 1/6] libvhost-user: Add vu_rem_mem_reg input validation Thread-Index: AQHYC1hui2c7rDhyxUuUIehSKkRCNQ== Date: Mon, 17 Jan 2022 04:12:24 +0000 Message-ID: <20220117041050.19718-2-raphael.norwitz@nutanix.com> References: <20220117041050.19718-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220117041050.19718-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: e6ec0696-5d86-460c-2aee-08d9d96f90f6 x-ms-traffictypediagnostic: BL3PR02MB8018:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: e04NlVeuHK9pwIf+dqFt1iu5ypl9Mn4fW8ydRv7Jt+bD/kSeczGfgyykGSIb9dpPrVzUr+upFwLxd++BhHNhRPsSKwoPHTHmTqvb6xt0gX+mSdGhoNTGEOAilGKEpf2T4yDH/sFtXB4IqC+Nlo4G4u2pEUUmjBzx6CVMbFX41/cBMYef4dMhNR87i85i7E+01l4/lPzeAK3vy7Dg8Fwt3l+4WmIil7+WMfBHxILhV/uKp3uaQ94UhRIIIeXqtmqZXW8g5cnsveHlas4cSpm3cM3sg631qz7zI0O5L59e+oeT1itKbzzHDUCRggOw0hvAjYcF5UL7ywBCz+MdCjNpQ5gskaqQOyxecz5G/80KkV87JNDpQaJhymnfgA0hz6L1uhpsRwJ+ZglnkjcUNu/xzU7nmEtQcFFHLtdxiYPhIaXlUcUuaAy5ZQhIaOwUn8RvlVEftX9IOOnxdmJb4t52Je9mY25uKz2mHbGGwOWqn4Spi8hFLjE0Bx5ck9la5L9KYkvfX6mBBoY3AeV5zhXlVnykYgsoZ7PA3l57ULOLRY3wNvXjLLr/AXAfImfx2EfwDIQ1ZhXu1T8iQ4aBDOenvVPQTc12Ewj7BBTC0p1PlsBrjNwNfvrrl/jDTOZweHDYlAjHK/D6qlmkkuja0PRfe7vV2Bnxcacm/ep8KGbDQwbmA9elw62XTIrXl6FZKErWtGjyJsKZh1cFz1aeexx8JQ== 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)(38100700002)(508600001)(66946007)(1076003)(316002)(71200400001)(64756008)(83380400001)(36756003)(8676002)(76116006)(66446008)(66556008)(6486002)(66476007)(86362001)(6506007)(8936002)(44832011)(2906002)(26005)(6512007)(5660300002)(4326008)(38070700005)(54906003)(122000001)(110136005)(186003)(2616005)(107886003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?W07qHd4OMSEHJYESVgCfkv3?= =?iso-8859-1?q?h5F+Tr9nLNSVmo7BTvZKaa1ZrLpwm4qR5O+3BaHr63EhB7g8pcVO14Htabjo?= =?iso-8859-1?q?wztBz1C9P3H+mOk2gE2WU0WRv6lNcfZcmagHIOmpgmavKBwFqPerTDyu4OL5?= =?iso-8859-1?q?0qIWtkvCuJedyGUJVsj+HiVniwvo+IIhJKR1uUAPmSAGxcPGEy3GJ8XuUGzh?= =?iso-8859-1?q?fLCDxgM8zPCrhUmdx2E9riQk/Q8mCWuEmIwoFzwMDmeNTB/1c14LW9ose9a8?= =?iso-8859-1?q?xbGuAoEViInu3IUdMke0+zjNscLI6ykrolWoh1PzUvzBTdoVxiIkBeyZ04iC?= =?iso-8859-1?q?aWk9QqdJoCh+6rvnKEqZwWjM6e8nv2hy/vzMO53AhSnaQkCPn7DykV/Fy3D2?= =?iso-8859-1?q?lloHTVdAt1kU/i/pW8GPmpoOh44Fd5EyhUJ7fMwkZ9lbzST4xLkOoPFNxzk1?= =?iso-8859-1?q?nnbDdgOYX6tTcBBYdjHCV7Za9O3k00GqkxBIlRReBwRQdxPan+gT7tmzpD53?= =?iso-8859-1?q?4CdRjBq8zQoPAthT3U1AeUJoiorArUOXBFLPQkCsqD6lEjyGGNAGSg3F+gpj?= =?iso-8859-1?q?CyHLCTKq2mP3SF2o0khU9eusDke9x5+7DIUWlcT3W0tNs8KGYp9SdW8VxO/s?= =?iso-8859-1?q?d94tB3pjfQ6/Wo0sBAXYNTuxx4SJam5tX6K1n4GpWLpnvNzW9Wkj7XsTlksx?= =?iso-8859-1?q?pGQOuFvDAgAfMQbB2ixw1epOvsqgMhO2gSf13TZOOTpGRYlIdczowDtm+ywY?= =?iso-8859-1?q?M94vUmfLzxNn2muRuggQHW83PSEk14rbXrhD02LN+jR19oIrETfSJ8zfNxap?= =?iso-8859-1?q?KuDSvHABUuDzqEmot0B4sXgWViyRJb9DwtOjTSYjNYdF+YOz2em00jBMWnu3?= =?iso-8859-1?q?HKHZ/xlICEC0XpFsxTSstBeRVBzPHi/NBmcc5Vt3Gep/nbTz4aKXGw/X1cxR?= =?iso-8859-1?q?0kVIjwcLV917i9rCdSTVThZSSF5ODTXEjz/5DwmvHCeuyeIhDoUHqtdLq3TH?= =?iso-8859-1?q?ht3JRBd3ZQC3OIJnDdj5Hv/AA02LZd+TqxPozx8bGPKSgCAVEVt20vcAzwUP?= =?iso-8859-1?q?+r69OPOQbotxMP9xLcASXeByw/mNmPLdmgvxNgfrBhqakGenRn69zyIV2GRx?= =?iso-8859-1?q?Daz1etk3YAioMQEuo4S5it3b/xxFBAGHRnv6b66zzIhBI0ffQZvMJOLQjY3w?= =?iso-8859-1?q?lZ5stEzEVfwXxqCHJ0QiqOx+IxxkYSEglA2hJDMuJIFNsFd98nGVmrlNVtMr?= =?iso-8859-1?q?S5lNBlk+69u+G0AzC2QvorqXW35Tktyo+zZAeiejBrM7EunW3GlgVxaLiN57?= =?iso-8859-1?q?d4z4MT/raE9gB5WkwMhQGcq/12gFiSG3r8DtnwGE3h+DwukHqHIHdPGHecsV?= =?iso-8859-1?q?Mb8VmFp8sqoMv7d0E2sPlgpVxHhEzTt1mXQyl4pCJ8pbq9gu13ad2RI7HJhd?= =?iso-8859-1?q?O66wgLfy7owDJj78eQUi1Hpg/Z8eJFSCJv97uiulV+Mv2HuoemidyEe9jc+o?= =?iso-8859-1?q?a/kmvMCsIqtOiys/bsHs2z4ZIUsT3kh7Cj6/fT105InwJlS6aPST2ul7KuCk?= =?iso-8859-1?q?n7suOyw8WOFh1CF5bYvABg6LI4M9OnqLnsjZUWoWIyToLzSYxm0tWr2BB5Ht?= =?iso-8859-1?q?UkaSN4aLjbLLOKVp4uZKEgE/O/IQggbWfqoW0ZekNHEP7i01d/lsNGqARbAZ?= =?iso-8859-1?q?DvaVWR/51XJ72raS+rYHCVZc2p1V+fl5mOQY6gwJRyEgNwCp+3rl13HgzZtp?= =?iso-8859-1?q?c42k=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: e6ec0696-5d86-460c-2aee-08d9d96f90f6 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:24.5972 (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: 3AJbkiiN7+RKkX2PhDKiZtLGD8YNBQ94C1isu095jo8OORk0qqQB/N/+SA1n4Tnl1DdqSBDGddVJiybjTUkOFhLb7YOhGTof3R1M0QzY3n0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-GUID: hdVziY2nT9hZ8HgZW9tAIDpR-Kt8Pt4G X-Proofpoint-ORIG-GUID: hdVziY2nT9hZ8HgZW9tAIDpR-Kt8Pt4G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_01,2022-01-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.7, 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 multiple FDs are sent from the VMM to the backend in a VHOST_USER_REM_MEM_REG message, one FD will be unmapped and the remaining FDs will be leaked. Therefore if multiple FDs are sent we report an error and fail the operation, closing all FDs in the message. Likewise in case the VMM sends a message with a size less than that of a memory region descriptor, we add a check to gracefully report an error and fail the operation rather than crashing. Signed-off-by: Raphael Norwitz Reviewed-by: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 15 +++++++++++++++ subprojects/libvhost-user/libvhost-user.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 787f4d2d4f..b09b1c269e 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -801,6 +801,21 @@ 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_close_fds(vmsg); + vu_panic(dev, "VHOST_USER_REM_MEM_REG received %d fds - only 1 fd " + "should be sent for this message type", vmsg->fd_num); + return false; + } + + if (vmsg->size < VHOST_USER_MEM_REG_SIZE) { + close(vmsg->fds[0]); + vu_panic(dev, "VHOST_USER_REM_MEM_REG requires a message size of at " + "least %d bytes and only %d bytes were received", + VHOST_USER_MEM_REG_SIZE, vmsg->size); + return false; + } + DPRINT("Removing region:\n"); DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", msg_region->guest_phys_addr); diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h index 3d13dfadde..cde9f07bb3 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -129,6 +129,8 @@ typedef struct VhostUserMemoryRegion { uint64_t mmap_offset; } VhostUserMemoryRegion; +#define VHOST_USER_MEM_REG_SIZE (sizeof(VhostUserMemoryRegion)) + typedef struct VhostUserMemory { uint32_t nregions; uint32_t padding; From patchwork Mon Jan 17 04:12:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12714744 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 31ABFC433F5 for ; Mon, 17 Jan 2022 04:17:33 +0000 (UTC) Received: from localhost ([::1]:55108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JSW-0004zo-7E for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:17:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNk-0006gO-Mn for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:37 -0500 Received: from mx0b-002c1b01.pphosted.com ([148.163.155.12]:12278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNh-0003MU-VC for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:35 -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 20GNl9Et029596; Sun, 16 Jan 2022 20:12:32 -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=44ZrRvmfbahsg+z/gNtfg7Ej5XPa8KWTStWXi8F7Qwo=; b=J8O5gy/kSKd1zwycuIjiNIBONLGx7yCQZ4DdjYrA6PQLDRUf44ppJeW926eu4r299pgs He5t05Rph+BzGGJYC7oupyXap8/p5481JezPXPb1HWgRp8Z7GPJMfFCOUYaxBUHUnG9x NCjorU5kr9ibr2P04SaCEjg7bf0UizF5FRfgJ8Fj6t5kArdO5mI4htvLBbLCNlknAaRj 30olSKRqxNV7vUSBEg458Ccwj5pn09tYgS8SW6H7gAZCmp8ulBRxrcKU/COPbB0U9qdW RIfTeD1+CCi0GvXu6wXuxOkSmvEaXtj4Nffrmj7Cs7SgKlNmcYOTd/GJmfrQMZFQzfad tA== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3dkxfjaate-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k1uPUd6vkJFCW8RCpm8SDODPhEH32BZFX2P3OMWLSLPClz+Zw8kWKXJ4l+Dt6pB6VyNtB0uCV0ctGeS3yHhvTCOol5tdYYpggZTcgyhPIMvtFnzHKc+0+wXyVa7pX4jzhk8eBY/kO/70l+U6ylf/mMQgCn4Ar48gbI4PESDWHsJRzAc94CK16Gm2jJysHhz3oQ2oDfpB90qLTGJ28AvI1d3cyFTtbYNMW+LOyLEIN+uzqrdRZn0+BDdtL+cMZ6iURbG+YQ15JokLKxxKVXJobBQPoKljW+Z7bjtDiMMCvtrzeXHqQ8mJQi3ESXvEZA1stVbz/5hV3e9IGu41+leRvQ== 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=44ZrRvmfbahsg+z/gNtfg7Ej5XPa8KWTStWXi8F7Qwo=; b=fqkLVCddqd1rV9h7VBMQ9w8inASBt2D+HbSTE7P4wB2DVMgsA5h93Stjt7umdYSCejpd4RfKU+rCzaJdR7AlSSe4qXr34l0xrCeBC/nrF1d2x3ulab8NPLrDj4+98rK1/BdfCfmXha5k1UoZr4x7HHWmdUxlL5786q/6fZ1EAxf5t6txzP6gbXbwhKrHGEab7o6PBncxMwRutvbFwKS1sPltvO3uO6BsKJhXwJIcn3fLeNZR4SvLq4FnGeT/eFx6pHnSYMDNqQtxmsV60+NHy5JDpXHw+qfO99qYgIbQUakUXYwzGnXrlhj9cwkdglfJPK2M/VcRRM4BLK09IfseVw== 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 BL3PR02MB8018.namprd02.prod.outlook.com (2603:10b6:208:359::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 04:12:31 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75%5]) with mapi id 15.20.4888.013; Mon, 17 Jan 2022 04:12:31 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v3 2/6] libvhost-user: Add vu_add_mem_reg input validation Thread-Topic: [PATCH v3 2/6] libvhost-user: Add vu_add_mem_reg input validation Thread-Index: AQHYC1hyG2brQEFqgkq/5jE3B/5vvQ== Date: Mon, 17 Jan 2022 04:12:31 +0000 Message-ID: <20220117041050.19718-3-raphael.norwitz@nutanix.com> References: <20220117041050.19718-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220117041050.19718-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: 7ba68f2a-a107-4c61-5843-08d9d96f9519 x-ms-traffictypediagnostic: BL3PR02MB8018:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AHQA6lyQ7kmoqoI8LtYEZh2zgdwXHJglUM6ph0zASVDJU/c1S5bUQ3Sw+feywj9Um2YhC7Y57z4L5CzeAQJJf1U9lCX3F3GS8Gf9UuRm36uk/GszIHZ/hE5SMvLkmQ9L3EMD71sASjpDeedbxTvASIy546KHJYlTAsD4WoOKUF0Bi06d3NKFeXDoGtRtP/QVdHD72sWGG3kSpbxJP88ARoEhGceNcY2NzH4FR7v/OoGEixnW7tHauZ3lIpsw6DlRcInkP7HDRJ6jB8ywfedhUyyl80BIR6ZI0AsK98jYTSwnLjawZLdCkH8zoxRB6uYrZB3jLcLn6FfXDxb/uc1KDJm2x24pTVy/xS87rn0mksK3TLqL9xKw5QFnGdP0oM2Y6F89tjNrms66Y5Oj1h+ZHToqmWbwpRvcgJY2xnOK11NF/74tveQLdhhzbDcIMTHRAaiuD2XaI2DLMIeje168BKdqvClxGkGEhB5DtbS1PYZIMvN1k1HpE07Hv7m4yEqb7rmDwp24EwoL/VzMofy1mCfMKEeiY7frIxV2BCnlLtyIJ9CZj8gsQJdo2h+3LE5dWNNFAIYed8X6GbrqWqRYihp/UmAzoPq3Tq5qsk9rgYO32kCDsmnfSCxQyC0LhbyjeG+VyiGIMD1sEccrtL0loCc4temm4IHg8S33kpEB7a426cRjY39vo9Jaow4X5xVU5gRfDnKeuAgcGnqI8k95PQ== 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)(38100700002)(508600001)(66946007)(1076003)(316002)(71200400001)(64756008)(83380400001)(36756003)(8676002)(76116006)(66446008)(66556008)(6486002)(66476007)(86362001)(6506007)(8936002)(44832011)(2906002)(26005)(6512007)(5660300002)(4326008)(38070700005)(54906003)(122000001)(110136005)(186003)(2616005)(107886003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0jPQQO6ZAPMAkjVbBNZuJPJ?= =?iso-8859-1?q?5yu0L+2OnQBhhVqrrDyFemua/2MrxEVcC8yYifjyo3OoIEPOrYiQYqCBxv+f?= =?iso-8859-1?q?diEQHKMAKaw355/oOlTEfeEzvj+G8TrjDsB7KTIhgbOAQNfR3CUcDNWdsWi1?= =?iso-8859-1?q?eHktZxbXl7WgB4uSNNYm84tgSLSnV1ZFyGeHs4EHuwBqoVAFIbFkroAZpY1U?= =?iso-8859-1?q?Blb84CANwZh9DqwOdQnmCKQe/Fxt9iFWyAEWGOHADbi7l1IZNrxGhRvAE0HP?= =?iso-8859-1?q?BqcPJmitAL24NDFGTYdUbVw2sdnMQBaJNl0af0U5Vre2PC1sFbPKokNPRRsE?= =?iso-8859-1?q?5Sra3zpBRlB8jh5VtcJJNfdhb7+q/c7HxRVB7/ZB0ZzrQZ2mMX0H5HQqoVCO?= =?iso-8859-1?q?Bv/KOBCFlhOQ1KNa15cMGF/2qYhNmuZBAn0bay6g8etyfC3lPD3eiFZQ8RLM?= =?iso-8859-1?q?oolOZqj6c9aMO5tq+py+WD1aCUvSL4NhOffx48MDEX8+P4MnNQ5uPQyw4GXA?= =?iso-8859-1?q?Dsf9gOVz8JZHNYzhkym4UQ+Q4OhilY2jtuMr3bqmoVObv+Gx3OSeAsyoXiKN?= =?iso-8859-1?q?jgty+TP3buDElOX+EWt9kq3lGLGBZJGaN0wqZoSoRM6HeuLXmLM9UY+5KPzg?= =?iso-8859-1?q?ZTvqEBpgFtOkVvV4tZIfMCA5773CSjsm6sF7TNvRa+n1PGd0SsBGhQNbl8eW?= =?iso-8859-1?q?lpuG4JL6+ivv4cKbmjkNNgNYL91GBPADV+oNEuXtp7RHYx+5sCx4NIDVhZaO?= =?iso-8859-1?q?8K9APerTUt5nTyCED1LP3a8nVnaW8FughsmraalsvwtYFo5pDkmKlnWLaKtD?= =?iso-8859-1?q?byHt3K9w7g4EnsAlM8dioIOsSTy2BKStRuhBVXLw1WFJQnku/w7kp0Jr0LAE?= =?iso-8859-1?q?rR9gVnOMey6egnv6XEWHVHRWNltO5gORJmh6wEGLWSspL9zT1BtRZUOa60ap?= =?iso-8859-1?q?XY0kINOMyGJlzTulb9qKCEwjmGEkRmTEG5OxMy6WRG7N0NIvXXdO5qgooixL?= =?iso-8859-1?q?QVBj4oCvBAGlSa7Bx6g24IMnN1NjLrg5HkZ5/S9FpPXKQGpqbQdrZg8IeyO9?= =?iso-8859-1?q?Pa3M5tOb7rW7lzhe0WeJeb9a9dGMWKNpKITChDDLRYUq2WJ0hWmEJXCL1wAL?= =?iso-8859-1?q?Gmcj8VT1PVDoJ1FKrjg+ZsWfc0mEGyt6Nut1oyNS3CnXrx85vR/xA2qx5IwR?= =?iso-8859-1?q?jM5MPOB8nrN5npsilBE+Gxr3X8cEBvj3/E89KpQDrL5qeY9aBjH/RboZHTme?= =?iso-8859-1?q?MdGec09odh/VyliFIPdXVA8PXzoyiE2U5l1dZFzAYjmmSmoGQ/ZGNHcy0cfb?= =?iso-8859-1?q?s45xg/+Ffj07jwF/rAluPTLn1OZpvevhqs8qBf9u54wpuXSG8QaH+F/jHBGm?= =?iso-8859-1?q?beiOhZ5dF86SaTf8MT6EEBKYylisIdcCHuTx2XELAvBMjdsfekWjKlpHMLqZ?= =?iso-8859-1?q?xhGVHoqkgtyquDhUc21VXmK8aDh5lmnqM6KPc5gljAaulZ+jHoZFDdRpwQCb?= =?iso-8859-1?q?MWs3o+te6xg6+cx74xDd+XgDe6F43WA4nCAOVug0jth3XK/QuOQvzetzVef5?= =?iso-8859-1?q?Fh+MnBsGiggY/+BkDekG2NXtN/bphI+K4vBJdnMD/jYH3gZhx6Sjud3tm8ey?= =?iso-8859-1?q?DFugDpkOgyCxsTMApNsiZvO5H+Ra/R5aCPwbKABMgqTTR5YJQ7uvyUxlDHyS?= =?iso-8859-1?q?zqrmY4b5WeiCbd5djOSXRtnDx7X2XHq5ciQ9O0DQbzkZX9ZEzrSkFCWRxqkW?= =?iso-8859-1?q?89Aw=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: 7ba68f2a-a107-4c61-5843-08d9d96f9519 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:31.4905 (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: 0L/QL38zNFDb116IJfA8NCpzF89Fiwu0d4w3cBGf0Cy6HXKIVzePYPFzljiKVgJsLo4Z1IRGGnzZGRjb7N3Bro0BW/mOS/N0KLp85SjkNUs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-GUID: 5dfyRWRZQOAF5GMYXIADfxvGsBApSwe8 X-Proofpoint-ORIG-GUID: 5dfyRWRZQOAF5GMYXIADfxvGsBApSwe8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_01,2022-01-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.7, 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 multiple FDs are sent from the VMM to the backend in a VHOST_USER_ADD_MEM_REG message, one FD will be mapped and the remaining FDs will be leaked. Therefore if multiple FDs are sent we report an error and fail the operation, closing all FDs in the message. Likewise in case the VMM sends a message with a size less than that of a memory region descriptor, we add a check to gracefully report an error and fail the operation rather than crashing. Signed-off-by: Raphael Norwitz Reviewed-by: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index b09b1c269e..1a8fc9d600 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -690,6 +690,21 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VuDevRegion *dev_region = &dev->regions[dev->nregions]; void *mmap_addr; + if (vmsg->fd_num != 1) { + vmsg_close_fds(vmsg); + vu_panic(dev, "VHOST_USER_ADD_MEM_REG received %d fds - only 1 fd " + "should be sent for this message type", vmsg->fd_num); + return false; + } + + if (vmsg->size < VHOST_USER_MEM_REG_SIZE) { + close(vmsg->fds[0]); + vu_panic(dev, "VHOST_USER_ADD_MEM_REG requires a message size of at " + "least %d bytes and only %d bytes were received", + VHOST_USER_MEM_REG_SIZE, vmsg->size); + 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 Mon Jan 17 04:12: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: 12714741 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 CC494C433EF for ; Mon, 17 Jan 2022 04:14:33 +0000 (UTC) Received: from localhost ([::1]:48710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JPc-0000e2-H6 for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:14:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNk-0006gh-Q4 for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:37 -0500 Received: from mx0b-002c1b01.pphosted.com ([148.163.155.12]:26182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNi-0003Mf-MK for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:36 -0500 Received: from pps.filterd (m0127841.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20GNmbYE022754; Sun, 16 Jan 2022 20:12: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=xaHInSOS/q1CMpidgiagiNwsW+h503QSEfrAjl1YQfA=; b=QKeBE1f7vNiQGAOvmkvMn3JXuBGr0r0VognO6zk0zyeUoBMC+EW8eLD/PhZfvjJIrAaF laj2Q7MiDV3hf8hrMlZ8PQpoitYVUv0Wk10Ba2VQLr+YzNece3RMSXcn4wUbuMJpPzTH Nx1fzcvX0WoOtC6AwKiQHJFfloaKeJib+aHEA050N3ze/aEE0e3s7FHTjfzZqMhrQAlF /XBtxM8XvkspQ3pBZN3IfC+fga4UCNkzjzDoMzKhU2tlEwwRXCHNmVZ8ch1NFnueKN+2 Bd7Sg5Hd/1suMXcExXv9KqyvelhpgF13byOaGivtIvrFipggwq0OEUeet7eI2KJxkvLl fA== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by mx0b-002c1b01.pphosted.com (PPS) with ESMTPS id 3dkvpbaewj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:33 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ais9IBrJ1qq1JQlVPL6WFwmVzmt6jzjyk73Jem7Fa1DSh+mr3/kC7O23SreSbHzOMWucn8czTxVBugan2HGeObFBfAodAP9PwprYrR97xkIzHhmIbqAww09Z6I9qQ8caJVIsqjNouRyXNkTENRhGXTUm2aUVQ5chS/XHYDaYbQvPi3bXmeeB/3mgAPTKD300uYWkadcYeSYV+Rb039ffnUNXsk5JsntzyavACmbsX1T4PtkUDf2bHWXTuBpezjWmRkD/eu0JcVLZdg+8Ldc+LfsymiCWkTLY9e4ImefgT8Z7AonPtOsUzbcFhjXQ2W2uktsuHKlMYp47k/sIG49G7w== 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=xaHInSOS/q1CMpidgiagiNwsW+h503QSEfrAjl1YQfA=; b=cs6RkfVZVG2vkF2DdDPGmJV1jOtc0zT6WPOrT2Zq/VN4aEdF3LI/y4AUbv+dcMN/7rA/ya7M6gMZNsW5VNxwj2qemhFeixPZjzhp3ZqNPxuz6cLr/mJUE21pD3thW55SSU/7xsoFTS3zXJQtSPWK9tvd/GgfXi3H73COVDQ4R29ZGp+hNxyc58BRxfdR8YUqEHYYQSJmdicp+xwIaWuWNwT0UB/g4COnehFURgHYBpftY2QlQ2m/j58s9hxOvsctVX29rxqPRqMlZTnIbSOK2rSctaUljDAyKJsdlPXuxKSONYpiKjGWLhA/j+39ZGixk6LvqYfqlaMzBiF6wKLnjw== 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 BL3PR02MB8018.namprd02.prod.outlook.com (2603:10b6:208:359::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 04:12:32 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75%5]) with mapi id 15.20.4888.013; Mon, 17 Jan 2022 04:12:32 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v3 3/6] libvhost-user: Simplify VHOST_USER_REM_MEM_REG Thread-Topic: [PATCH v3 3/6] libvhost-user: Simplify VHOST_USER_REM_MEM_REG Thread-Index: AQHYC1hzNWc6tFSMPEOov58tcXyXPw== Date: Mon, 17 Jan 2022 04:12:32 +0000 Message-ID: <20220117041050.19718-4-raphael.norwitz@nutanix.com> References: <20220117041050.19718-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220117041050.19718-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: f75b1840-699b-442d-f7ab-08d9d96f95c4 x-ms-traffictypediagnostic: BL3PR02MB8018: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: VjAhPR3Z5fYaIg6o9HWtusQ3FyiRezhCFyvQugaBluKT5ZfN4xOs7FUlxtL9EDyHDXPBaFrXMvRGMfGa2YWR/Lcoy7weef/JJRjhFYQJCeg60DCOvwMCjzPAADgMSK9+AYp023Dq4DbGavD86n0DwXUbFnb+IGD5gSLnB26He1Efa1iiIBAcC0xehI5BIkQd42qyT03bnxki5zHvm0hV3FzroTZ20IiEaMvfEImiP5dlZb8KyfXhtEkoEwr2w+kNx5rS/0Rp84ubMzRZ6NURIwO73T1GZ2/aj+q/mSBZKh8mnC7DWSg4x42sUorbNmdW/gExIQRJbEz/08UC71IFo8neb8l5ULEa4/DIe8TABMq8hYhv+txncJTa/YqeKYdMI345lACJyif+ertc/uxKGcrVgTUrb26XOadJqVVWop3ZhWzM4MU0cRat5Z0OTn5X7KII1eY6s0i/5KXQVlI+ehHCyJNLljTrhpM6lXllqQ9xPkOodJ6rxEJYK19fSzZJ4ij67YcD7YEOY9WP/NowQfJKdfh4zYcFk4ZS4+CJi1ldlu8VF+tAwTXMSze130pPhDjNAHBh0WG32L9Fb6t9L7FOYuQ8WyKMx5mr5TbXulv3buMe0t987x/IUPkvcUApRZQRLA8BH8j8w2AUPNcM+icr7955L2JikiPwABuQDohCIsMHOYF0TXXr6ydRS351RaxuEkF9K/WoMscyNbLMaA== 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)(38100700002)(508600001)(66946007)(1076003)(316002)(71200400001)(64756008)(83380400001)(36756003)(8676002)(76116006)(66446008)(66556008)(6486002)(66476007)(86362001)(6506007)(8936002)(44832011)(2906002)(26005)(6512007)(5660300002)(4326008)(38070700005)(54906003)(122000001)(110136005)(186003)(2616005)(107886003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?ydnIHdPFcaQE+mYk2Md0dxh?= =?iso-8859-1?q?VoBhvxEu06XBi9Pa8MskzXurs0qCemkHv95wOfX262wOaN9pOwl8WFe04xcd?= =?iso-8859-1?q?z/tm8iN7t47WEb2HBlHug81ByXhd03k0A5sWtH9KK+lXrAujuToXXdmq2Ub3?= =?iso-8859-1?q?MixuZj6ZzfoH6VVmbib3UhytO4l0khlskRbjMrMvtQNKt18eeGTtDk8YzU+8?= =?iso-8859-1?q?K6F1kNCg4wDSjQJnbaOw0a2KZ4icEyHrhpObrNqR/x9ju1BCTb3arA+ojq4k?= =?iso-8859-1?q?RE6eE9X5cLvzWzDO7dxQSk4soM0FoA1FPzheD0nG2p2A/dZb/f6mxI7eojYz?= =?iso-8859-1?q?QyyFQ5eE3qurDUwjR5UnK+R+xrbpemxbEDtfVhWwcdcPdZjiKhYZe0ERvAAk?= =?iso-8859-1?q?ESzyV6EumZ7F3aNcGEhsvCXdLYkctx6Rp0E/yiGsOEjhcywsVVAC246lFKOM?= =?iso-8859-1?q?cqqoEyO1nOd6VdV6BxORm9n0wUM3h2Nz4RPkyh67WDGMw4/NsS07u8UujrKq?= =?iso-8859-1?q?uyTkYLaEQTJwlWrmnHj2nmCTEeAHFUXezflmZ2MKtN9zRIeWeCe73h8kDcXC?= =?iso-8859-1?q?Nrq4lguLYlCmIBde7XDwYcyQoJjcGF49mgiklcsDsGa5QmvpBMCHrBWJNtXh?= =?iso-8859-1?q?flZXaYiarq+LBPKjrybVmd2cVX4qn/FNwaheuvqNkJVOTjKA6yyjFY9eVLck?= =?iso-8859-1?q?D53tJ1k3+kNDxAxv9j2vZIYv1S4EYGzUgxR0VXZltmmaNOGo/OVZOcuvfeHy?= =?iso-8859-1?q?NDMkKgQC5JkUEg/TAmAVklrOG3IE4nyXPaj7G/vGuz297cvBQIZL9QR8r60f?= =?iso-8859-1?q?LLNR7U8pnR6OpORnXrGVwGB0fuD+T5nAwAJWwsOA73WUOD01DUG0SavA2PVM?= =?iso-8859-1?q?4qovaFe6Bg0aO5DVaObjpxZoLVHIK/6HMy8tiegEyaKZMnrAkJHgv46i20CE?= =?iso-8859-1?q?scKmh+VwHXjerf4d/XbR8gufHpo1PJgt/ZvWrtoToBg/+CNO6bUSX31tYEIU?= =?iso-8859-1?q?ErfI7/ZnbDo5MD+mE+mk3rGArjxiWjqOGFfhZLpe3qktlSF0TyHrP9PbpfhU?= =?iso-8859-1?q?Qu4BqaWemlDAdlZwti3MAUvN5BpCZk8gEUOXZKlTX/IBcKJ8LbSrl5a8gsAs?= =?iso-8859-1?q?bqI7lNZE+2cV2IF7bcz6dYn3+eFYQwleGZANulD0bJVPm0E9fqSOP2KzNZba?= =?iso-8859-1?q?vIEo/oZ+hZYSHENiFOhuUTJducb2XFGj3TkRkta0m5nB5eCl0xFChnN94CKJ?= =?iso-8859-1?q?RLQA4TaOLlfWX0FP1j0u953b0HA/ymt24SI9mCe4MNY8FGo3m5ytPNxFYKrR?= =?iso-8859-1?q?Rp/6RA09uhKVdK2P3lMAnIONe7BemvBml9u8c4UXnNXZlxAPBZ+/FX4vDGsn?= =?iso-8859-1?q?LyppPRVyeHuBSNNv6jINjnh+U8L4fqbgLw+kzYHPLV7NGy+IctyUCRRz2pMF?= =?iso-8859-1?q?IzuAk0taZKDr3/V0bpQA0yXskU+upnBF0jMRaI4gVzIalv3Pn2Bf6cyKItF8?= =?iso-8859-1?q?yz87z/FaATOBeWO4CQ/vu3qXX/d9cvLLrzSBlV2+VLIQjds7eZkGYyzYewvq?= =?iso-8859-1?q?kiLphbToclZd/IxxwIhu/CFxKLm0Fvvpa+oiBrJlMYtvkgjFz/5dnFbPVlKD?= =?iso-8859-1?q?2QUw4n5pYpOZVxSm60xrNfU2iZda7W0fqaSKjPI24n70yhSBD5HFuu8Uy2gb?= =?iso-8859-1?q?Iqmivp/eOvKJjjNcJxJE3MmNF/0mB+5eNNOFTPX9SB8AThCTdY2TRsl+TA1C?= =?iso-8859-1?q?jf98=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: f75b1840-699b-442d-f7ab-08d9d96f95c4 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:32.6634 (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: lXx6Ev6DKXfBO7faJOZapcdDabraKucw4lDQLWV50vX3bWUWF6J0YXvUi9eKDcwMVwJ5Uz000lJAp00q+Ucpt/alJ8k5zZIgVH37i8nHP0I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-ORIG-GUID: a3A4DmqyXo7wXNX2MNIqEHN1mxBS7YzD X-Proofpoint-GUID: a3A4DmqyXo7wXNX2MNIqEHN1mxBS7YzD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_01,2022-01-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.7, 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. Reviewed-by: Stefan Hajnoczi Signed-off-by: David Hildenbrand Signed-off-by: Raphael Norwitz --- 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 1a8fc9d600..7dd8e918b4 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -811,10 +811,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_close_fds(vmsg); @@ -841,28 +839,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 Mon Jan 17 04:12:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12714746 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 73CC2C433F5 for ; Mon, 17 Jan 2022 04:19:06 +0000 (UTC) Received: from localhost ([::1]:58924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JU1-0007YW-BA for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:19:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNo-0006lX-Ld for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:40 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:8520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNl-0003Mt-OB for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:40 -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 20H3I4GS011096; Sun, 16 Jan 2022 20:12: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-id : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=ntUOdEHzsaOY78kdSbKxbEuBjHHqoZPjDrvgo2JQr0o=; b=oVR82AP35Qba4NvYr4OmqmwudONbXsMGp3j/BRQ0pJaTW6WbYVf2FAlwqQcAAaAO8LON T0cJ+zneXyBDVLKvGslz92VltWlXbpkUKp36yrgM3Tta8JqptoIOL1oxwQLqpu1rnxkr Sh1qgQwKLs8irKvm3nM0SNEunQcr4GBPYuPayG59Z5VpjexFas0ELYhZp8YJ7kp820aM pmE+MoNHf6Y6PbftqGNIJnooaiolCZo1q0PKAPGEFpzzROZnsIg1WTsVTGZRFhBfeAwE PQ2JwxRNLtQztOQ5c8ESCryL24s3Fcr7AEG/I2ONUb+ii7XCVyK+cpBR0GQlVJ4RbgNJ jA== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3dkufw2hf2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J71NLPsb+EnwbU2gX50iizdfVePzgOjP2jqqRBjgxuh9FJFhnOPqvqdKVGZu0pY+qYwvnicPyHkVsJZXYtae8jIolSZ98xu2NIpkvyFETp2LFF30cZHVw/Rcezoyvu8IZTVGl8DCGUEl/2t+nXJi3uMH/GsHXSriCP0zg+1tzWHgPEi+bj7u4LOpNCcvhXAqDm9pvQt4h8z/Fh+yoxw07ZR/Xr3/Ad0I+jesAK+7DXivh9eI3HogTKZ4JSu/AkLBIX+ntGsBUzLByQ4sRUcQgRaiucA1g2zArc3BtZUfrBUhk0MfA9rhl63ALLYwKU5sXAFBQsCF5XHl9J6SLqT/8A== 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=ntUOdEHzsaOY78kdSbKxbEuBjHHqoZPjDrvgo2JQr0o=; b=eVo5KH88HQeyPCiaGkfotzlwF2O448uIb6+VYP/TdzKnPxInGiDu6fyIlxxcjfsOaT5fGSjUxQ0YrNpVFgVY1P0mSYmRzdm8WRghbCXfIPMe76gqpuLM9YDZsrOSbs83joU9B2x384eQahHRGDjRGLXuGuZGuEpmYthSakyYkqveEnvtWuNJD324+KKd0M51L5m9XKeL9wgxjOc8hjcyU4YA8HrsnbtWqzysF5ezlHhQ4g7X9L91ZUhckdK0gArY6lL2Sk9NDqk82AdUpNQVUzay4UatF9ci8Sk/iYQmCIf0PEsgwMDzFAoYiClWb9zxiJRLhyX78AUF1kRFrZnliQ== 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 BL3PR02MB8018.namprd02.prod.outlook.com (2603:10b6:208:359::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 04:12:33 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75%5]) with mapi id 15.20.4888.013; Mon, 17 Jan 2022 04:12:33 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v3 4/6] libvhost-user: fix VHOST_USER_REM_MEM_REG not closing the fd Thread-Topic: [PATCH v3 4/6] libvhost-user: fix VHOST_USER_REM_MEM_REG not closing the fd Thread-Index: AQHYC1hzhTdPV+Hio0Of0p9AfUTQhQ== Date: Mon, 17 Jan 2022 04:12:33 +0000 Message-ID: <20220117041050.19718-5-raphael.norwitz@nutanix.com> References: <20220117041050.19718-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220117041050.19718-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: 071fdd94-bc63-4f09-a5ee-08d9d96f9670 x-ms-traffictypediagnostic: BL3PR02MB8018:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:3276; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5Pa9eU2grN5KrosL3BCb0T1ovpOQOnoxvDTSfBfitk7NLgwmq1PSAtpJfO/iGoT+UjLXLMjc091SQOiWaa9rbICMyONaV2nu9AjoFPB2JibW0qMDmkmGsL9OmeV6Lnpv4ZUOFx8X8iXxiX0JFmZQ/xLMrYhV3mFYHo5fIdt+eQu0QBqR6wju/gFurvQUIPRSJVrT40yusSoJhZOQyrtG5rs+/eWFRIKEm39cRcMDlNkpcJKvTOmXEj78ZSloKnTlV7zORrorm/Wjk/6QAhjygQa9g+N/Km8zsgU8ie0+wlwW+gK6eBcp2Z9k0lFjBYOajNP0nOlJkLWsB8I5T2lYfqyRA9SQOYqVAVG7JlxAoJgk5fPYvPfSADt2GKaefVIBjS9PM+4CAyIdds54DBqONLsdno3h7rNH5Rted0AF2zx82n/0PFDdv9dXg3xya+QR93jlrsAitnhn0NdrK3zlgmgwEmt0eISFjW7Im7HqQWFO7WS+N/n/0ocrRWGfG7/bEmo5lFe4n7M70SrXh7wTa9jA6xWL/3GH0IdDz2xFEV7MEpN7dIES26EESdZIY4cyja42b/QE4/1L/p/DRsfpG9F2w4myLPC0XtmyXK3SLQ5fi2p/5lK2TkJR0NpSjEKQZ+A4EqvFUhLL0HPvZKpiXuwQgk6gBKEFTr/legq0+K/oQeTWigt6K/1COgU0Xn5Wb3A5RWVm9+5tru3V4fS39Q== 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)(38100700002)(508600001)(4744005)(66946007)(1076003)(316002)(71200400001)(64756008)(83380400001)(36756003)(8676002)(76116006)(66446008)(66556008)(6486002)(66476007)(86362001)(6506007)(8936002)(44832011)(2906002)(26005)(6512007)(5660300002)(4326008)(38070700005)(54906003)(122000001)(110136005)(186003)(2616005); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?BOCQEjGUQjTvldebfZV+RLiAKMLu?= =?utf-8?q?vbzQ9ZNd2BFLxLgOrORMv12eIR4WKtpSsS+S+70GJfmxTbwl0rma/8ZCiOUihmMio?= =?utf-8?q?YAeBAj3fz1aecw4PZR9nnETth3imQZABTBnSVFQAEQ+sJrEAj/Rf+Tgks6ONMuuhU?= =?utf-8?q?P/3OtPQz8o7yJG87dAMlzZa0NBmpPBBNuxzGLY2jr1jh01s6ah1eN9gGNEZ6RGxZk?= =?utf-8?q?thpArS0ww24p6DBiLOXQ6A4J5NgTr9lzPmPhosEDuVoQGAL3rnq1JkZPRgPI/fVcM?= =?utf-8?q?G4bDjuK+8GHwwz+FvMtjX+wVv5UcSo4k51t9ZTNUlWIcrfkZm4oCu4xwpmUkIEgel?= =?utf-8?q?gcoHrjGcubVvAjyfeipmldIt07TDt32UBYPgqFReQZve2VEGkSnpIX8mOBRxaRiPQ?= =?utf-8?q?CAqMhRxkNokxu/eMiZI6O8afECLhpNW28KRVCcDWee9qSTAELaXZy6bHpGIWDCPTF?= =?utf-8?q?QUslj+cFY/F5LvvzJasbUR3KbGGEpKIimZpdkKXdbf3qkWpx6ZAkuhD4cugHc9h/H?= =?utf-8?q?To27thyfyhuN/l13KcccAbNKYZtPC4nm7U4noCfbX3hRd+4phNsW7/cjppEpRJGHp?= =?utf-8?q?oPYQJserTgHt3U7vLNKON6fxK6E669nP23hTP0nLrVAEKeGodTT26soOoPzDj/LEy?= =?utf-8?q?IShDW5zd9ThO3Ek79WeGH8YiEpmAYu93rL52EQIme2Oo13A3NwxRU26NyD0j2JwCE?= =?utf-8?q?+hPvdUx/WVoR+2c9jeKyeiXIC+MLdMtjdXbNciW2OsrfDnmQpjjN1LBwgSQKD270X?= =?utf-8?q?YK9MdI50uutWQoyqiHDGkH4eH4/uFL2NHz5sS2Qye5xKPpAmCI0hySp7cQU61M62y?= =?utf-8?q?FbFotxoOntFpEdeDu1vmmn4K2jrWW4IF6QczCMQGkDpPshhh+/uxobebIeGSzSqDa?= =?utf-8?q?0ipG8Q6CVpVF3NU0H0QULVD9wHY1OC34dxFpytyYg9L1zxCinkG55S1KzFkE1TMM9?= =?utf-8?q?KX0Gh1TczsGqSJPkBRt1HSLg09v2nRLdZ0yyIHbPkZupHERHmYub/gMjmV6/Edxeb?= =?utf-8?q?lbuv6b7Ama/oJreLbkN59kSaA2YrRMj12D8Mtpi8EnazTslXtGoNteVDsx85Xheqs?= =?utf-8?q?ELsicpnuJd1ZXIHpPptt6NzOUxckSiKcf2hEUAsB/BCcjBbGff+HUKiTbypfcib7Z?= =?utf-8?q?zjMvI39MDoy3/B/MNxpTJJEFRXlrX5KuJBuN4spHJ0kagDd67xl9GAkIWuoTceOp2?= =?utf-8?q?MbZNNfq/X/HuHwUxQnrwiv25qtXSQldsunt1wMliWr7Yj5uHHeFgTKCQuXVHY2sLa?= =?utf-8?q?TmlXxHdtwaQWnMIr4QQRM2KOj+26i4A1XvBGjkD0Wkj8I572V1HmQEFfruo5agpoY?= =?utf-8?q?nElWCm+3z38segj7/bCMsGeqswzqgxdJT/QDsTax+d6Zee0H/jSL3QzUuLGav5dHO?= =?utf-8?q?u+6C+1fiXNsFg0XBZO8rPyU96o5SuZhSCbALhlYZZfSRLvb8Sdb+h7yFUMOGWujAz?= =?utf-8?q?mIiNBXnO5PYGvJSfRQwKPhbUd3BCVJQfoku8BxFH2fwb/n2Ntjga/AGQ85L3pE0RY?= =?utf-8?q?slI8XHUHfydMODFYYJxsMwDZ1R/LTthF4nOTt0DFk0juLmY/Qd0OvARNOQYzov+gZ?= =?utf-8?q?mglYQK0dAqZVH0iqd5iSuP3Wkpuquok7r/jrS2Zwf56PelJ5tTxelc=3D?= Content-ID: <0DE309A181A84B4D96A7705A703E5152@namprd02.prod.outlook.com> 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: 071fdd94-bc63-4f09-a5ee-08d9d96f9670 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:33.7886 (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: AddtD1LBAWzpG9mScpgURbPe7aMXSI4MYQtPj0rYn+1g4gu6Uyk03RhrIkDgftohx46xXk/oxGBgXNoiGIFUi1dQCRPo/otgsaZqczWBRO4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-GUID: gT4SscprzXs-6jxcYGMQRtaKCxZ23eky X-Proofpoint-ORIG-GUID: gT4SscprzXs-6jxcYGMQRtaKCxZ23eky X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_01,2022-01-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.7, 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: Paolo Bonzini , "raphael.s.norwitz@gmail.com" , "qemu-devel@nongnu.org" , Coiby Xu , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We end up not closing the file descriptor, resulting in leaking one file descriptor for each VHOST_USER_REM_MEM_REG message. Fixes: 875b9fd97b34 ("Support individual region unmap in libvhost-user") Cc: Michael S. Tsirkin Cc: Raphael Norwitz Cc: "Marc-André Lureau" Cc: Stefan Hajnoczi Cc: Paolo Bonzini Cc: Coiby Xu Signed-off-by: David Hildenbrand Signed-off-by: Raphael Norwitz --- subprojects/libvhost-user/libvhost-user.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 7dd8e918b4..3f4d7221ca 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -868,6 +868,8 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { vu_panic(dev, "Specified region not found\n"); } + close(vmsg->fds[0]); + return true; } From patchwork Mon Jan 17 04:12:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12714743 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 6A9CCC433F5 for ; Mon, 17 Jan 2022 04:15:14 +0000 (UTC) Received: from localhost ([::1]:50974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JQH-00029D-46 for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:15:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNo-0006lD-Et for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:40 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:30538) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNm-0003Mv-61 for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:40 -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 20H3I4GT011096; Sun, 16 Jan 2022 20:12: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=jdBLatFfZQgIAeVKzCsuAft5+5bH67jwOxFnsHpVJUE=; b=SWJYXhf81IaWN0C5v1QfI1INKL1hkCDszzqRDYFh9I7DSiXfoKPiex3Tr2iydaB4xtfa TLkhJKOAiVpU4d/Q81F4d6cEO5SuxfD2ZykEDFcZmwz3x5xmZBhwVDxq/aAA0FhCr0Li nf8e353db+n4nvpFTHAyPiiHBtxUQ6b8rQa8oZ+ElIPn9T2hpejKa2+qumZF5T3Kl12U eSL19+9cpAFTgHOYmKOx+pLaeD1LgYo14JQQ2jyCv7QlfmcChhvnQWg9LTyUWVAJU33+ 7o6Bb4zrElmKXNbnbPb14G8j+cO3xYEk6W51mETE4VTXigwr37c+83Xa9kwXH/e2mp15 lQ== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3dkufw2hf2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VEgUjfbAWsyYLlIcqAsI2ZdkzXaNIFTnJMnwp+ZOOC4mPvV261uuNSkcaHfYsl0Ec2mBei4r3SuCAMSoarKmiorukkxsWheOj1vN1DOAIjhG7K9DRsMEiejQQaHVF687eGf+bSj/3ZRgMXmXaZp25oNx8hFn7kbd+ibMroYEElvFAaDqmKAqYC3FgXiZXmGMvnFvf4NK707wOqwXRmrHwPDhSwnKsqQlNI5JVQc0dtxjpMZiZisECrTDJBZ+L4CYrdt05B7u2O2b3r4opjl/l7nzF2ijSWTcpE4HVMMkOqvmjZ9EYlVxcdgZPfG+luEt4vPtAMihYT9jg3BdxYGw1Q== 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=jdBLatFfZQgIAeVKzCsuAft5+5bH67jwOxFnsHpVJUE=; b=ofzBM6V41zBnYX+hFxWZiUa19qLMTCJ1KUct61U98IKiQnyPyM1S48PxGAzPh/MQEl1ohMnOxddIt9S2QzFRWjVSJ2Dg3zajvYRFin27A3y3w2TINTNKAWu3louneiMP8s20ncf+vll5Y0ZLpWmBvwfdJPSRKooWP3b+3zL/jWrNrIOPNxTuYqRM0XEuWpZEY2dF/BfmED3qL5kXR4xGhYp6Fz1ROXhdL92Y2ZoZVZ3t6rXJD/yJOx3HdrkfAWNcGe4aWzeGvxmyechoBbTe+gm7t2OEtGczY6v+gj/FPvlnu7iDiT7GoVhb+q9MrNoTYG5lKBXUiZwrh5mHUVHlmw== 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 BL3PR02MB8018.namprd02.prod.outlook.com (2603:10b6:208:359::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 04:12:34 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75%5]) with mapi id 15.20.4888.013; Mon, 17 Jan 2022 04:12:34 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v3 5/6] libvhost-user: prevent over-running max RAM slots Thread-Topic: [PATCH v3 5/6] libvhost-user: prevent over-running max RAM slots Thread-Index: AQHYC1h0Lmuup4pxo0qGaWbHhV/eVA== Date: Mon, 17 Jan 2022 04:12:34 +0000 Message-ID: <20220117041050.19718-6-raphael.norwitz@nutanix.com> References: <20220117041050.19718-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220117041050.19718-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: 2f03a471-19db-4492-c052-08d9d96f9712 x-ms-traffictypediagnostic: BL3PR02MB8018:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: knCkOcPcFQQK3i6e0FYNnnpmNgy+IZ75sgjEQU9XoVCqZoKd85PV9QIuk4xA0Flmxi2ve68IQKtjHqmT33rpSz6VNGiVrjB5LVctWW8whCo6zp10gbYAOQrt6uKA51I9IXwEK24VOfMdinBOJMcgM65t+zVdFUNnW/Oz4aZJCaSJ/BA+uZ9h4m9i5KB76aZV+L9WybabiQTtPG1surmxSgMk9dBkHJcv1RcjIeCJ5LXE+bMwzZBcNsnUajaYEoURpcXYN4pwrFXR1BULvfo1D9GU/RxSktqo/p/Y779kZ3shJfi8sYmpAuWv+LiQ7X4EsYuDCLY3QmLyNgP3UCee4RtDUAk9VMOwKcbkbwJiRV7sB6rP6Vq0V2yt34crMaWGrbAXaMuYo8Sfuq7jrUAwF+nZYO3WU33Al85akmocE4ySmxgTDOUMFzmALz313Cbhe+wBF8epd6l8beEhn3hmTsodASBenw3TjrxdfjC7zfWwUnOkIuy9Th5xRzYI9mAKw3asySE63aK9XmuNMm1WACsP8QcpFIaczogyMVSgaZr+JBpNeGmjgfHhj5aQryuGIo9ZgwhCpblmbJvY9QxDEwlCR/yUU+llSYEpJfD9hpZ9YO3n8Zko+w7fsJrCeUs/8RDzQ7Y9KWd5SEVWkaJkM8eVFT3Kwp8ZHtAyTptac6E5z8ac7EpFbtB6+isAWiqIEDuvAdJGEgbv6Te1p4M/lg== 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)(38100700002)(508600001)(66946007)(1076003)(316002)(71200400001)(64756008)(83380400001)(36756003)(8676002)(76116006)(66446008)(66556008)(6486002)(66476007)(86362001)(6506007)(8936002)(44832011)(2906002)(26005)(6512007)(5660300002)(4326008)(38070700005)(54906003)(122000001)(110136005)(186003)(2616005)(107886003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?ocb+zWXI57gctF6Bc/hYNBY?= =?iso-8859-1?q?agLAirs56/nxdyIUYpiQbjjBx2KCJPbTUTEEwZ5trGMFs+Z6RH47wapC9+xk?= =?iso-8859-1?q?RZj/BPyT37V6yL6TAIZ1pX+aqflIsgPQ7Qv30zIBbgKi3R2lv2vUgYit18aI?= =?iso-8859-1?q?bszWoJFVc1WVvMdNJ+uhLnlG/t6QtA1L4W6Zgpclbp4IVykrmGnx8iuC4uK1?= =?iso-8859-1?q?fZ9yn6zd/ufJ6qvzmUsfoLoh9Su+toF+L2EUXJLEzHDCfMhziOFxAGs0Q6lk?= =?iso-8859-1?q?OG5zZE7Y7m0fi5CCsOnEJkYqvCyI5IlbusiSy5U4syYUqrNIwvRq6345SscK?= =?iso-8859-1?q?TBEUjBCBu941JKC9OTS154k+NpVMgDLYPuaxWA1ettlwEys4RuWl+lCm82H7?= =?iso-8859-1?q?aCyv70zUw962QVQph+gFGV1T7NWIYuswmcXTda/p83yYLbzYTCGvvES9TAOz?= =?iso-8859-1?q?of3tRuYkWwHahnTJwwyWldTLPqQJsw3XgCrKbdmzzfbJTTj5UQ8SiFgen1kc?= =?iso-8859-1?q?aK42ql8toovGDBVvgvmLuawx7b2b6owDGFIPlJd+837G+TGr3atBlwxTodwG?= =?iso-8859-1?q?b7yykI/0McM5HVpjlgVnU3TjHa1bfBZei5eeG6AnulSLqTxrp5US+pyL7iBl?= =?iso-8859-1?q?47hLIK5AsLAI3U12dLVe7/5YVkbs7i+wj2y/s09M/dstPHOumZ5hwVd4aEU7?= =?iso-8859-1?q?4iPESgWaLUC/LB5t/y7iQefdLI3twR/AGVfnfCLzT+WYl05TM7p61FoGjTLH?= =?iso-8859-1?q?+2NwWt2PBf4ETes7j6zFVJ81TfBYbGkyc8qef8xvwtSPNY+Wce0nud1ZAM8G?= =?iso-8859-1?q?aGcvNvdgkBNRRAl3mGwKGMcuCocfCPHmRddtka3I35HyePMTwAu/8MSc7KPe?= =?iso-8859-1?q?HmQscEnyspHDhxHwETs5bEEGu24v84iWST3E87oeTHsWbMKewsl4VnZ5IyhY?= =?iso-8859-1?q?FLYVsW1Bcs+mPK+Q8yc47uAnNBQbwrK0z+mp7zLgnzmBBZsS+aOLWK5S1e+9?= =?iso-8859-1?q?nxGFzYIsTEkl6BqsHfHNOXEtVCBM/TqMO0C1w/JKhF3FOdapEADbnI28AnJI?= =?iso-8859-1?q?WmLrMcfj/ex/bqpFpciElpXoEYtm9yk89By3mq32HkkSEU1LnLyhVplq8tgc?= =?iso-8859-1?q?uqCU+OSJLmt3e64JzH5dhP5NglsdzAqJUJ++JLtj9qALh2IjAI0RlOtv1F0m?= =?iso-8859-1?q?Xkt9Wn5mWZ5DbAn+lk/y71vt3xQucNe7FiSoZ5JIxsLbyKMJRYkCiYkpI9cL?= =?iso-8859-1?q?bsQb93KNMhInibfpOOUlOpYHRDwy9Q8vVZrIXOj7/yYGb3WTLuE/vHGt3NlF?= =?iso-8859-1?q?cQrGaoqIO7/5M9M8g2ttr3ft/3FYP13Skn1tzMwZBbDf3qZ9X2suh6xqQ1ML?= =?iso-8859-1?q?i0uoBUzbNtqIFLlatnY6vL1esAn4dV8JTt0bpYwtggh1Jei5zZKiizq1aDxF?= =?iso-8859-1?q?BS5FjzKLTqrwDEgMqx8fwB5YokfgqQ9RGuKtnaQhiFrAvKcTLhUVmzdtRVSm?= =?iso-8859-1?q?pA5PXtgSUD0mLfR1uvYibLvqFj70tapqIk3bblb1NQjOB0OtXpqC/3GGhgy6?= =?iso-8859-1?q?UWzypo6GoT7K3iQe+mJ07g1BCaaa5ru7H/kCTOPFGjvS5FikDUqdttRqzw/d?= =?iso-8859-1?q?w7QNot7341meIqif/LRTAMrtw4Fpo8u+bRKt6wUZUaNNZAUTtTcujjbETkph?= =?iso-8859-1?q?eJjvEKve8VzP94xGFo8P4n68O4oD5vuh8ldcfkSFL9zIaP+pgzpm7hIlsUsy?= =?iso-8859-1?q?S8Uk=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: 2f03a471-19db-4492-c052-08d9d96f9712 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:34.8039 (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: IwaXOSNiRoowjDUzmC5TyhIeJe5NgJiszP8AM0IgleX28tIufaMKJX1quoBYKWb93pK7T/1ZpOZvA++1SlZ4BQuXZ16V9lBURgq/PINs9+Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-GUID: yi0k7HknDm3XQnIsUlUDMRQ7Xp3EAJai X-Proofpoint-ORIG-GUID: yi0k7HknDm3XQnIsUlUDMRQ7Xp3EAJai X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_01,2022-01-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.7, 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: Philippe Mathieu-Daudé --- subprojects/libvhost-user/libvhost-user.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 3f4d7221ca..2a1fa00a44 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -705,6 +705,14 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { return false; } + if (dev->nregions == VHOST_USER_MAX_RAM_SLOTS) { + close(vmsg->fds[0]); + vu_panic(dev, "failing attempt to hot add memory via " + "VHOST_USER_ADD_MEM_REG message because the backend has " + "no free ram slots available"); + 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 Mon Jan 17 04:12: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: 12714747 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 D32A2C433EF for ; Mon, 17 Jan 2022 04:21:18 +0000 (UTC) Received: from localhost ([::1]:35066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JW9-00022l-Sy for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:21:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JO2-00076o-De for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:54 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:61404) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNo-0003N3-K7 for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:53 -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 20GKxQNx032449; Sun, 16 Jan 2022 20:12:37 -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=NtM9o550nUP3yb93VP2RWhxfXwHcdlYOhpQg1QJie10=; b=YWxMM7JeUAPVVX9gaK1n1mP0LpbeOIAvMgmZmm1EQ66HVG7fEmFyIcNrcubHXbPGVRZA iYWnOlr5fSQ44MPATbE70xWC64ZPtDYLgMs/kGWZARQGD3ddQNrcolWRMe+xU/HKbNJq kfkci7lJAPG0NDD6w8iRlFTSWOJ/Kk+eBE5eXL5UTei+1YmcW4bDeNLYU+h0FvpQP7nW hNlotRPelVdGr19WZ6ryiO6RiSqaCOCPDllRCe5XhMt/w20cGa2TDg3HBo5B56aHGJFu wFNaLBQpf1tlSan8AR9cy9qxFak/8BDmb5F/qZ+Upnna3/Bxcdf6dYFDHebWFKtzNAmZ cQ== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3dkxq1tagf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y4IZXu4b2C/fuymeM9Pw2FGPreppn1c3lvgSuhSMfbxjqM/+tmQFhllGiDK8TGcoSDZIVnYAaNJwRIN9/bRMDLSosk4V1JgnQtKqlXUL/3hU6vPfJ67OL5lJR5PF6Rq5fgNQIzRWvIPjYyNGIq5DdGgHgZk+rF/7N7q1F7xxjPYiz5Hz/8re3SkEXxhz5Wlne/FPxRoXmiL9oOSy1nRHqIYoCjxPVrqEhFzTUNKrlbMUGAKap5qrSAvtd4fT2HE2SXQhmbS12IBkZd7K2OZUPBeORAYF+RSyhYErmtLh51FX+LUrz08EnkkveQUNk4fUdDmrO1iXPryk7RKI+/pijg== 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=NtM9o550nUP3yb93VP2RWhxfXwHcdlYOhpQg1QJie10=; b=mEE26R7obC47whfVnDATfudltosSP76kPlMfngPaoRiFOZ7Wt7CXoLUa3aVnyAH1M59i8Wcd3FPoWLcwcoByJK64VSTrQhEDeFnK6aItowYoojBzUR+yCGM3mVuSbD/XzibuxLJb0sADFsaj2v5akbrdESo41CAm9/9OGwOSQBvtEpFoIVKPsh8ImnpjHDGyQR3EQN6bu05FkdTx9yXFEPsQ70bV0eKq6Zoy87wqMukjKdkhfay9LjmMEWi/SHK6PxG1tnuEvVGCk1Aa0KxNPTPZMgpX9iXYlwGgDBlcp1mPzSO69mdKPOXdmxSaWwNExGfcISLp6YK8T2DmRowHnA== 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 BL3PR02MB8018.namprd02.prod.outlook.com (2603:10b6:208:359::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Mon, 17 Jan 2022 04:12:35 +0000 Received: from BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75]) by BL3PR02MB7938.namprd02.prod.outlook.com ([fe80::4ce1:59d7:578d:7e75%5]) with mapi id 15.20.4888.013; Mon, 17 Jan 2022 04:12:35 +0000 From: Raphael Norwitz To: "stefanha@redhat.com" , "marcandre.lureau@redhat.com" , "mst@redhat.com" , "david@redhat.com" Subject: [PATCH v3 6/6] libvhost-user: handle removal of identical regions Thread-Topic: [PATCH v3 6/6] libvhost-user: handle removal of identical regions Thread-Index: AQHYC1h1GoOP5FV9bkuu4JxnCe3gIw== Date: Mon, 17 Jan 2022 04:12:35 +0000 Message-ID: <20220117041050.19718-7-raphael.norwitz@nutanix.com> References: <20220117041050.19718-1-raphael.norwitz@nutanix.com> In-Reply-To: <20220117041050.19718-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: 584de1f3-3c89-4f3d-0475-08d9d96f97b5 x-ms-traffictypediagnostic: BL3PR02MB8018:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: O68tfmaEAao3Jz7/sTwhvfLPDwmX+9DSf87VWEHZQNFeWRGLPY/qw1GKq4sK1Fm++mZ/2m3Eu1ASGUoZSybP/o9S10UXbbiuaBc0WEAqG6mja2u9sa3XpBxg9faoTxDkAvU2a9Jk4C3Pb5Kj9h/pnJytIdOyWlihXTh2yn1axS+UQbU6ev72TxGERW+CedoCIzQoMEPzThINsPgXpvj0eXbeFBppf5FqG2ViAvt9xZ0u04PgMhfcZYGQkOJHwlbxr9eyDun233ZxDACD4QVpvZMMY3/Gnl3/NpRR4LdwVdOu2/oYULqP06t/RCQcfZN036HWksAT3FM75LmaOIkb3az2KRrnc6BBTNoEekXRqb6gzatvpdjnnay+xSJK5KY39HeQ4jlc7CJD5OYXW5Aq1E4/OGqPPzgDTtoJvW/LdFqu4vW+o3FYshHIxFbsJV0I+zZBu6suBpkK6JVJGJdl9mbkjFzrCdv46ivJd0ounnPqEcw02csklsnbJ4SKI6Xp53D5xKsW09/1OQqpArKMkskG6QXvyX2uR23TZQbKen/KiY+t9H4yL4na8gmykBqi6P8AY4H1vM2aZ4Gw2B9EDRHRM9MSsNSJFcNtzT5b8mQ6e/DlpFKXtbYflfQlBMgK5FPF6I52yVaE7p/1UMhMn+VisxDo+Vfq3TtfUFne9vfBquTlXXjfUSitvhCPCmMqSJvft6HHxpMbyDRNrXpSVg== 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)(38100700002)(508600001)(66946007)(1076003)(316002)(71200400001)(64756008)(83380400001)(36756003)(8676002)(76116006)(66446008)(66556008)(6486002)(66476007)(86362001)(6506007)(8936002)(44832011)(2906002)(26005)(6512007)(5660300002)(4326008)(38070700005)(54906003)(122000001)(110136005)(186003)(2616005)(107886003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?hd1FEM1lyP33b/TrYD8QD7f?= =?iso-8859-1?q?yAOqj32b/P5DE+iScNdq4Ni7DdipcK4oZlzR3vrGoAW+Dn3IIdRnfleDrjLl?= =?iso-8859-1?q?b0LBfuddnDdL7JY4xVDEB049xkXtV4dS/cP6JpMgUPiMpq3JsEXBfCc5iOB1?= =?iso-8859-1?q?/pJ9vTyPSkANmEgEWf+OqceM3u44DTZLSNWLzIwiQM9gwS0xEeKIRjDITO/D?= =?iso-8859-1?q?j4USxmmlCvsUyC8E0LCvJ3tWPCpg1esO2lcEva3jAAFEjEMzv6RJWBqNzDUM?= =?iso-8859-1?q?6XoMQGm6RMAXaHJEQjIJlbY5tEAMpC+C0/42f3Jzea+B8M/NGOVY8fZwIAVd?= =?iso-8859-1?q?9vX+k02DCMXu0pjMP/6eCx0vZEK+r8Rxebx1J9CM0iz5lBhFubEtsmSBBatf?= =?iso-8859-1?q?OnAXKO0FECMMFFCBRfxxUHzGBm0xXl/ktXxdnbGKFcMpqhNUCCCUKO0akqQ+?= =?iso-8859-1?q?dLzm39oZUzidJWKwI4CIvJssET3ScK1JQlCRLXCPYd2afrFXpXJ0y9IFyvNw?= =?iso-8859-1?q?K7DeV4fRhuSujbJ71WRhtMVoBeSttDkKZH+Ov8EJUUE9dK9gdPozNVvn6fCg?= =?iso-8859-1?q?HtP7KImqx8wl1nP5WTjbNseqTie8nVe5BPmfoCFklglamzBvBg/uhnVOyPeQ?= =?iso-8859-1?q?LB5XxxeXbInLIiSbDvL6MHK5dMz9mCw2JVOjih+mTii58bQ9VZ/BlhXYskKY?= =?iso-8859-1?q?DvCZLZaACqoPuW4xeq13M+EUwOGdh67twGxqIoB3yOqwfsmGnOFjxL3N9eun?= =?iso-8859-1?q?U4EBTKCyQf0If99whzBGQMluhbF98qKrmxXxnC0FOwJzUcdRAMSOdCRKFiU8?= =?iso-8859-1?q?yWXQtl5gOjC3nMOE8G0IquHtZ7vbrNy/DkbPIS5yscQWuBK9S28Q1CMmDLnM?= =?iso-8859-1?q?/EguiMrifu8UrRCEneEls5p9ifA6TEgxzkj1p3PVIEstYTbYxbSfT7fCQbTY?= =?iso-8859-1?q?JKIuAP2wW6xHfFSOjIpqvHnMT3gfp+Y4Js8jMOJgedvQjNMgAJCL+GowX0zD?= =?iso-8859-1?q?0qdk8eD1y4dj07cIedmuv7x/mUSrPpkussUIWziJfy49jL3653jUl5yKtFco?= =?iso-8859-1?q?EJVapjywidcf9fD+zjDuvVDJawt0o6U51OlW0N0p83FLxLtrHZAMnRWaVWd4?= =?iso-8859-1?q?QIfVm+jnsxLQVh9OPBeZ6e+ojTczOSlL9WsPT+11s3flTFx+THSraes3y6he?= =?iso-8859-1?q?rnZvtj+XwFTIn8CCXTaq58YhVUmrCYr5Z24zNxVKwURksDq9xBlMW7T+4d3F?= =?iso-8859-1?q?b9nRAgt41WUAP5M9K5dbcvKJSsLisAQrJgdUCwgbmGFrE5nfjuS8zavUlCPY?= =?iso-8859-1?q?vuOdgoHP1kJrOecyMvBcSdCnnj+YRwXiSXuW6MyXO9J4uID+YXkNsCZUnesz?= =?iso-8859-1?q?a6ktNe+f+uV7NrOeTkwJH2IhOTrpvDIkbs1wmn7vZVgiDpuJVryJ+8uHnqnR?= =?iso-8859-1?q?oJdxzyL85wSwmrlVtELmiBGpPMNdtysmAqbTXU8aZTeOjEWK0slr2Bs1D+Gg?= =?iso-8859-1?q?l8F/jP5wvoF63HnWKvowKR0GaXktGoYoX5LD2JqK4i/wnYlIhUhyIYZmVruc?= =?iso-8859-1?q?2oNucHFtPY+WUEdhLLlbcXTuuj6zoLiWRdZyC48jFFQsG2Q8v8HdhbFAxyRv?= =?iso-8859-1?q?lc9KE4Dh/V4U/F8CKPSzVd9LMiHHLWVg4E5rdo3cF6wKPT832/DP6H1Vi90a?= =?iso-8859-1?q?6WL0vwYGSyp7fVNZOeD3Z4Nz0nMFMK0GJhAC5fyOdCrmihwBGrXh9KBLhMHQ?= =?iso-8859-1?q?lqUE=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: 584de1f3-3c89-4f3d-0475-08d9d96f97b5 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:35.9143 (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: 6M12pk7LDBhI82MxrSqLzstzzeQQHTIImrVgjbA3xeHeDfc1QSeFW4E/Fw9uhss5hEXBbgzLqEMiZBVeLgD3Y1TupMhckhLc1xORG31wTmk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-ORIG-GUID: 2FgkBzG0XxhQVHzUhBSz_VT6rNk1VhV5 X-Proofpoint-GUID: 2FgkBzG0XxhQVHzUhBSz_VT6rNk1VhV5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_01,2022-01-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.7, 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: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 2a1fa00a44..0ee43b8e93 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -821,6 +821,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_close_fds(vmsg); @@ -856,21 +857,24 @@ 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; + + /* Continue the search for eventual duplicates. */ } } - 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");