Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5816183rwl; Tue, 11 Apr 2023 10:17:40 -0700 (PDT) X-Google-Smtp-Source: AKy350ZO43EHFuVMSb4xIu8qmxnw01ROFF5bBs2h2TsFjnzsukUyaEdeh1BmpZyFLj41oHn2P7HN X-Received: by 2002:a17:903:888:b0:1a1:bff4:4a06 with SMTP id kt8-20020a170903088800b001a1bff44a06mr3084368plb.24.1681233460380; Tue, 11 Apr 2023 10:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681233460; cv=none; d=google.com; s=arc-20160816; b=ppGj+pxr1FQmPUAWfcVL6/anTeGEm7ey0jGKH7+okIcYFrS6kxakD3hrnqYPZoczkK bzXyjNyoN0GgWFQpS2kiAtq1AuXJG8VsjbPg/MzpRtmAKEuWamh0CatFouRZgR/e1ToB kKAu5jUc5Y8W/6hGnBefNlrcft969KQZopLpoHSEIzRKhZSyjiVQin1AiuJR6w7T36Kv uHQ+yX0krmrDSa121XPtLIH6ffRIc6N50I4r/WZeRI53BaFBqaPewHmc0i00T0XxbMd3 PTSHpIsbCb4b962ktgpLswJUUlg7OavyfO+Gad04FrtVDiUkwFm0Exm7VspHaSXuKWLa Fjqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=EV6cfMT7nUFO+GhkngWs75MUy3suilNcezIYIXwpKok=; b=DGP5RRPYDlbK0XJMqxgc+/Q9AwlCnkaeAFHE02B7B80GiuVrzg7KufEUWhoNZG1c1U bCk00xnUvzqA/qU+DC4r6YLNIjsRKrNiRAx4r2NDASwQFSypH3fxjmr2BGWCD4wa9qrm vI+fI5gZdQrvCLU5IkzJcls3uqNf6ztDbAPAOAb+8oQkDKkMfoLzv9woPWsjOMawzPiu Cz2DjwsJbU1r12WJ50Ive66pPEMGPAMTl0gIL3/DMTZ/vg/pvz9uu4I0RHkbOmWGptDO Hb44YuNxwL/Ntg07eJx+oZuvzhPQnPhAFsNwQjj9EGj/y0LU3Hthz3WytQhUJF2/Oqgk hEnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D0mVuMS2; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a170902fe8200b001a1e0fd406csi14264154plm.217.2023.04.11.10.17.23; Tue, 11 Apr 2023 10:17:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D0mVuMS2; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbjDKRLO (ORCPT + 99 others); Tue, 11 Apr 2023 13:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbjDKRLM (ORCPT ); Tue, 11 Apr 2023 13:11:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE71469F; Tue, 11 Apr 2023 10:11:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BBB6E629B1; Tue, 11 Apr 2023 17:11:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 726DBC4339B; Tue, 11 Apr 2023 17:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681233061; bh=Z1vS1CZUHcjyBePBOAorksWeXWINj9Fg7ftzrrGoqxU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=D0mVuMS2zEpPUjigFlE+EG/i7FtUIzq9DWNMZrbNP02GSjlSx+VrJFn659veZib9A Pmghq1klwiischli2dMlSeIv9OCE2CZx3Ko3oQzqtb14e91cPTupLaGRmpQlJubhFm kB2g5LdxaWodBIWODzACWRjkUuggJV/FaImRE0szEgFpeC9v44Y2LZEL7yJIeP0/mn mu9VeRTtrAfLG8QpXohhbNRoGzERHlwNfon4EFbA8eWo8uW+HnxqAz3dGG5qqaK7DV 15F7jyBTlSkcjgeH4Bz0C34vVHFDoIaIFgptFqHLqvmLAsaOku76d71SPmLorUwPQT m2h8+2C0ItDUw== Message-ID: Subject: Re: [PATCH v2] nfs: use vfs setgid helper From: Jeff Layton To: Christian Brauner , Trond Myklebust , Anna Schumaker , Chuck Lever Cc: Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Date: Tue, 11 Apr 2023 13:10:59 -0400 In-Reply-To: <20230313-fs-nfs-setgid-v2-1-9a59f436cfc0@kernel.org> References: <20230313-fs-nfs-setgid-v2-1-9a59f436cfc0@kernel.org> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Tue, 2023-03-14 at 12:51 +0100, Christian Brauner wrote: > We've aligned setgid behavior over multiple kernel releases. The details > can be found in the following two merge messages: > cf619f891971 ("Merge tag 'fs.ovl.setgid.v6.2') > 426b4ca2d6a5 ("Merge tag 'fs.setgid.v6.0') > Consistent setgid stripping behavior is now encapsulated in the > setattr_should_drop_sgid() helper which is used by all filesystems that > strip setgid bits outside of vfs proper. Switch nfs to rely on this > helper as well. Without this patch the setgid stripping tests in > xfstests will fail. >=20 > Signed-off-by: Christian Brauner (Microsoft) > --- > Changes in v2: > - Christoph Hellwig : > * Export setattr_should_sgid() so it actually can be used by filesystem= s > - Link to v1: https://lore.kernel.org/r/20230313-fs-nfs-setgid-v1-1-5b1fa= 599f186@kernel.org > --- > fs/attr.c | 1 + > fs/internal.h | 2 -- > fs/nfs/inode.c | 4 +--- > include/linux/fs.h | 2 ++ > 4 files changed, 4 insertions(+), 5 deletions(-) >=20 > diff --git a/fs/attr.c b/fs/attr.c > index aca9ff7aed33..d60dc1edb526 100644 > --- a/fs/attr.c > +++ b/fs/attr.c > @@ -47,6 +47,7 @@ int setattr_should_drop_sgid(struct mnt_idmap *idmap, > return ATTR_KILL_SGID; > return 0; > } > +EXPORT_SYMBOL(setattr_should_drop_sgid); > =20 > /** > * setattr_should_drop_suidgid - determine whether the set{g,u}id bit ne= eds to > diff --git a/fs/internal.h b/fs/internal.h > index dc4eb91a577a..ab36ed8fa41c 100644 > --- a/fs/internal.h > +++ b/fs/internal.h > @@ -259,8 +259,6 @@ ssize_t __kernel_write_iter(struct file *file, struct= iov_iter *from, loff_t *po > /* > * fs/attr.c > */ > -int setattr_should_drop_sgid(struct mnt_idmap *idmap, > - const struct inode *inode); > struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns); > struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap); > void mnt_idmap_put(struct mnt_idmap *idmap); > diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c > index 222a28320e1c..97a76706fd54 100644 > --- a/fs/nfs/inode.c > +++ b/fs/nfs/inode.c > @@ -717,9 +717,7 @@ void nfs_setattr_update_inode(struct inode *inode, st= ruct iattr *attr, > if ((attr->ia_valid & ATTR_KILL_SUID) !=3D 0 && > inode->i_mode & S_ISUID) > inode->i_mode &=3D ~S_ISUID; > - if ((attr->ia_valid & ATTR_KILL_SGID) !=3D 0 && > - (inode->i_mode & (S_ISGID | S_IXGRP)) =3D=3D > - (S_ISGID | S_IXGRP)) > + if (setattr_should_drop_sgid(&nop_mnt_idmap, inode)) > inode->i_mode &=3D ~S_ISGID; > if ((attr->ia_valid & ATTR_MODE) !=3D 0) { > int mode =3D attr->ia_mode & S_IALLUGO; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index c85916e9f7db..af95b64fc810 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2675,6 +2675,8 @@ extern struct inode *new_inode(struct super_block *= sb); > extern void free_inode_nonrcu(struct inode *inode); > extern int setattr_should_drop_suidgid(struct mnt_idmap *, struct inode = *); > extern int file_remove_privs(struct file *); > +int setattr_should_drop_sgid(struct mnt_idmap *idmap, > + const struct inode *inode); > =20 > /* > * This must be used for allocating filesystems specific inodes to set >=20 > --- > base-commit: eeac8ede17557680855031c6f305ece2378af326 > change-id: 20230313-fs-nfs-setgid-659410a10b25 >=20 Reviewed-by: Jeff Layton