Commit 6263aad5 authored by ChenXiaoSong's avatar ChenXiaoSong Committed by ChenXiaoSong
Browse files

NFS: make sure open context mode have FMODE_EXEC when file open for exec

mainline inclusion
from mainline-v6.2-rc1
commit 6f1c1d95
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB6FR2
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6f1c1d95dc93b52a8ef9cc1f3f610c2d5e6b217b



--------------------------------

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: default avatarChenXiaoSong <chenxiaosong2@huawei.com>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>

Conflicts:
	fs/nfs/nfs4file.c

Signed-off-by: default avatarChenXiaoSong <chenxiaosong@kylinos.cn>
parent 81e029d5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1095,7 +1095,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);
+2 −6
Original line number Diff line number Diff line
@@ -30,7 +30,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;

@@ -49,17 +48,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;