Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee3ae84e authored by Trond Myklebust's avatar Trond Myklebust
Browse files

NFSv4: Servers should only check SETATTR stateid open mode on size change



The NFSv4 and NFSv4.1 specs are both clear that the server should only check
stateid open mode if a SETATTR specifies the size attribute. If the
open mode is not one that allows writing, then it returns NFS4ERR_OPENMODE.

In the case where the SETATTR is not changing the size, the client will
still pass it the delegation stateid to ensure that the server does not
recall that delegation. In that case, the server should _ignore_ the
delegation open mode, and simply apply standard permission checks.

Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent b0212b84
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -2142,20 +2142,25 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
		.rpc_cred	= cred,
		.rpc_cred	= cred,
        };
        };
	unsigned long timestamp = jiffies;
	unsigned long timestamp = jiffies;
	fmode_t fmode;
	bool truncate;
	int status;
	int status;


	nfs_fattr_init(fattr);
	nfs_fattr_init(fattr);


	if (state != NULL && nfs4_valid_open_stateid(state)) {
	/* Servers should only apply open mode checks for file size changes */
	truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false;
	fmode = truncate ? FMODE_WRITE : FMODE_READ;

	if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) {
		/* Use that stateid */
	} else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) {
		struct nfs_lockowner lockowner = {
		struct nfs_lockowner lockowner = {
			.l_owner = current->files,
			.l_owner = current->files,
			.l_pid = current->tgid,
			.l_pid = current->tgid,
		};
		};
		nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
		nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
				&lockowner);
				&lockowner);
	} else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
				FMODE_WRITE)) {
		/* Use that stateid */
	} else
	} else
		nfs4_stateid_copy(&arg.stateid, &zero_stateid);
		nfs4_stateid_copy(&arg.stateid, &zero_stateid);