Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp962004imm; Wed, 17 Oct 2018 11:00:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV61O7fvEf2h6aoEmxpvPR89ubndKHRidLiN+novKoujVPD8nr8SGCq0rcN7LIDPoGEBACOma X-Received: by 2002:a62:5251:: with SMTP id g78-v6mr27394735pfb.256.1539799201319; Wed, 17 Oct 2018 11:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539799201; cv=none; d=google.com; s=arc-20160816; b=moQHrUUWvOTJz0/JtY0kocORTp8pXGH1nc0eHpvpWiJ7DCueD0Pa4relbvfLRhicJi Y93HN0eqzcisAkXpzbAo6bo7AJ65QI2LvVDyZopBMzRTavUs63azTncO5WIuX5DjFAN2 RFjK6hbiwSrNVMEJiAUcSJAhe2BG4ybIHcBdf0EDbhMkuUUBM/NGptredcTUaI1kaxJd ezOiqeuQo99GUhDHC0kceWSHoFiRdfXtRTccNiaA66msleDdWUgLL11hKnR8WIXZFNmt rQIpCFah2Hm04LxfevNYiZVbCC4bo5vgGUq/FU3E0igQmRRfU0TscFgIE7Puit2rPHxq DfLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7wc0TmFIQz6XPjga22BUjOCfVjs9S6j2LIm4hCvDv6w=; b=odNEiKk6ApkHq0bpFbW+I8I9AsBQMDTNh4eb6aSRY87Tgyo1JFA+Vg/CsV8IVoTzEs UxzXNlW2V/DIo4gEJmbWNWZguS0kKTZ4CB18ja7D+DKIIBCj2hYHhrR8loaJe4HZMafh 2yCcxtk9PdUum0ZPEHFa6g01i0oKevvqH/uNoqbW1mhZc2Iw3EdmJQjCgZSCV9e1TtmZ M64cVVubObo6Av2plq97uic21w1TNIEiy1f7fV6n10xVrE19vGFglQIgUDi32ey9z+jw 9wLxQpChaqzTaAFC59GE4gNxdXT433aIxk9FMMl5Xk5E5Vww/tM7M57xSBEO5yH4cPJN HuSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=20160920 header.b=Zz1q4iP2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si19501555pfm.51.2018.10.17.10.59.45; Wed, 17 Oct 2018 11:00:01 -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=pass header.i=@umn.edu header.s=20160920 header.b=Zz1q4iP2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727695AbeJRBzx (ORCPT + 99 others); Wed, 17 Oct 2018 21:55:53 -0400 Received: from mta-p2.oit.umn.edu ([134.84.196.202]:43830 "EHLO mta-p2.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbeJRBzw (ORCPT ); Wed, 17 Oct 2018 21:55:52 -0400 Received: from localhost (localhost [127.0.0.1]) by mta-p2.oit.umn.edu (Postfix) with ESMTP id 489DA279; Wed, 17 Oct 2018 17:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=umn.edu; h= content-type:content-type:subject:subject:message-id:date:date :from:from:in-reply-to:references:mime-version:received:received :received; s=20160920; t=1539799143; x=1541613544; bh=Ifx6ZwYA5w SQGoccvwX9BecsQMW3u5OcLbAA9CLp+/0=; b=Zz1q4iP2UMgJL0Mkbi7AdIosKT sJWk/yLy4QjJTseF5PCzvAqiATtLeU3B6EXFvwLcXTP+E6a2E/MBZk4Raf0I4XQX sKqLNnwl+Ok0ukffTY/KAr+qGiP7Zya+0162KC5nXXO8kGEIdmsmcmH3GZR2fapb aXJ/YncxQ56L1DDE21bvyR4WZvcSCdSCiy/9HfVIs8eB2Xtv7QfbAwKMBFrZMQNM fXnKTMJt6U7Bs3FEUb8fzksFdHIzui8r92O7neS3RJKASPpf4sj/Rryw2JfcY/i1 Y4TIrSDlG7xHh+OoWyrlba5zU/xvhq/YkSlD8v4A68RSHNeomkxHsVIerkyw== X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p2.oit.umn.edu ([127.0.0.1]) by localhost (mta-p2.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k15l3IR9XKrM; Wed, 17 Oct 2018 12:59:03 -0500 (CDT) Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: wang6495) by mta-p2.oit.umn.edu (Postfix) with ESMTPSA id 1869324D; Wed, 17 Oct 2018 12:59:03 -0500 (CDT) Received: by mail-ot1-f43.google.com with SMTP id q50so27133418otd.0; Wed, 17 Oct 2018 10:59:03 -0700 (PDT) X-Gm-Message-State: ABuFfoiWuGB7zeMcIJi9zfhhWEhEue7e8BjNbQHlCVqfgePCWf4ErKi/ 34BvGssFLqo007lY2qPcyyckd/zx/ujNcwHQu44= X-Received: by 2002:a9d:f61:: with SMTP id 88mr17954040ott.364.1539799142698; Wed, 17 Oct 2018 10:59:02 -0700 (PDT) MIME-Version: 1.0 References: <1539786725-1812-1-git-send-email-wang6495@umn.edu> <20181017094506.1b09eb64@w520.home> In-Reply-To: <20181017094506.1b09eb64@w520.home> From: Wenwen Wang Date: Wed, 17 Oct 2018 12:58:26 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] drivers/vfio: Fix a redundant copy bug To: alex.williamson@redhat.com Cc: Kangjie Lu , kvm@vger.kernel.org, open list , aik@ozlabs.ru, david@gibson.dropbear.id.au, Wenwen Wang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 17, 2018 at 10:45 AM Alex Williamson wrote: > > 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. The value in start is different from the value in minsz. So why is this 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, No problem. I will seperate these two patches. And yes, this is not tested. Thanks, Wenwen