Skip to contentSkip to conversation

nfsd: only set RD_STATE in nfsd4_setattr() for sole TIME_DELEG_ACCESS

PATCH In review Dominik Maier 3 participants 3 messages Nov 19 – Nov 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsd: only set RD_STATE in nfsd4_setattr() for sole TIME_DELEG_ACCESS

In nfsd4_setattr(), whenever FATTR4_WORD2_TIME_DELEG_ACCESS is set in sa_bmval[2], RD_STATE is unconditionally ORed into flags alongside WR_STATE before calling nfs4_preprocess_stateid_op(), even when other attributes are also requested in the same SETATTR operation.

Because nfs4_check_delegmode() accepts a read delegation whenever RD_STATE is present in flags, an NFSv4.2 client holding only an OPEN_DELEGATE_READ_ATTRS_DELEG delegation (and ordinary UNIX write permission on the file) can combine FATTR4_WORD2_TIME_DELEG_ACCESS with:

- ATTR_SIZE or FATTR4_WORD2_TIME_DELEG_MODIFY to truncate the file or modify delegated mtime without a write stateid, bypassing another client's OPEN4_SHARE_DENY_WRITE share reservation; or
- non-delegated attributes (such as FATTR4_WORD1_MODE, OWNER, TIME_MODIFY_SET, ACL, or SECURITY_LABEL), which execute with ATTR_DELEG set on the shared iattr and cause notify_change() to skip try_break_deleg() against other clients' concurrent read delegations.

Only set RD_STATE in nfsd4_setattr() when FATTR4_WORD2_TIME_DELEG_ACCESS is the sole attribute set across sa_bmval[0..2].

This issue was discovered by an AI-assisted code review tool (ARTIST) and validated in QEMU against an unmodified v7.4-rc3 kernel without kernel modifications or error injection. A standalone reproducer is available on request. The fix was build-tested with KCFLAGS=-Werror and checked with checkpatch.pl --strict.

Fixes 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR")
---
 fs/nfsd/nfs4proc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +9 -1
index 3a82af3..9b348bf 100644
@@ -1353,7 +1353,15 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	if (deleg_attrs || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) {
 		int flags = WR_STATE;
 
-		if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS)
+		/*
+		 * Only allow a read delegation stateid when setting
+		 * TIME_DELEG_ACCESS alone. Any other attribute requires
+		 * write state (and must not carry ATTR_DELEG under a read
+		 * delegation, which would suppress delegation recall in
+		 * notify_change()).
+		 */
+		if (!setattr->sa_bmval[0] && !setattr->sa_bmval[1] &&
+		    setattr->sa_bmval[2] == FATTR4_WORD2_TIME_DELEG_ACCESS)
 			flags |= RD_STATE;
 
 		status = nfs4_preprocess_stateid_op(rqstp, cstate,
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 45 lines · Dominik Maier

In nfsd4_setattr(), whenever FATTR4_WORD2_TIME_DELEG_ACCESS is set in sa_bmval[2], RD_STATE is unconditionally ORed into flags alongside WR_STATE before calling nfs4_preprocess_stateid_op(), even when other attributes are also requested in the same SETATTR operation.

Because nfs4_check_delegmode() accepts a read delegation whenever RD_STATE is present in flags, an NFSv4.2 client holding only an OPEN_DELEGATE_READ_ATTRS_DELEG delegation (and ordinary UNIX write permission on the file) can combine FATTR4_WORD2_TIME_DELEG_ACCESS with:

- ATTR_SIZE or FATTR4_WORD2_TIME_DELEG_MODIFY to truncate the file or modify delegated mtime without a write stateid, bypassing another client's OPEN4_SHARE_DENY_WRITE share reservation; or
- non-delegated attributes (such as FATTR4_WORD1_MODE, OWNER, TIME_MODIFY_SET, ACL, or SECURITY_LABEL), which execute with ATTR_DELEG set on the shared iattr and cause notify_change() to skip try_break_deleg() against other clients' concurrent read delegations.

Only set RD_STATE in nfsd4_setattr() when FATTR4_WORD2_TIME_DELEG_ACCESS is the sole attribute set across sa_bmval[0..2].

This issue was discovered by an AI-assisted code review tool (ARTIST) and validated in QEMU against an unmodified v7.4-rc3 kernel without kernel modifications or error injection. A standalone reproducer is available on request. The fix was build-tested with KCFLAGS=-Werror and checked with checkpatch.pl --strict.

Fixes 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR")
---
 fs/nfsd/nfs4proc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +2 -1
index 3a82af3..9b348bf 100644
@@ -1353,7 +1353,15 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	if (deleg_attrs || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) {
 		int flags = WR_STATE;
 
-		if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS)
+		/*
+		 * Only allow a read delegation stateid when setting

fs/nfsd/nfs4proc.c nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1367

Quoted 10 lines
fs/nfsd/nfs4proc.c +7 -0
+		 * TIME_DELEG_ACCESS alone. Any other attribute requires
+		 * write state (and must not carry ATTR_DELEG under a read
+		 * delegation, which would suppress delegation recall in
+		 * notify_change()).
+		 */
+		if (!setattr->sa_bmval[0] && !setattr->sa_bmval[1] &&
+		    setattr->sa_bmval[2] == FATTR4_WORD2_TIME_DELEG_ACCESS)
 			flags |= RD_STATE;
 
 		status = nfs4_preprocess_stateid_op(rqstp, cstate,
maintainer
#2 lore raw
In reply to Dominik Maier
Quoted 11 lines · Dominik Maier

In nfsd4_setattr(), whenever FATTR4_WORD2_TIME_DELEG_ACCESS is set in sa_bmval[2], RD_STATE is unconditionally ORed into flags alongside WR_STATE before calling nfs4_preprocess_stateid_op(), even when other attributes are also requested in the same SETATTR operation.

Because nfs4_check_delegmode() accepts a read delegation whenever RD_STATE is present in flags, an NFSv4.2 client holding only an OPEN_DELEGATE_READ_ATTRS_DELEG delegation (and ordinary UNIX write permission on the file) can combine FATTR4_WORD2_TIME_DELEG_ACCESS with:

[...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: only set RD_STATE in nfsd4_setattr() for sole TIME_DELEG_ACCESS

      commit: f6100c1e9950cf6e18e142e75b5f96051ae0d5ba

--
Chuck Lever <[email protected]>