NFS: make sure open context mode have FMODE_EXEC when file open for exec
authorChenXiaoSong <chenxiaosong2@huawei.com>
Fri, 23 Sep 2022 05:40:14 +0000 (13:40 +0800)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 6 Dec 2022 15:38:38 +0000 (10:38 -0500)
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 <chenxiaosong2@huawei.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/inode.c
fs/nfs/nfs4file.c

index 6b2cfa59a1a2b40edc5aecc3417a4a747c0de303..e98ee7599eebacc2f31ccbfe69e0b72651d604d3 100644 (file)
@@ -1168,7 +1168,8 @@ int nfs_open(struct inode *inode, struct file *filp)
 {
        struct nfs_open_context *ctx;
 
-       ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp);
+       ctx = 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);
index 9eb18128787951218b3f7a898dd9747a112777de..2563ed8580f37045cfbc791b95234e1dd927d9a2 100644 (file)
@@ -32,7 +32,6 @@ nfs4_file_open(struct inode *inode, struct file *filp)
        struct dentry *parent = NULL;
        struct inode *dir;
        unsigned openflags = filp->f_flags;
-       fmode_t f_mode;
        struct iattr attr;
        int err;
 
@@ -51,17 +50,14 @@ nfs4_file_open(struct inode *inode, struct file *filp)
        if (err)
                return err;
 
-       f_mode = filp->f_mode;
-       if ((openflags & O_ACCMODE) == 3)
-               f_mode |= flags_to_mode(openflags);
-
        /* We can't create new files here */
        openflags &= ~(O_CREAT|O_EXCL);
 
        parent = dget_parent(dentry);
        dir = d_inode(parent);
 
-       ctx = alloc_nfs_open_context(file_dentry(filp), f_mode, filp);
+       ctx = alloc_nfs_open_context(file_dentry(filp),
+                                    flags_to_mode(openflags), filp);
        err = PTR_ERR(ctx);
        if (IS_ERR(ctx))
                goto out;
@@ -366,8 +362,8 @@ static struct file *__nfs42_ssc_open(struct vfsmount *ss_mnt,
                goto out_free_name;
        }
 
-       ctx = alloc_nfs_open_context(filep->f_path.dentry, filep->f_mode,
-                                       filep);
+       ctx = alloc_nfs_open_context(filep->f_path.dentry,
+                                    flags_to_mode(filep->f_flags), filep);
        if (IS_ERR(ctx)) {
                res = ERR_CAST(ctx);
                goto out_filep;