From patchwork Mon Jan 17 04:12:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Raphael Norwitz X-Patchwork-Id: 12714742 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 25FD9C433FE for ; Mon, 17 Jan 2022 04:14:35 +0000 (UTC) Received: from localhost ([::1]:48664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9JPd-0000cR-Oa for qemu-devel@archiver.kernel.org; Sun, 16 Jan 2022 23:14:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNh-0006eJ-HW for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:33 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:9442) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9JNf-0003MA-D3 for qemu-devel@nongnu.org; Sun, 16 Jan 2022 23:12:33 -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 20GJKdlq007012; 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 : content-type : content-id : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=EHnrFjcuJCEm7lKnyuWSiM5iQzfUGnLK3az8ezOt+4o=; b=ux4V+4VJxHd3SOCiZBy+G+zO+bJ6bQjOTaVN4WrmO8qDnSlKjxMybn/L8zXy6lMUtDOw c1LOKwzgNTmPwgYtxqzGxLhquqZjoaq646jbeMIscVmEEfLzMmRJ6KQEmJqXuwTI709p uG806DWmPbp25XRQa7pAWjAAyJLdtac+qYcHXIGA8J5z41GYjaQyzbqqyZB7/98PAaGv /vp8vdCr4VKk4hbarczHzraXVCv7K4HndrtDLjShzp8Wgj/x5FJ4EEAMc3M32NqhMcuB zQBKjc4Y31HJJP9I/skKUVqQDmEIAH1gW8upAHWlJjrQZHQ2c4LwLessnR86whfdeQOg yA== 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-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jan 2022 20:12:25 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cSq7HlfXQZQEfZ1H+5ktPzjHfV0B4QDbOkv9kyeavhHMLgD5SA50dQfRvxCWhtHfp+L+MnwmMIeXNGUnxK8fyp9vTio3cGNXXew5bDtI24UHLDsrVrNIdi0Ixz9YZ2FDM9s5XPvyAOXaNaXwnHrFqsPnEZO9dcpoI4n6up8Zqm8JNl8mjd+jRYOtDQu4WzgGnlq/dkEoOfc43B2ZHNgGI08z2kyzO3qJ3mkbDjvA6wk/XEzY1ql6XhKeYj9gd0Vs0nPkAxHPkXn+O2K7+Uhl4mHmdnNY+MI1UMIkxQxLypA2EDZqEPhcp4NypC+1aBHP9nmBqe4BrjWp3uKnLf1ZnQ== 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=EHnrFjcuJCEm7lKnyuWSiM5iQzfUGnLK3az8ezOt+4o=; b=BzhciLaJWBehPoqXQlaONW75vzfZOQzG5dYHCgcnnqHetI/kceYSrEU0inZV32r0YfKLtjIYYgbip8uExlMdAanNIvnAnNfRksZqE1dwlvhLlPD1HeqSf0o0yLbqntqjMs7R4QpExpiuGilRGAca6FHAaS9TvJXKiejbsUUorsPQ1M6chC/9Q0ZBF+AE5axtdz68Ec7UpLYRLNk6tzmg8VLyEaEsGTcc+siJtISNbCTSGLRME77UJnCEIryfz0whYV7rtxBJoIi10jNdLPjAdZPCfybz4MFDoIgRD7Rs/y2dp7QjO5qTLNzCvNAFGGDSQOaiql4/DedhSLcRetbOfA== 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 0/6] Clean up error handling in libvhost-user memory mapping Thread-Topic: [PATCH v3 0/6] Clean up error handling in libvhost-user memory mapping Thread-Index: AQHYC1huy31Z8KbM3UOALQuSYiQOfQ== Date: Mon, 17 Jan 2022 04:12:24 +0000 Message-ID: <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: c38c7ba8-5387-4e70-8079-08d9d96f90c6 x-ms-traffictypediagnostic: BL3PR02MB8018:EE_ x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:1186; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: k8dyMIvb8olEf/YUmFJ5YCFihYSlxIEVD99VVWVNbYAUrADLVieApCYRT0EoM5rUXZ087I2ysmYZs1+OrqPtgb6yQ4xLaQCOAHVREHH0LF3UUsDbH7K2dwvLqp8bJsQsKRVKtE7YuN2DAlvWijaJxsXWa+DcsLUHDxoK581QsrkRKIOwNy9ZWVqOxTHU/uhrXoWwAIckkQj+EI3fiBPEbN+wFZ1oeAXzd9QP48agkfgra3OICtPac5v4orAmAf351vddXqIMLWLZOOdoEf2HvcfnBLgCS0HQESba5lrtCCKiHzlefskFzvHxGEuuLKh0Q8aU1dGROubDLuXbJvZ0YDHkksw9lX6w2jUSWBsDwQIXudwu1x0Et1f0J6z2EFO7KBbF/FVVXX97AAKB9s5nw+32ozrsZRe1wSEbbHgC2cT4x0/7h29ds01W+BlR5+V08R9zz6V0DvBqevdTnTpp+6U++z9lm3Z6mU8HjaVWXkwIObhiLiGKNd+YaQDNYgb1VESIqHrmHBLxlVgpAxceOsDpX8VKc1P84Ujz4wFsgtFRc2/aApq5bhoZlKax1gxUDetmFTZbyV42OlS38IXXfLbWcJpJyDwhYmLOQOQ1mmqUnV9wsgByr9X6B1Y8HsB5RZuiJO01qfWaWzU9bbCrYviX8xW3Qb1JtuU5KDYB4vHpiLKfwIJ/FkBQrxysTkE6iLl9BNO98CwsmdE8yi8HhNA0wheqBuP5fTs8VOM4bEQBqw8+EPoyFjOdR56RjZuGngj6ASwrrptZjzvx0imxDCLYUU/L/wICnEfBOU9+OWni+3PX5Y3Ofnq4/oH7UCltQeIqjyMFj8juEwI4qnxQdg== 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)(966005)(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: =?utf-8?q?kwc2Y+0ZRf+dQdHhcO+DcqeDC6fe?= =?utf-8?q?qL2exuR20vjgIClskXGj/HsSAxg50BS/5de4Hw4nInquNGAAHBManq9pPU47FeVxH?= =?utf-8?q?cOFDG1rdnWDc2egQRx1sQYuKO/896IJ5HWu3iHrBOrf1Z614jOrrBVnotb7OHgBQ6?= =?utf-8?q?/FcodTN+HkFnTiKcz84vptNRcVIJS6UbGLUMDqv1CIUmq9nQ6aw5J5fWolQkvDjkg?= =?utf-8?q?cB2zWWX9CGhkunBtzQyHY7f37/5W53lp83oDU5BC2pGgbYGdY7NbOeIflQ8kZtv9U?= =?utf-8?q?2FoGaDItC1hu6zLGZcUwfwAh1O7/saXCwKlzLYFz0YGdef9f1Nt8kV/KyHowly8Gx?= =?utf-8?q?PXs1fhCdvAlC7uOxX54QS2UcbGqSzj0g4fXO5FGNvsyXaVGQFwuhAAIRygedDEol1?= =?utf-8?q?8pxjOarO8ps66CslMqcmE0I+DdqavfFjDKZ7b9OhoEzxBkcTkNBTIqzU7o/Ob2y6m?= =?utf-8?q?85AuLbiM+3FosgHjkeTwTGSJGpG1gYDOO4Fwh/qQ6UVZJIhlx9Ai7m4M3T81Gbq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?q?nCeFaMG8WLOL2SdU+KbBrtDkkwvd7aHldIWjYEygAQl4iWHNDMT/MTQoXo2PC2yXH?= =?utf-8?q?483C7zPk5QAwDst9ua1JhHY8FKGuofPWlqb5ngRtPKdcoz4ls5Eupe3RYYSaIEY2Y?= =?utf-8?q?VEfTTeeVlUqhxTZj1IXwXjmmHEpDx+yKPdjc+i9ppyQaAwkK82/5fPjm9cP0Y4Y6n?= =?utf-8?q?RLYaBVIVUgkeuoYjffWsr6gGqHoRz5u0vdxdquF0SA4JcEa7IvK/Rs=3D?= Content-ID: <78CCD3212068C44280CB60C7B274A87D@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: c38c7ba8-5387-4e70-8079-08d9d96f90c6 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2022 04:12:24.2379 (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: fw/KimsLQpBnnMx/5BUkMQQ3JvwWE+DPFftbTyCnwHaQSzlep022w7hX40U+Ad8/BZg7Y5gJc/BsBM9Pt29vBPaC+FXhq5UTOfSDUxKUziw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8018 X-Proofpoint-GUID: JtlEXFEy8dZMjX_TQMhMcTkBsjtC4MzP X-Proofpoint-ORIG-GUID: JtlEXFEy8dZMjX_TQMhMcTkBsjtC4MzP 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" Hey Stefan, Marc-Andre, MST, David - As promised here is a series cleaning up error handling in the libvhost-user memory mapping path. Most of these cleanups are straightforward and have been discussed on the mailing list in threads [1] and [2]. [1] https://lore.kernel.org/qemu-devel/20211018143319.GA11006@raphael-debian-dev/ [2] https://lore.kernel.org/qemu-devel/9391f500-70be-26cf-bcfc-591d3ee84d4e@redhat.com/ Changes since V1: * Checks for a single fd vu_add_mem_reg and vu_rem_mem_reg return false instead of true. * Check for over-running max ram slots in vu_add_mem_reg returns false instead of true. * vu_rem_mem_reg unmaps all matching regions. * Decriment iterator variable when looping through regions in vu_rem_mem_reg to ensure matching regions aren’t missed. Changes since V2: * Fixed FD leaks on all input validation failures * Added comment David suggested to explain removing duplicate regions * Added David’s patch to close message FDs on VHOST_USER_REM_MEM_REG * Expanded commit message for patches checking FD numbers * Fixed vmsg->size <= sizeof(vmsg->payload.memreg) validation check * Improved error message when a backend has no free slots * Improved error messages when the backend receives invalid vmsg->fd_num and/or vmeg->size Dropped R-b tags due to non-trivial changes. Thanks, Raphael David Hildenbrand (2): libvhost-user: Simplify VHOST_USER_REM_MEM_REG libvhost-user: fix VHOST_USER_REM_MEM_REG not closing the fd Raphael Norwitz (4): libvhost-user: Add vu_rem_mem_reg input validation libvhost-user: Add vu_add_mem_reg input validation libvhost-user: prevent over-running max RAM slots libvhost-user: handle removal of identical regions subprojects/libvhost-user/libvhost-user.c | 76 ++++++++++++++++++----- subprojects/libvhost-user/libvhost-user.h | 2 + 2 files changed, 61 insertions(+), 17 deletions(-)