Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp817386imm; Wed, 17 Oct 2018 08:46:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV631gr6TKsTplsI7lw0wxf9mj9tucVl5xVBm31vFGkDmsXWMGehu2s+b1WScgVegGBTLE+X6 X-Received: by 2002:a62:8490:: with SMTP id k138-v6mr26936137pfd.177.1539791175361; Wed, 17 Oct 2018 08:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539791175; cv=none; d=google.com; s=arc-20160816; b=HI7zN3MkySNwswR91hjEzeDwi1ZyldICkEZB4Hckfa9EqcrMxK/hClwUW/Ls13Ohjv rzYKMwmGI2nTCGBlyIYVGKJs6RE1D117Ns1V6E35cvmi7Zg30Sm7ziQ431NIa16nUaUb grogkveyBvEf07wrsb7qQjaCXg1jmTx4X1OHnmm+O4F9oUx1hz7cLHk4jlUtqgwjo/Gr l0m0vi2wk4UiaWT0aj4xkoPPwy62RiYgOiLcjO2ecAnjTNJge+6865ASbVzICnilUAmo n5Z9iVXow/cRHOJsrGNttUOTrmpDmwE21DOvYmHP3XiQ7He7fZxw5YIO086Xb+X4vCR1 2BXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=X3C/XTqM+z7KWtTLVBsAwVq9LofWockuWF7CppQkWM8=; b=j+5ylbFHAyhgZ9T7Z4Zc4WrojnpY5lTW+fpajvcN7upTfK1NnMWV2VP7eN/C6Fr/P8 bRk7FKxQ49l0oh802cxhFIDIuMuyf1+qOSDDOYYLRE4msaPWTGmIQPmLV/Vmyn1MXB7w N5VhpAdewf+d8F+JvYnB36zLT1LG7mhfVFHBfGqmDugvu31nasK6aYO1KCtgc6AYQtqN I+E1nBpkazEC308Eq2NdKjmv+wVPH810qAfznUv1i/0kQL8GAukpKCUusjw/J7BT2dpC EHH/ccQt3y4skcHdZS4xM1LbcBp7wlWw+9bGcY40Rrt4PB4FNP6WqdimKAsK4qAq1uNe zg8A== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si17512771pln.232.2018.10.17.08.45.59; Wed, 17 Oct 2018 08:46:15 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727531AbeJQXlZ (ORCPT + 99 others); Wed, 17 Oct 2018 19:41:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34766 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJQXlZ (ORCPT ); Wed, 17 Oct 2018 19:41:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D7389D411; Wed, 17 Oct 2018 15:45:08 +0000 (UTC) Received: from w520.home (ovpn-116-90.phx2.redhat.com [10.3.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A11219E14; Wed, 17 Oct 2018 15:45:07 +0000 (UTC) Date: Wed, 17 Oct 2018 09:45:06 -0600 From: Alex Williamson To: Wenwen Wang Cc: Kangjie Lu , kvm@vger.kernel.org (open list:VFIO DRIVER), linux-kernel@vger.kernel.org (open list), , David Gibson Subject: Re: [PATCH v3] drivers/vfio: Fix a redundant copy bug Message-ID: <20181017094506.1b09eb64@w520.home> In-Reply-To: <1539786725-1812-1-git-send-email-wang6495@umn.edu> References: <1539786725-1812-1-git-send-email-wang6495@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 17 Oct 2018 15:45:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 17 Oct 2018 09:32:04 -0500 Wenwen Wang wrote: > In vfio_spapr_iommu_eeh_ioctl(), if the ioctl command is VFIO_EEH_PE_OP, > the user-space buffer 'arg' is copied to the kernel object 'op' and the > 'argsz' and 'flags' fields of 'op' are checked. If the check fails, an > error code EINVAL is returned. Otherwise, 'op.op' is further checked > through a switch statement to invoke related handlers. If 'op.op' is > VFIO_EEH_PE_INJECT_ERR, the whole user-space buffer 'arg' is copied again > to 'op' to obtain the err information. However, in the following execution > of this case, the fields of 'op', except the field 'err', are actually not > used. That is, the second copy has a redundant part. Therefore, for both > performance consideration, the redundant part of the second copy should be > removed. > > This patch removes such a part in the second copy. It only copies from > 'err.type' to 'err.mask', which is exactly required by the > VFIO_EEH_PE_INJECT_ERR op. > > This patch also adds a 4-byte reserved field in the structure > vfio_eeh_pe_op to make sure that the u64 fields in the structure > vfio_eeh_pe_err are 8-byte aligned. > > Signed-off-by: Wenwen Wang > --- > drivers/vfio/vfio_spapr_eeh.c | 9 ++++++--- > include/uapi/linux/vfio.h | 1 + > 2 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c > index 38edeb4..66634c6 100644 > --- a/drivers/vfio/vfio_spapr_eeh.c > +++ b/drivers/vfio/vfio_spapr_eeh.c > @@ -37,6 +37,7 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, > struct eeh_pe *pe; > struct vfio_eeh_pe_op op; > unsigned long minsz; > + unsigned long start, end; > long ret = -EINVAL; > > switch (cmd) { > @@ -86,10 +87,12 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, > ret = eeh_pe_configure(pe); > break; > case VFIO_EEH_PE_INJECT_ERR: > - minsz = offsetofend(struct vfio_eeh_pe_op, err.mask); > - if (op.argsz < minsz) > + start = offsetof(struct vfio_eeh_pe_op, err.type); I noted in the previous version that we already have this in minsz, so you're fixing a redundant copy with a redundant operation. > + end = offsetofend(struct vfio_eeh_pe_op, err.mask); > + if (op.argsz < end) > return -EINVAL; > - if (copy_from_user(&op, (void __user *)arg, minsz)) > + if (copy_from_user(&op.err, (char __user *)arg + > + start, end - start)) > return -EFAULT; > > ret = eeh_pe_inject_err(pe, op.err.type, op.err.func, > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h > index 1aa7b82..d904c42 100644 > --- a/include/uapi/linux/vfio.h > +++ b/include/uapi/linux/vfio.h > @@ -729,6 +729,7 @@ struct vfio_eeh_pe_op { > __u32 argsz; > __u32 flags; > __u32 op; > + __u32 __resv; > union { > struct vfio_eeh_pe_err err; > }; Please don't include two separate issues in the same patch. Am I also correct in assuming that this is untested? Thanks, Alex