Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4098090pxf; Tue, 23 Mar 2021 02:36:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfP1uA80cm3ZxEAtiVhDmWJmaL+172SrfLN890OOaoRt0JXXTgD/RY39+/JLVdGDUTkjo7 X-Received: by 2002:aa7:cf14:: with SMTP id a20mr3657181edy.49.1616492176697; Tue, 23 Mar 2021 02:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616492176; cv=none; d=google.com; s=arc-20160816; b=IWln7egYPrnncTdPnXEV/NOWJFrw//fxnoi1/njkpenqpNSnYwAVVd1d/nyhuOh3AP MGc/aZwr5XgKhxGFHLEAxTBuKyQEzwFrLI3VsANKenjQB/MnsqfA1DNdhrf9X7MLRS04 QlMAPuIEWC38lLztLNmJfPgu4Ks6hUg8l2JjLeF5LgeGa6fmNlmrAzu4/g/fkuWtXRvH hd2LHAhSnLS69MBxVqYqBLkbZRGjhvH21KzMjCnVC28823ls/NiWbcNZ2CGMszFwQ0GJ mn/DGJUv55IVVNUbkNysdP0W+5OGP4WeMsZ3z2mNAdLTHS11HrqOHoYil9IGE+9LCYp1 9dIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1qg3yYTweatGb9P8R1Pd7m7oUwjcHarEvoGFoJC3hqk=; b=u8JFrdFWHLncM1RWgdmcCndJsiTmK/Iwx9lkcpz0V2PJQ8A3fDtAxWE97evfjMO6AH TgDe/NFzWUEwRf1cb4mjnaL7vHk93DVw5Z/+BHq7PV1lv80qhXkFillrnWaD0gVfrh3/ l4eQHDpvTa7Qy7Jk7sYvA/Q8V+CFrXwKnHgrT8bYIglaPXDXU79rgdg0rlzJX5/yvxd2 9DY2FXAWPZfLoYZlOVkRw9HDdg5Z9UHY9lRPQ0tDfoBSno4tH4zZgnlXzEIsDuaKBd3c owLNK+bTbupX41S12XwfY4wlhxuNy7C/QkPJUR1j78ACPvtmWVNLNtxEgi23AfgNCPwZ q5sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si12690281edb.10.2021.03.23.02.35.54; Tue, 23 Mar 2021 02:36:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbhCWJcw (ORCPT + 99 others); Tue, 23 Mar 2021 05:32:52 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53197 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbhCWJci (ORCPT ); Tue, 23 Mar 2021 05:32:38 -0400 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lOdOs-0000ly-LP; Tue, 23 Mar 2021 09:32:34 +0000 Date: Tue, 23 Mar 2021 10:32:33 +0100 From: Christian Brauner To: Vivek Goyal Cc: Christian Brauner , Andreas =?utf-8?Q?Gr=C3=BCnbacher?= , Linux FS-devel Mailing List , Linux Kernel Mailing List , virtio-fs@redhat.com, Miklos Szeredi , lhenriques@suse.de, dgilbert@redhat.com, Seth Forshee , Jan Kara , Andreas Gruenbacher , Alexander Viro Subject: Re: [PATCH 1/3] posic_acl: Add a helper determine if SGID should be cleared Message-ID: <20210323093233.iyl4k6x432ytb72c@wittgenstein> References: <20210319195547.427371-1-vgoyal@redhat.com> <20210319195547.427371-2-vgoyal@redhat.com> <20210320100322.ox5gzgauo7iqf2fv@gmail.com> <20210322170111.GE446288@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210322170111.GE446288@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 22, 2021 at 01:01:11PM -0400, Vivek Goyal wrote: > On Sat, Mar 20, 2021 at 11:03:22AM +0100, Christian Brauner wrote: > > On Fri, Mar 19, 2021 at 11:42:48PM +0100, Andreas Grünbacher wrote: > > > Hi, > > > > > > Am Fr., 19. März 2021 um 20:58 Uhr schrieb Vivek Goyal : > > > > posix_acl_update_mode() determines what's the equivalent mode and if SGID > > > > needs to be cleared or not. I need to make use of this code in fuse > > > > as well. Fuse will send this information to virtiofs file server and > > > > file server will take care of clearing SGID if it needs to be done. > > > > > > > > Hence move this code in a separate helper so that more than one place > > > > can call into it. > > > > > > > > Cc: Jan Kara > > > > Cc: Andreas Gruenbacher > > > > Cc: Alexander Viro > > > > Signed-off-by: Vivek Goyal > > > > --- > > > > fs/posix_acl.c | 3 +-- > > > > include/linux/posix_acl.h | 11 +++++++++++ > > > > 2 files changed, 12 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/fs/posix_acl.c b/fs/posix_acl.c > > > > index f3309a7edb49..2d62494c4a5b 100644 > > > > --- a/fs/posix_acl.c > > > > +++ b/fs/posix_acl.c > > > > @@ -684,8 +684,7 @@ int posix_acl_update_mode(struct user_namespace *mnt_userns, > > > > return error; > > > > if (error == 0) > > > > *acl = NULL; > > > > - if (!in_group_p(i_gid_into_mnt(mnt_userns, inode)) && > > > > - !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID)) > > > > + if (posix_acl_mode_clear_sgid(mnt_userns, inode)) > > > > mode &= ~S_ISGID; > > > > *mode_p = mode; > > > > return 0; > > > > diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h > > > > index 307094ebb88c..073c5e546de3 100644 > > > > --- a/include/linux/posix_acl.h > > > > +++ b/include/linux/posix_acl.h > > > > @@ -59,6 +59,17 @@ posix_acl_release(struct posix_acl *acl) > > > > } > > > > > > > > > > > > +static inline bool > > > > +posix_acl_mode_clear_sgid(struct user_namespace *mnt_userns, > > > > + struct inode *inode) > > > > +{ > > > > + if (!in_group_p(i_gid_into_mnt(mnt_userns, inode)) && > > > > + !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID)) > > > > + return true; > > > > + > > > > + return false; > > > > > > That's just > > > > > > return !in_group_p(i_gid_into_mnt(mnt_userns, inode)) && > > > !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID); > > > > > > The same pattern we have in posix_acl_update_mode also exists in > > > setattr_copy and inode_init_owner, and almost the same pattern exists > > > in setattr_prepare, so can this be cleaned up as well? The function > > > also isn't POSIX ACL specific, so the function name is misleading. > > > > Good idea but that should probably be spun into a separate patchset that > > only touches the vfs parts. > > IIUC, suggestion is that I should write a VFS helper (and not posix > acl helper) and use that helper at other places too in the code. If there are other callers outside of acls (which should be iirc) then yes. > > I will do that and post in a separate patch series. Yeah, I think that makes more sense to have this be a separate change instead of putting it together with the fuse change if it touches more than one place. Thanks! Christian