Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3863199imm; Mon, 8 Oct 2018 10:44:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV63/dVKRcgLROpxUG5d5SPTzSpyBtBJ8vIR9xy1lwV6UcunWC2RuykrSfX4LDlOAYCGkg3u1 X-Received: by 2002:a63:3e06:: with SMTP id l6-v6mr21045302pga.96.1539020640623; Mon, 08 Oct 2018 10:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539020640; cv=none; d=google.com; s=arc-20160816; b=eYD1MiOzfRXLy9w/kTRtqcm4V7j68HbVaxoNzdu+31LPWRqUcslJTRGeWe6cEqkeTs Fo4JS1t22iGmfpwkgmnXB3ghYB9I+MsjqQipm4zdXMD2f7b4XMFWkK+xJGyWWMUIMLa2 25ofr4mXdzESdEdlNOgsOYSAHTNUqZ1ylJir796N87HsivcXKYVoxUBJHLpVvJDSmJ/e 7QRv6DSlQEaZCozkZvW3sK8FdR+lI6KOJPbXKghK05h4HkCqg5u9st4xLza7Ht2RwvGY /LAo2nLF0vfRj0jt+Szr6mt7WbnkCwTb/vKpIGKeo20k/1mkRETjHr8S9lGyQed7y56k lqsA== 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=F++hbfZmr/dY/ApYk+/zedivoxUWR3r929y5QrmYHus=; b=Hy3OvmwLs62ZW7G9TWETPW2FOPvsJw3ggolrGFVY9Rz/n0yJNq9Yd4rbsZcFS7BtpU e1Z6UXknroAyZYyXJ9I9miNtz14O7h4Lim85eFdTPPZ/t+1Y72TKCEyWosud28NY4G6X fCxbAwCXEVRSYM0rvT85aA+mA6AwUgfjtxf8Z/iHBqKvU1yswiZQWxUwBkOyXTViH3+k cD70OjU9cp6InNMdXwhhwB2Fv93WshEaQXev5MECoEpkFHbgmED8VrL0dn+bjFN5dKCk 4ufAnFtnqF/CUwZKL2LmDBgSnYRtekvEFgI/ZYqQXC/w8XoUVy/ZwwsImAYoMCazRZk7 c3vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=20160920 header.b=W37Hj22V; 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 f62-v6si9809662plf.288.2018.10.08.10.43.46; Mon, 08 Oct 2018 10:44:00 -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=W37Hj22V; 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 S1726582AbeJIA4J (ORCPT + 99 others); Mon, 8 Oct 2018 20:56:09 -0400 Received: from mta-p2.oit.umn.edu ([134.84.196.202]:60742 "EHLO mta-p2.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJIA4I (ORCPT ); Mon, 8 Oct 2018 20:56:08 -0400 Received: from localhost (localhost [127.0.0.1]) by mta-p2.oit.umn.edu (Postfix) with ESMTP id 4E2F1629; Mon, 8 Oct 2018 17:43:18 +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=1539020598; x=1540834999; bh=6+crBoWQ0W Eqsb+PFYKpnRZPl03KiO+SyHIHOzzkodc=; b=W37Hj22VPtfJdGW2gKfmYUY0+T vUiMxC65poff67psU617vGh4XgK3LCjdZtfFMu0pNsNeE32CdfHsCbsDQktnBzZ2 KyfYoVBcGpnmZZtIxCU8KwcTCuPQge9FTbJP8RjGNHS+K+Ozdj+LGNwTmDmF3Ljq bMjz/HMx3zbyK7dCUuNir/+rLA/EAUMa1lfAKUAFHgFHMWZVyVIt3nReqTEX05Aw eNV8iOUN1t30pk02QGpC7U7itlGQ3wlOTXcyJcbFFbDH3XJz6v907DxIRzmHQefk 693N3tlcApoDWegT6+FxEpI0gQmU/hgPT7GQVmRs1GrJrHQi6PjTAiQy6RTw== 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 NOdrSd3eNi2M; Mon, 8 Oct 2018 12:43:18 -0500 (CDT) Received: from mail-it1-f172.google.com (mail-it1-f172.google.com [209.85.166.172]) (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 0F41C60A; Mon, 8 Oct 2018 12:43:18 -0500 (CDT) Received: by mail-it1-f172.google.com with SMTP id l191-v6so12568372ita.4; Mon, 08 Oct 2018 10:43:18 -0700 (PDT) X-Gm-Message-State: ABuFfogF3JlI1LzXqGnwQPWXtqvJXDSOrZ04Q6y9GsaBArgarNUayC7r Pr/MQSRHEJ4rx0TwInwnrjeYH6i/FrgOjVybwTY= X-Received: by 2002:a02:b476:: with SMTP id w51-v6mr18270996jaj.140.1539020597741; Mon, 08 Oct 2018 10:43:17 -0700 (PDT) MIME-Version: 1.0 References: <1538923466-29705-1-git-send-email-wang6495@umn.edu> <20181008104350.7776c729@w520.home> In-Reply-To: <20181008104350.7776c729@w520.home> From: Wenwen Wang Date: Mon, 8 Oct 2018 12:42:40 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] drivers/vfio: Fix a redundant copy bug To: alex.williamson@redhat.com Cc: Kangjie Lu , kvm@vger.kernel.org, open list , 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 Mon, Oct 8, 2018 at 11:43 AM Alex Williamson wrote: > > Hi, > > On Sun, 7 Oct 2018 09:44:25 -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 and security reasons, the redundant part of the second copy > > should be removed. > > Redundant, yes. Performance-wise it's 12 bytes on a non-performance > path, so theoretically yes, but in practice maybe it's a simplicity > trade-off. Security? I don't see it, please explain. > > > This patch removes such a part in the second copy. It only copies the 'err' > > information from the buffer 'arg'. > > > > Signed-off-by: Wenwen Wang > > --- > > drivers/vfio/vfio_spapr_eeh.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c > > index 38edeb4..5bc4b60 100644 > > --- a/drivers/vfio/vfio_spapr_eeh.c > > +++ b/drivers/vfio/vfio_spapr_eeh.c > > @@ -86,10 +86,10 @@ 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) > > + if (op.argsz < sizeof(op)) > > return -EINVAL; > > The original code is written such that new operations can be added, > possibly with new entries in the struct vfio_eeh_pe_op union, which > might change sizeof(op) to be more than necessary for a > VFIO_EEH_PE_INJECT_ERR op. Existing userspace suddenly wouldn't work > without effectively reverting this change. This is a subtle dependency > that is not worth the above code change, imo. > > > - if (copy_from_user(&op, (void __user *)arg, minsz)) > > + if (copy_from_user(&op.err, (char __user *)arg + > > + minsz, sizeof(op.err))) > > return -EFAULT; > > Please rework with the assumption that the union in struct > vfio_eeh_pe_op can be expanded and must not break existing userspace. Thanks for your suggestion. I will resubmit the patch. Wenwen > Thanks, > > Alex