nfsd: only set RD_STATE in nfsd4_setattr() for sole TIME_DELEG_ACCESS
Subsystems (2)
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.
--- fs/nfsd/nfs4proc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +9 -1
@@ -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
Quoted 45 lines · Dominik Maier
In
nfsd4_setattr(), wheneverFATTR4_WORD2_TIME_DELEG_ACCESSis set in sa_bmval[2],RD_STATEis unconditionally ORed into flags alongsideWR_STATEbefore callingnfs4_preprocess_stateid_op(), even when other attributes are also requested in the same SETATTR operation.Because
nfs4_check_delegmode()accepts a read delegation wheneverRD_STATEis present in flags, an NFSv4.2 client holding only anOPEN_DELEGATE_READ_ATTRS_DELEGdelegation (and ordinary UNIX write permission on the file) can combineFATTR4_WORD2_TIME_DELEG_ACCESSwith:-
ATTR_SIZEorFATTR4_WORD2_TIME_DELEG_MODIFYto truncate the file or modify delegated mtime without a write stateid, bypassing another client'sOPEN4_SHARE_DENY_WRITEshare reservation; or
- non-delegated attributes (such asFATTR4_WORD1_MODE, OWNER,TIME_MODIFY_SET, ACL, orSECURITY_LABEL), which execute withATTR_DELEGset on the shared iattr and causenotify_change()to skiptry_break_deleg()against other clients' concurrent read delegations.Only set
RD_STATEinnfsd4_setattr()whenFATTR4_WORD2_TIME_DELEG_ACCESSis 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")Signed-off-by Dominik Maier <[email protected]>--- fs/nfsd/nfs4proc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)fs/nfsd/nfs4proc.c +2
-1@@ -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,
Chuck Lever
maintainerQuoted 11 lines · Dominik Maier
In
nfsd4_setattr(), wheneverFATTR4_WORD2_TIME_DELEG_ACCESSis set in sa_bmval[2],RD_STATEis unconditionally ORed into flags alongsideWR_STATEbefore callingnfs4_preprocess_stateid_op(), even when other attributes are also requested in the same SETATTR operation.Because
nfs4_check_delegmode()accepts a read delegation wheneverRD_STATEis present in flags, an NFSv4.2 client holding only anOPEN_DELEGATE_READ_ATTRS_DELEGdelegation (and ordinary UNIX write permission on the file) can combineFATTR4_WORD2_TIME_DELEG_ACCESSwith:[...]
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]>