Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3594902pxf; Mon, 22 Mar 2021 10:03:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6Z9s3MRYcBTWxJ9WY6PAkQv9OS4uLY57ybbU0KSCa88aoUevd20lHYwBwAcgmAt3ZiFho X-Received: by 2002:a17:906:4e99:: with SMTP id v25mr788191eju.532.1616432601528; Mon, 22 Mar 2021 10:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616432601; cv=none; d=google.com; s=arc-20160816; b=kjZEv2QQGPBJ6B8TN+0VZpe3XOJKY/XQuqfYZjZwFu4ilL3Pk1k3IDB2kHjYX0dT5T Nx/tzkH+Q2s+4XwhAxKMiQHh/5Ot0TGRdHnKgrpwoP6l6PTc50EwLiPurIC9jeGTNFNg ciQwf3dA4icaCFQn4mVkRSUMMEGHQATrz5tVwDzDNDfgLslroR5kyxyf3/VkuWEcRcp+ LPE29Vb6gx889341MDB7qnrdg+CnkwWlF2YJdHfQVp1Efv173YS+vdxwY2bBuO+rl6r9 Bq8NwIpDH00Dnw3rAgFEUVtuNttaY/ssRmQMseK1F/cEuoJOLrYr8+RE/ddwzygSTvsn wTSA== 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:dkim-signature; bh=kI6JCUton9Pw1WTmpNMH1+Wj/jifPkleYuBOY5L9rd8=; b=eU56p+IPR27xrm8+zXY+BKC6dOFtZhMKsB85Izsz0+6QBBNPRhKlbN5Z2zlACL5tRa boSB3gsaBFwr8TRIXzL5FWe9oUvyvNlbNvD/rcnJx++IoNruW4J5kLjkEf9siJtz3Oqu tO/BNOdY1+SiMT99Jefrx/MAqtoqZVVZrFZ5NJvaA5SYPTgfnt+3+Ue/EhzJBrlXwZTf gtG9ytZthtT9gPbojr+ftji/Vtu+c92LDPiXU0Pon0Y/p+idLthizDLG5OIvA6aOgpr+ G5i0IcC9DyJ6AURo/3X8NDH1iTgDzoXytRvbeDX9jVRNzNuiHHzkD0yt8iXfuIr98onb g22g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rp6BH5UC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si11640735eds.83.2021.03.22.10.02.59; Mon, 22 Mar 2021 10:03:21 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rp6BH5UC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230198AbhCVRBs (ORCPT + 99 others); Mon, 22 Mar 2021 13:01:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35349 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231518AbhCVRBT (ORCPT ); Mon, 22 Mar 2021 13:01:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616432478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kI6JCUton9Pw1WTmpNMH1+Wj/jifPkleYuBOY5L9rd8=; b=Rp6BH5UChMLPZvUrspq7nDNAALV4kApmYZhuVLOnIQN0eUPnTTQGxc5BYt+aOnbSd7Y4A4 OVVGVUyBT4PfhEw4WxXZh9Y/BKE6pKFJ2TdwojmaJqkhuQ0hTj38xwoos7VKVcVh+YMdO8 patTlbgxcxbmSZrATbmg87uo6+2VGAw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-eTs5gemHNB2cz_t9qTRHAQ-1; Mon, 22 Mar 2021 13:01:17 -0400 X-MC-Unique: eTs5gemHNB2cz_t9qTRHAQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20406513F; Mon, 22 Mar 2021 17:01:15 +0000 (UTC) Received: from horse.redhat.com (ovpn-114-132.rdu2.redhat.com [10.10.114.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 066662B0A9; Mon, 22 Mar 2021 17:01:11 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 603BD220BCF; Mon, 22 Mar 2021 13:01:11 -0400 (EDT) Date: Mon, 22 Mar 2021 13:01:11 -0400 From: Vivek Goyal To: Christian Brauner Cc: Andreas =?iso-8859-1?Q?Gr=FCnbacher?= , 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: <20210322170111.GE446288@redhat.com> References: <20210319195547.427371-1-vgoyal@redhat.com> <20210319195547.427371-2-vgoyal@redhat.com> <20210320100322.ox5gzgauo7iqf2fv@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210320100322.ox5gzgauo7iqf2fv@gmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. I will do that and post in a separate patch series. Thanks Vivek