From nobody Thu Apr 2 13:20:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8001DECAAD8 for ; Fri, 23 Sep 2022 04:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbiIWEjq (ORCPT ); Fri, 23 Sep 2022 00:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiIWEjh (ORCPT ); Fri, 23 Sep 2022 00:39:37 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2D9BC77; Thu, 22 Sep 2022 21:39:30 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MYfVt3BdszpTJK; Fri, 23 Sep 2022 12:36:38 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 12:39:29 +0800 Received: from huawei.com (10.175.101.6) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 12:39:28 +0800 From: ChenXiaoSong To: , CC: , , , , Subject: [PATCH v3 1/2] NFS: make sure open context mode have FMODE_EXEC when file open for exec Date: Fri, 23 Sep 2022 13:40:14 +0800 Message-ID: <20220923054015.2890271-2-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220923054015.2890271-1-chenxiaosong2@huawei.com> References: <20220923054015.2890271-1-chenxiaosong2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Because file f_mode never have FMODE_EXEC, open context mode won't get FMODE_EXEC from file f_mode. Open context mode only care about FMODE_READ/ FMODE_WRITE/FMODE_EXEC, and all info about open context mode can be convert from file f_flags, so convert file f_flags to open context mode by flags_to_mode(). Signed-off-by: ChenXiaoSong --- fs/nfs/inode.c | 3 ++- fs/nfs/nfs4file.c | 12 ++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index bea7c005119c..bafa808823db 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -1173,7 +1173,8 @@ int nfs_open(struct inode *inode, struct file *filp) { struct nfs_open_context *ctx; =20 - ctx =3D alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp); + ctx =3D alloc_nfs_open_context(file_dentry(filp), + flags_to_mode(filp->f_flags), filp); if (IS_ERR(ctx)) return PTR_ERR(ctx); nfs_file_set_open_context(filp, ctx); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 9eb181287879..2563ed8580f3 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -32,7 +32,6 @@ nfs4_file_open(struct inode *inode, struct file *filp) struct dentry *parent =3D NULL; struct inode *dir; unsigned openflags =3D filp->f_flags; - fmode_t f_mode; struct iattr attr; int err; =20 @@ -51,17 +50,14 @@ nfs4_file_open(struct inode *inode, struct file *filp) if (err) return err; =20 - f_mode =3D filp->f_mode; - if ((openflags & O_ACCMODE) =3D=3D 3) - f_mode |=3D flags_to_mode(openflags); - /* We can't create new files here */ openflags &=3D ~(O_CREAT|O_EXCL); =20 parent =3D dget_parent(dentry); dir =3D d_inode(parent); =20 - ctx =3D alloc_nfs_open_context(file_dentry(filp), f_mode, filp); + ctx =3D alloc_nfs_open_context(file_dentry(filp), + flags_to_mode(openflags), filp); err =3D PTR_ERR(ctx); if (IS_ERR(ctx)) goto out; @@ -366,8 +362,8 @@ static struct file *__nfs42_ssc_open(struct vfsmount *s= s_mnt, goto out_free_name; } =20 - ctx =3D alloc_nfs_open_context(filep->f_path.dentry, filep->f_mode, - filep); + ctx =3D alloc_nfs_open_context(filep->f_path.dentry, + flags_to_mode(filep->f_flags), filep); if (IS_ERR(ctx)) { res =3D ERR_CAST(ctx); goto out_filep; --=20 2.31.1 From nobody Thu Apr 2 13:20:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08F0CECAAD8 for ; Fri, 23 Sep 2022 04:39:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbiIWEjo (ORCPT ); Fri, 23 Sep 2022 00:39:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiIWEjh (ORCPT ); Fri, 23 Sep 2022 00:39:37 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51973E68; Thu, 22 Sep 2022 21:39:31 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MYfWf2bvhzHqFM; Fri, 23 Sep 2022 12:37:18 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 12:39:29 +0800 Received: from huawei.com (10.175.101.6) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 12:39:28 +0800 From: ChenXiaoSong To: , CC: , , , , Subject: [PATCH v3 2/2] NFSv4: check FMODE_EXEC from open context mode in nfs4_opendata_access() Date: Fri, 23 Sep 2022 13:40:15 +0800 Message-ID: <20220923054015.2890271-3-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220923054015.2890271-1-chenxiaosong2@huawei.com> References: <20220923054015.2890271-1-chenxiaosong2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After converting file f_flags to open context mode by flags_to_mode(), open context mode will have FMODE_EXEC when file open for exec, so we check FMODE_EXEC from open context mode. No functional change, just simplify the code. Signed-off-by: ChenXiaoSong --- fs/nfs/nfs4proc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 3ed14a2a84a4..806d243f66e8 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2624,8 +2624,7 @@ static int _nfs4_recover_proc_open(struct nfs4_openda= ta *data) */ static int nfs4_opendata_access(const struct cred *cred, struct nfs4_opendata *opendata, - struct nfs4_state *state, fmode_t fmode, - int openflags) + struct nfs4_state *state, fmode_t fmode) { struct nfs_access_entry cache; u32 mask, flags; @@ -2636,11 +2635,7 @@ static int nfs4_opendata_access(const struct cred *c= red, return 0; =20 mask =3D 0; - /* - * Use openflags to check for exec, because fmode won't - * always have FMODE_EXEC set when file open for exec. - */ - if (openflags & __FMODE_EXEC) { + if (fmode & FMODE_EXEC) { /* ONLY check for exec rights */ if (S_ISDIR(state->inode->i_mode)) mask =3D NFS4_ACCESS_LOOKUP; @@ -3023,7 +3018,7 @@ static unsigned nfs4_exclusive_attrset(struct nfs4_op= endata *opendata, } =20 static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, - int flags, struct nfs_open_context *ctx) + struct nfs_open_context *ctx) { struct nfs4_state_owner *sp =3D opendata->owner; struct nfs_server *server =3D sp->so_server; @@ -3084,8 +3079,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opend= ata *opendata, /* Parse layoutget results before we check for access */ pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); =20 - ret =3D nfs4_opendata_access(sp->so_cred, opendata, state, - acc_mode, flags); + ret =3D nfs4_opendata_access(sp->so_cred, opendata, state, acc_mode); if (ret !=3D 0) goto out; =20 @@ -3159,7 +3153,7 @@ static int _nfs4_do_open(struct inode *dir, if (d_really_is_positive(dentry)) opendata->state =3D nfs4_get_open_state(d_inode(dentry), sp); =20 - status =3D _nfs4_open_and_get_state(opendata, flags, ctx); + status =3D _nfs4_open_and_get_state(opendata, ctx); if (status !=3D 0) goto err_opendata_put; state =3D ctx->state; --=20 2.31.1