Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1074157rwe; Thu, 1 Sep 2022 12:04:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4EfqAHJOi5iLBcyxg60vc8+dPd6Lhm4MjTCpUwib+GtA7ph4xj/plv4W04YMYp41S3i19J X-Received: by 2002:a17:907:7394:b0:73d:cd06:aacd with SMTP id er20-20020a170907739400b0073dcd06aacdmr25762943ejc.180.1662059069999; Thu, 01 Sep 2022 12:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662059069; cv=none; d=google.com; s=arc-20160816; b=pJQ5whOwCHSd7rA86HgwQ9lgk0bEbfw2j7tjjsCRvWV+V+KMvYJejnvrXNuZn2gm1P najsnAeudOdgBR2lUAewM60rJ2Ue1hUxAqAVtq4gC2sSFYXAoc5P0zh+diFpfCT4NM/6 ajeEFVEefePRV2w9WRvkoFG4LBHHnG6DXQ7Wkkv0h0yXgWwyq+dsFX0dTCY0vtb9vjr5 mTGeQsL5u4s6YNCCJ1lEPqm2RDlJ5+y1OgqctX4BtJ2YEkg2XQmiLVqaIxaVv0cg+7WJ mamgQpEgSquXvyl66XHeF7u1ya5cfmcruKHUwV7EuuFebGSWY+RbQt4uUtllgn2DBCge r1KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wEDFLR9s/J1BJ/smF3b5Dr+Av+Fe8W69vH4j6IUZc3s=; b=l57dcVNsvPfEHw9Epq/3oGjBDbDoWRHivn9lBBVf+NGzHvMwxGUTL/sedpHnL3YVju QnXjDvxf6GfKwRfpf2sLK91KXmHCJT2pnFTctLX2RdSJbEJ9g9HBO0J2t/fVl7dRxvbK EeCT2+csI+K1KLuL+DQbk1vm+7XI+BySQSvay0P4kgb6B3aDhgYolMxHEeloytfGWRUT qBvSvGSwRguU635W8Hl17SZFo+y6RuxfLWMEN/aA0lA+nfxHEKfUGl7/Pb9j88LqJGhp PzdgWti5cjepg3RWLc7XL6Eaw3m10wDeyy48pCOAGl0LRMQWh1ZhAT5bAwb3FcChmwhj L4fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fHqcI/9B"; 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 u2-20020a50eac2000000b004486942c312si1995960edp.571.2022.09.01.12.03.48; Thu, 01 Sep 2022 12:04:29 -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="fHqcI/9B"; 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 S231443AbiIASxm (ORCPT + 99 others); Thu, 1 Sep 2022 14:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233277AbiIASxg (ORCPT ); Thu, 1 Sep 2022 14:53:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFC4A95E62 for ; Thu, 1 Sep 2022 11:53:35 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5D6DEB828F0 for ; Thu, 1 Sep 2022 18:53:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B6A0C433B5 for ; Thu, 1 Sep 2022 18:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662058413; bh=GfMeomvV0eKE2x9wgjK+kIOmvOJNyrdvetmlWKVMYuU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fHqcI/9BWj0y6OJfsWIw19ZlFI84LEVxJUrRtFzjXtpEi3CQthuAMvxPqlUkNMeHm 2zlh4RsqzplQF8x2oRsx+uPVNXsIefVbapdoI85r41wrqekIoWvMUjXyCDgPCYXsQ1 NnVjhsKC5tZFC4xdzcDKsFzyvwAkPYhYN0cgaSNs3f1ePYntBHXaV2VLX2RkHFnA+i YyeVH0UdYVZMGztOOkeA40/kP/izWzx3ji+TXvs467gu4n66j7B9Lc+c6G7OHPpU2L CFDwq4K3ygjKSdSnaShUZV/tsnSECT5oHou5jRSJlYV6J5Vtuudfknven5YsoJNv8N CzSj/lN42q6DQ== Received: by mail-wm1-f49.google.com with SMTP id h204-20020a1c21d5000000b003a5b467c3abso1892799wmh.5 for ; Thu, 01 Sep 2022 11:53:32 -0700 (PDT) X-Gm-Message-State: ACgBeo1NUNhhmpsEt6oINDpQWbJTSuzCW9y1bfafyrEjvkvyxWeSEgvT NBUsLFScZ9R6FK1HeN2SUZXsaLc/7HyY7vrpyVg= X-Received: by 2002:a05:600c:28c8:b0:3a8:40bb:be4c with SMTP id h8-20020a05600c28c800b003a840bbbe4cmr359167wmd.28.1662058411548; Thu, 01 Sep 2022 11:53:31 -0700 (PDT) MIME-Version: 1.0 References: <20220901180503.1347290-1-anna@kernel.org> <50a371e51b76469671ede8d47201eb8d01dd5720.camel@hammerspace.com> In-Reply-To: <50a371e51b76469671ede8d47201eb8d01dd5720.camel@hammerspace.com> From: Anna Schumaker Date: Thu, 1 Sep 2022 14:53:15 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] NFSv4.2: Update mode bits after ALLOCATE and DEALLOCATE To: Trond Myklebust Cc: "linux-nfs@vger.kernel.org" , "cuiyue-fnst@fujitsu.com" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Thu, Sep 1, 2022 at 2:47 PM Trond Myklebust wrote: > > On Thu, 2022-09-01 at 14:22 -0400, Trond Myklebust wrote: > > On Thu, 2022-09-01 at 14:05 -0400, Anna Schumaker wrote: > > > From: Anna Schumaker > > > > > > The fallocate call invalidates suid and sgid bits as part of normal > > > operation. We need to mark the mode bits as invalid when using > > > fallocate > > > with an suid so these will be updated the next time the user looks > > > at > > > them. > > > > > > This fixes xfstests generic/683 and generic/684. > > > > > > Reported-by: Yue Cui > > > Fixes: 913eca1aea87 ("NFS: Fallocate should use the > > > nfs4_fattr_bitmap") > > > Signed-off-by: Anna Schumaker > > > --- > > > fs/nfs/internal.h | 25 +++++++++++++++++++++++++ > > > fs/nfs/nfs42proc.c | 13 ++++++++++++- > > > fs/nfs/write.c | 25 ------------------------- > > > 3 files changed, 37 insertions(+), 26 deletions(-) > > > > > > diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h > > > index 27c720d71b4e..898dd95bc7a7 100644 > > > --- a/fs/nfs/internal.h > > > +++ b/fs/nfs/internal.h > > > @@ -606,6 +606,31 @@ static inline gfp_t nfs_io_gfp_mask(void) > > > return GFP_KERNEL; > > > } > > > > > > +/* > > > + * Special version of should_remove_suid() that ignores > > > capabilities. > > > + */ > > > +static inline int nfs_should_remove_suid(const struct inode > > > *inode) > > > +{ > > > + umode_t mode = inode->i_mode; > > > + int kill = 0; > > > + > > > + /* suid always must be killed */ > > > + if (unlikely(mode & S_ISUID)) > > > + kill = ATTR_KILL_SUID; > > > + > > > + /* > > > + * sgid without any exec bits is just a mandatory locking > > > mark; leave > > > + * it alone. If some exec bits are set, it's a real sgid; > > > kill it. > > > + */ > > > + if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) > > > + kill |= ATTR_KILL_SGID; > > > + > > > + if (unlikely(kill && S_ISREG(mode))) > > > + return kill; > > > + > > > + return 0; > > > +} > > > + > > > /* unlink.c */ > > > extern struct rpc_task * > > > nfs_async_rename(struct inode *old_dir, struct inode *new_dir, > > > diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c > > > index 068c45b3bc1a..23023ddf75d1 100644 > > > --- a/fs/nfs/nfs42proc.c > > > +++ b/fs/nfs/nfs42proc.c > > > @@ -56,6 +56,7 @@ static int _nfs42_proc_fallocate(struct > > > rpc_message > > > *msg, struct file *filep, > > > struct nfs42_falloc_res res = { > > > .falloc_server = server, > > > }; > > > + unsigned int invalid = 0; > > > int status; > > > > > > msg->rpc_argp = &args; > > > @@ -78,10 +79,20 @@ static int _nfs42_proc_fallocate(struct > > > rpc_message *msg, struct file *filep, > > > > > > status = nfs4_call_sync(server->client, server, msg, > > > &args.seq_args, &res.seq_res, 0); > > > + > > > + if (!res.falloc_fattr->valid) > > > + invalid |= NFS_INO_INVALID_ATTR; > > Oh wait... We shouldn't need this.^^^^^^^^^ > nfs_post_op_update_inode_force_wcc() will do the right thing for you > here. Sure. I can remove that and put everything under the "if (status == 0)". Anna > > > > + if (nfs_should_remove_suid(inode)) > > > + invalid |= NFS_INO_INVALID_MODE; > > > + if (invalid) { > > > + spin_lock(&inode->i_lock); > > > + nfs_set_cache_invalid(inode, NFS_INO_INVALID_MODE); > > > + spin_unlock(&inode->i_lock); > > > + } > > > > This all really wants to go into the 'if (status == 0)' below. > > > + > > > if (status == 0) > > > status = nfs_post_op_update_inode_force_wcc(inode, > > > > > > res.falloc_fattr); > > > - > > > if (msg->rpc_proc == > > > &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE]) > > > trace_nfs4_fallocate(inode, &args, status); > > > else > > > diff --git a/fs/nfs/write.c b/fs/nfs/write.c > > > index 1843fa235d9b..f41d24b54fd1 100644 > > > --- a/fs/nfs/write.c > > > +++ b/fs/nfs/write.c > > > @@ -1496,31 +1496,6 @@ void nfs_commit_prepare(struct rpc_task > > > *task, > > > void *calldata) > > > NFS_PROTO(data->inode)->commit_rpc_prepare(task, data); > > > } > > > > > > -/* > > > - * Special version of should_remove_suid() that ignores > > > capabilities. > > > - */ > > > -static int nfs_should_remove_suid(const struct inode *inode) > > > -{ > > > - umode_t mode = inode->i_mode; > > > - int kill = 0; > > > - > > > - /* suid always must be killed */ > > > - if (unlikely(mode & S_ISUID)) > > > - kill = ATTR_KILL_SUID; > > > - > > > - /* > > > - * sgid without any exec bits is just a mandatory locking > > > mark; leave > > > - * it alone. If some exec bits are set, it's a real sgid; > > > kill it. > > > - */ > > > - if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) > > > - kill |= ATTR_KILL_SGID; > > > - > > > - if (unlikely(kill && S_ISREG(mode))) > > > - return kill; > > > - > > > - return 0; > > > -} > > > - > > > static void nfs_writeback_check_extend(struct nfs_pgio_header > > > *hdr, > > > struct nfs_fattr *fattr) > > > { > > > > Otherwise, looks OK. > > > > -- > Trond Myklebust > Linux NFS client maintainer, Hammerspace > trond.myklebust@hammerspace.com > >