Skip to contentSkip to conversation

NFSD: detect mismatch of file handle and delegation stateid in OPEN op

PATCH In review Dai Ngo 2 participants 2 messages Jun 10, 2025

Subsystems (2)
lore
Share & tools
lore

Dai Ngo

author reviewer
#0 lore raw

PATCH v3 1/1 NFSD: detect mismatch of file handle and delegation stateid in OPEN op

NFSD: detect mismatch of file handle and delegation stateid in OPEN op

When the client sends an OPEN with claim type CLAIM_DELEG_CUR_FH or CLAIM_DELEGATION_CUR, the delegation stateid and the file handle must belong to the same file, otherwise return NFS4ERR_INVAL.

Note that RFC8881, section 8.2.4, mandates the server to return NFS4ERR_BAD_STATEID if the selected table entry does not match the current filehandle. However returning NFS4ERR_BAD_STATEID in the OPEN causes the client to retry the operation and therefor get the client into a loop. To avoid this situation we return NFS4ERR_INVAL instead.

Fixes c44c5eeb2c02 ("[PATCH] nfsd4: add open state code for CLAIM_DELEGATE_CUR")

---
V1 -> V2: replace NFS4ERR_BAD_STATEID with NFS4ERR_INVAL and add
comment to explain the deviation from the spec.
V2 -> V3: squash V1 and V2 together.
Add Reported-by and Fixes tag.

 fs/nfsd/nfs4state.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
fs/nfsd/nfs4state.c +14 -0
index 59a693f22452..ade812bd2996 100644
@@ -6318,6 +6318,20 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 		status = nfs4_check_deleg(cl, open, &dp);
 		if (status)
 			goto out;
+		if (dp && nfsd4_is_deleg_cur(open) &&
+				(dp->dl_stid.sc_file != fp)) {
+			/*
+			 * RFC8881, section 8.2.4, mandates the server to return
+			 * NFS4ERR_BAD_STATEID if the selected table entry does
+			 * not match the current filehandle.
+			 * However returning NFS4ERR_BAD_STATEID in the OPEN causes
+			 * the client to retry the operation and therefor get the
+			 * client into a loop. To avoid this situation we return
+			 * NFS4ERR_INVAL instead.
+			 */
+			status = nfserr_inval;
+			goto out;
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;
Signature · 1 line
2.43.5
maintainer
#1 lore raw

From: Chuck Lever <[email protected]>

Quoted 6 lines · Dai Ngo

NFSD: detect mismatch of file handle and delegation stateid in OPEN op

When the client sends an OPEN with claim type CLAIM_DELEG_CUR_FH or CLAIM_DELEGATION_CUR, the delegation stateid and the file handle must belong to the same file, otherwise return NFS4ERR_INVAL.

Quoted 8 lines

Note that RFC8881, section 8.2.4, mandates the server to return NFS4ERR_BAD_STATEID if the selected table entry does not match the current filehandle. However returning NFS4ERR_BAD_STATEID in the OPEN causes the client to retry the operation and therefor get the client into a loop. To avoid this situation we return NFS4ERR_INVAL instead.

[...]

Applied to nfsd-testing, thanks!

[1/1] NFSD: detect mismatch of file handle and delegation stateid in OPEN op

      commit: 9fd9dde965d8848b240a47dafe558a1e5f24e9ca

--
Chuck Lever