Thread (2 messages) 2 messages, 2 authors, 2025-06-10
STALE372d REVIEWED: 4 (4M)

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

From: Dai Ngo <dai.ngo@oracle.com>
Date: 2025-06-10 14:32:07
Subsystem: filesystems (vfs and infrastructure), kernel nfsd, sunrpc, and lockd servers, the rest · Maintainers: Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Linus Torvalds

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 belongs 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.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
---
V1 -> V2: replace NFS4ERR_BAD_STATEID with NFS4ERR_INVAL and add
          comment to explain the deviation from the spec.

 fs/nfsd/nfs4state.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index be2ee641a22d..ade812bd2996 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6320,7 +6320,16 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 			goto out;
 		if (dp && nfsd4_is_deleg_cur(open) &&
 				(dp->dl_stid.sc_file != fp)) {
-			status = nfserr_bad_stateid;
+			/*
+			 * 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);
-- 
2.43.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help