Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1241440imm; Sun, 15 Jul 2018 02:54:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe1Y8klNWQnRAT0YUKjYxBTxc8SifCPFg8z3Kfrmf5L2+NBI/+7xgaxpLXLgx6ObZzhGps8 X-Received: by 2002:a63:743:: with SMTP id 64-v6mr12308110pgh.216.1531648455472; Sun, 15 Jul 2018 02:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531648455; cv=none; d=google.com; s=arc-20160816; b=Hk+GchnWyG9dK04rL14VUsvvTS702nsL6WlW13ahyUdMevLeAUVaJgIg5kuVvx+fLS OVdpSmjmzb4GhkenQ8CC6qAFttMlXm8T2XSxiszmyFjVgUE5VUsY4mfoXH3XdPXLQibp oQtJhhxmNOFDYEpCT4O+fLZkNKDmrWg4JLbRh528pq8WJQ8zO2CCnvBRr0PxSeNm40pF 8tmb6cMsdnGNA9s0R/g9KLXvqOpec8KUWp8cFp9TcsedI3FKQ4V8YmCLQQVyWNlmmjme zP20AbdpxLV8s02anZvg3J7CcRC1V9x16nMLA5HcIbCPHOr92is+FlPMm73U+Fduxaar iLZA== 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 :arc-authentication-results; bh=IgrugwOwyoY56WQp208Xwr17ST0En17/+ZBuCRyokes=; b=omeq37JgthXertrgIH3a0pteQq210y0fhJbGHp9hISIGxsYggIqY41pOIqG6y0I8K5 +c6T8T5thFYIetJdQanquDeDQWe4GkY9dfgCkudp4sNSb8C9aQwye2SQUIceytzV/JP8 8H2neaw429w+VcfIGQg4dR56yOMPQ5SzZMUIGZMWz/VDpf9bNoOzYWJOOQQHP6d0c7im VKQK0IBsSymPjm1Vo/eEmsMJSC+QL2nXBPyz3s2iLUTGzzgMSfueImv2+w5pkVXlMEay VFCaKFNZrgHE+RsVygefAdKedx/PZgNM72XjoUB3uwcf1kitPe0kfg5puupmv5R9tQ5u n/QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PJumkcX9; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w19-v6si28268553pfn.160.2018.07.15.02.54.00; Sun, 15 Jul 2018 02:54: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; dkim=pass header.i=@chromium.org header.s=google header.b=PJumkcX9; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726221AbeGOKPt (ORCPT + 99 others); Sun, 15 Jul 2018 06:15:49 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:43150 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbeGOKPt (ORCPT ); Sun, 15 Jul 2018 06:15:49 -0400 Received: by mail-ed1-f68.google.com with SMTP id b20-v6so2224955edt.10 for ; Sun, 15 Jul 2018 02:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IgrugwOwyoY56WQp208Xwr17ST0En17/+ZBuCRyokes=; b=PJumkcX9A4lGd6E0+02L5SH7G0cyUPth61Z+5oHVlFJkoClanH4IVNUlJeHcsG0nHD ATAVf7jIHLIv+ogzMwjECpdBNsQzhqffZU6AuBHbYKikLIkT0iRR2Bi0W5L8SfnQM05k +egD9l4Sgwogl8dYJypJNPTntKZcTjgU3MpA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IgrugwOwyoY56WQp208Xwr17ST0En17/+ZBuCRyokes=; b=XQI8ETVecDo1/2A83iQ3X1NF5vLvZYrmU0uhZZXoQJtpX7I9rSDffPu6WPv9Meqazc U+Os3K/V8kxHR36TtLt29ZeW5/YJfUlgUZA6jTGQaNYsycfZBFi/cIxLuBsIP1+LHMkJ /fQm1ucJQJ/wC+zB+WJfoI9ljqn/P3IewZqLJPLpdPs+KJtIXWuR2Yfe664F8ozJ2JBO IpPoiPlI0KeUj5i5Hbbc5gzmNPnLLuINY1kaKRnzppnIKqSJiG+vdAaf/LKc9hbaTWGW etaL6x6QBbMsD/yNAB7UpXoDY/3rPFV0xFsTovejo9QJfrLkRrftu6tfyCwd4UXmSRIP 4c9A== X-Gm-Message-State: AOUpUlEs2wLCdZ2g12a3RP+x1sNl8Wcg9BVe6Da03udCeOf9dVUBox20 herNmkJLyiV9UA27PncXOQ6BxeQkID0= X-Received: by 2002:a50:cd07:: with SMTP id z7-v6mr13607792edi.60.1531648404407; Sun, 15 Jul 2018 02:53:24 -0700 (PDT) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com. [209.85.221.47]) by smtp.gmail.com with ESMTPSA id o2-v6sm13061106edd.84.2018.07.15.02.53.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Jul 2018 02:53:23 -0700 (PDT) Received: by mail-wr1-f47.google.com with SMTP id r16-v6so29000008wrt.11 for ; Sun, 15 Jul 2018 02:53:23 -0700 (PDT) X-Received: by 2002:adf:8325:: with SMTP id 34-v6mr9084484wrd.67.1531648402720; Sun, 15 Jul 2018 02:53:22 -0700 (PDT) MIME-Version: 1.0 References: <20180714055816.223754-1-toddpoynor@gmail.com> <20180714055816.223754-12-toddpoynor@gmail.com> <20180715090544.GC23333@kroah.com> <20180715093216.GA16003@kroah.com> In-Reply-To: <20180715093216.GA16003@kroah.com> From: Dmitry Torokhov Date: Sun, 15 Jul 2018 12:53:09 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 11/18] staging: gasket: always allow root open for write To: Greg Kroah-Hartman Cc: devel@driverdev.osuosl.org, toddpoynor@gmail.com, frankhu@chromium.org, jnjoseph@google.com, lkml , Simon Que , rspringer@google.com, Guenter Roeck , toddpoynor@google.com 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 Sun, Jul 15, 2018 at 12:32 PM Greg Kroah-Hartman wrote: > > On Sun, Jul 15, 2018 at 12:11:47PM +0300, Dmitry Torokhov wrote: > > On Sun, Jul 15, 2018 at 12:05 PM Greg Kroah-Hartman > > wrote: > > > > > > On Fri, Jul 13, 2018 at 10:58:09PM -0700, Todd Poynor wrote: > > > > From: Todd Poynor > > > > > > > > Always allow root to open device for writing. > > > > > > > > Drop special-casing of ioctl permissions for root vs. owner. > > > > > > > > Reported-by: Dmitry Torokhov > > > > Signed-off-by: Zhongze Hu > > > > Signed-off-by: Todd Poynor > > > > --- > > > > drivers/staging/gasket/apex_driver.c | 9 +++------ > > > > drivers/staging/gasket/gasket_core.c | 8 +++++--- > > > > drivers/staging/gasket/gasket_ioctl.c | 15 ++++++--------- > > > > 3 files changed, 14 insertions(+), 18 deletions(-) > > > > > > > > diff --git a/drivers/staging/gasket/apex_driver.c b/drivers/staging/gasket/apex_driver.c > > > > index b1318482ba65..ffe11d8168ea 100644 > > > > --- a/drivers/staging/gasket/apex_driver.c > > > > +++ b/drivers/staging/gasket/apex_driver.c > > > > @@ -644,13 +644,10 @@ static bool is_gcb_in_reset(struct gasket_dev *gasket_dev) > > > > static uint apex_ioctl_check_permissions(struct file *filp, uint cmd) > > > > { > > > > struct gasket_dev *gasket_dev = filp->private_data; > > > > - int root = capable(CAP_SYS_ADMIN); > > > > - int is_owner = gasket_dev->dev_info.ownership.is_owned && > > > > - current->tgid == gasket_dev->dev_info.ownership.owner; > > > > + fmode_t write; > > > > > > > > - if (root || is_owner) > > > > - return 1; > > > > - return 0; > > > > + write = filp->f_mode & FMODE_WRITE; > > > > > > Ok, this is insane. You don't change, or check, the permissions on a > > > file handle while it is already open, as you only check the permissions > > > on OPEN, not on WRITE. See the recent rant from Linus on the linux-api > > > list for yet-another-long-threaad in which he explains this. > > > > > > So this whole ioctl can just be removed, it is totally crazy and wrong > > > and should just be removed. > > > > No, the code checks whether the requested ioctl command is compatible > > with the mode the file handle was open with. There are some ioctls > > that are allowed on file handle opened for read and others that > > require file handle to be opened for write. That is all. It does not > > change permissions past open. > > That's really not obvious here :) > > And is odd on a whole other set of "crazy design", but ok, let's let it > live for now. Are you talking about ioctl still or something else? Because such ioctl handling is quite common, take a look at blkdev for example, where disacrd ioctl is only allowed when device is open for writing. > > I can't wait for people to just realize this whole "new" subsystem can > be replaced with UIO, but that's a topic for a different thread... Yes, that is true and that is why I am not sure why we are going through all this staging exercise. As far as I understand we'd still need to have quite a bit of kernel code so that we can safely program DMA controller (it does not look like uio_dmem_genirq.c is sufficient as is for gasket needs), but that should be solvable. Thanks, Dmitry