Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3240666ybb; Tue, 31 Mar 2020 00:57:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsnPaRDRuOzPRPn1S6bF1tCiNWWG+CBiijwFgP88GAU5FpPfwwyBq5gLZ8QnF2+Yin+ar2A X-Received: by 2002:a9d:171e:: with SMTP id i30mr12093885ota.327.1585641453360; Tue, 31 Mar 2020 00:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585641453; cv=none; d=google.com; s=arc-20160816; b=TGBTalOYbyoCz4Wo9uYKAqtmd6LaP6J6MqPo4mHbFfMd9b82DKBObnh+aCnHt7uSoh HJCBPdJ7ACqgIXZ6HxdPF8N6aiTH1io9R20wcZbY/cKpezD3xFwSjoxNW56s2y8sqiCA CVwMQEZEyMepTbAYsdGfnzixddclQ6ors/ssp093JJD0EJ0FxyUY/5x7CV1wy1xB0t3J obKHzEwBklfPdvEub77mRTzmm2FA493pNtJKGQwnJqrFCAbDN4PJoSEH/ggHqrMc6Qpj UZmudGVySjhpsL78cqiYZUdcevwwn2JCDZZsAyPD+X7mbVupYW0Czlr4CbQfe0Gpeb48 8YYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=tVPpfazcLCn+rGmQCgJ5zFx/4NhoiRWfcsMxHXRN42o=; b=sc+OkQOmTgbNxyi8eHKxQBeLoGfqX/9jK5oL5Pdqm32sOlcCYFfN4Oa0XnNdNsFeVj mk3rRxQQl8ruM32Bn5wvAGtImw01FLgmBj6tTPhM2yHC7Vo+Q+RW1hOz17VMZoPHGRtd U0wLZI9/a4QTUWQIHVMVS/rcTtP1J5KSmFAWhES5rw8oDwY6Dymqz4FLtT7PYVXa4B4n lcKuY3ygy+ueU1aJ2Py7aJvqnmBi8pQKbVC2h4linMqp8xMSNlEdOGtZJCmH/Wml7ekq v5eIPKvX2mnNGCK6+d+aWqGXp3veW7pKXIssPjQK3z3IG4AnotjUEOtVdJ4oRF63gIu5 UjGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="FFlNEE/n"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g124si7015755oia.0.2020.03.31.00.57.21; Tue, 31 Mar 2020 00:57:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="FFlNEE/n"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730175AbgCaH4G (ORCPT + 99 others); Tue, 31 Mar 2020 03:56:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:53358 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726397AbgCaH4G (ORCPT ); Tue, 31 Mar 2020 03:56:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tVPpfazcLCn+rGmQCgJ5zFx/4NhoiRWfcsMxHXRN42o=; b=FFlNEE/nlwmrb0Bytn4bR4slz5 DIFgIBF6s9N6avl/FcU0oeGua2Y42YpqPuAivHRf8axXjj4MQSNcS3ne3ktFngaVB0i+Y3P2EUwWN V2KClLrxzs589LKw7aEYMNJlL09rtXUi2Po090dVhWbpr40z+H/Ag4UoKqPZBQxEDdURIwGcdqkk6 q8EjEixndcchbHD/9Kf8bIMkWXZ03ArAmUaQ9rl7ja4K1T6yM4KUyunlW40SfWl7qiqV7rKKzYoU6 S16zsX2EoWgfit+02B9oGzvIfX43eDvQEiiL6ljkaebIIMhilw8jrQyo0IyP6ftKMn+nzxHpAN/ey zvQoSzBg==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jJBkh-0001Rp-Pp; Tue, 31 Mar 2020 07:56:03 +0000 Date: Tue, 31 Mar 2020 00:56:03 -0700 From: Christoph Hellwig To: "Liu, Yi L" Cc: alex.williamson@redhat.com, eric.auger@redhat.com, jean-philippe@linaro.org, kevin.tian@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jun.j.tian@intel.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, yi.y.sun@intel.com, hao.wu@intel.com Subject: Re: [PATCH v1 7/8] vfio/type1: Add VFIO_IOMMU_CACHE_INVALIDATE Message-ID: <20200331075603.GB26583@infradead.org> References: <1584880325-10561-1-git-send-email-yi.l.liu@intel.com> <1584880325-10561-8-git-send-email-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1584880325-10561-8-git-send-email-yi.l.liu@intel.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > @@ -2629,6 +2638,46 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, > } > kfree(gbind_data); > return ret; > + } else if (cmd == VFIO_IOMMU_CACHE_INVALIDATE) { Please refactor the spaghetti in this ioctl handler to use a switch statement and a helper function per command before growing it even more. > + /* Get the version of struct iommu_cache_invalidate_info */ > + if (copy_from_user(&version, > + (void __user *) (arg + minsz), sizeof(version))) > + return -EFAULT; > + > + info_size = iommu_uapi_get_data_size( > + IOMMU_UAPI_CACHE_INVAL, version); > + > + cache_info = kzalloc(info_size, GFP_KERNEL); > + if (!cache_info) > + return -ENOMEM; > + > + if (copy_from_user(cache_info, > + (void __user *) (arg + minsz), info_size)) { The user might have changed the version while you were allocating and freeing the memory, introducing potentially exploitable racing conditions.