Skip to contentSkip to conversation

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

PATCH Superseded Dai Ngo 5 participants 13 messages Jun 10, 2025 – Jun 11, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dai Ngo

author reviewer
#0 lore raw

PATCH 1/1 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 belongs to the same file, otherwise return NFS4ERR_BAD_STATEID.

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +5 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;
+			goto out;
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;
Signature · 1 line
2.43.5
#1 lore raw
Quoted 14 lines · Dai Ngo

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

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +0 -0
index 59a693f22452..be2ee641a22d 100644

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6323

Quoted 6 lines
fs/nfsd/nfs4state.c +3 -0
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;

How does the client react to NFS4ERR_BAD_STATEID ? Does it retry the same request or does it reflect the failure to the application?

Quoted 5 lines
fs/nfsd/nfs4state.c +2 -0
+			goto out;
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;
Signature · 1 line
Chuck Lever
maintainer
#2 lore raw
Quoted 10 lines · Chuck Lever
Quoted 9 lines · Dai Ngo

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

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 15 lines

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6323

Quoted 11 lines
fs/nfsd/nfs4state.c +3 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;

How does the client react to NFS4ERR_BAD_STATEID ? Does it retry the same request or does it reflect the failure to the application?

I imagine this triggers the client to go into state recovery, which won't be terribly helpful. Another reason to consider a different error code. I suggest:

15.1.1.4. NFS4ERR_INVAL (Error Code 22)

The arguments for this operation are not valid for some reason, even though they do match those specified in the XDR definition for the request.

This might bubble up as an application error and get noticed that way.

Quoted 7 lines
Quoted 6 lines
fs/nfsd/nfs4state.c +2 -0
+			goto out;
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;
Signature · 1 line
Jeff Layton <[email protected]>
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Dai Ngo
Quoted 15 lines · Dai Ngo

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

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +0 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 		status = nfs4_check_deleg(cl, open, &dp);

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6328

Quoted 10 lines
fs/nfsd/nfs4state.c +5 -0
 		if (status)
 			goto out;
+		if (dp && nfsd4_is_deleg_cur(open) &&
+				(dp->dl_stid.sc_file != fp)) {
+			status = nfserr_bad_stateid;
+			goto out;
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

In any case, whatever we decide:

#4 lore raw
Quoted 22 lines · Jeff Layton
Quoted 21 lines · Dai Ngo

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

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +4 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;
+			goto out;
Quoted 8 lines

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6328

Quoted 4 lines
fs/nfsd/nfs4state.c +1 -0
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Quoted 4 lines

In any case, whatever we decide:

Signature · 1 line
Chuck Lever
maintainer
#5 lore raw
Quoted 32 lines · Chuck Lever
Quoted 22 lines · Jeff Layton
Quoted 21 lines · Dai Ngo

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

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +4 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;
+			goto out;
Quoted 8 lines

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6328

Quoted 4 lines
fs/nfsd/nfs4state.c +1 -0
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

I guess we're stuck with reporting that unless we want to amend the spec.

Quoted 6 lines
Quoted 5 lines

In any case, whatever we decide:

Signature · 1 line
Jeff Layton <[email protected]>
#6 lore raw
Quoted 38 lines · Jeff Layton
Quoted 32 lines · Chuck Lever
Quoted 22 lines · Jeff Layton
Quoted 21 lines · Dai Ngo

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

---
 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +4 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;
+			goto out;
Quoted 8 lines

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6328

Quoted 4 lines
fs/nfsd/nfs4state.c +1 -0
+		}
 		stp = nfsd4_find_and_lock_existing_open(fp, open);
 	} else {
 		open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Quoted 8 lines

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

I guess we're stuck with reporting that unless we want to amend the spec.

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

In any case, whatever we decide:

Signature · 1 line
Chuck Lever
author reviewer
#7 lore raw
Quoted 42 lines · Chuck Lever
Quoted 41 lines · Jeff Layton
Quoted 30 lines · Chuck Lever
Quoted 21 lines · Jeff Layton
Quoted 20 lines · Dai Ngo

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

---
  fs/nfsd/nfs4state.c | 5 +++++
  1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +3 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) {
+			status = nfserr_bad_stateid;
Quoted 8 lines

fs/nfsd/nfs4state.c nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf · line 6328

Quoted 5 lines
fs/nfsd/nfs4state.c +2 -0
+			goto out;
+		}
  		stp = nfsd4_find_and_lock_existing_open(fp, open);
  	} else {
  		open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

Quoted 6 lines
Quoted 2 lines

I guess we're stuck with reporting that unless we want to amend the spec.

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Since the Linux client does not behave this way I can not test if this error get us into a loop. I used pynfs to force this behavior.

However, here is the comment in nfs4_do_open:

/*
* BAD_STATEID on OPEN means that the server cancelled our
* state before it received the OPEN_CONFIRM.
* Recover by retrying the request as per the discussion
* on Page 181 of RFC3530.
*/

So it guess BAD_STATEID will get the client and server into a loop. I'll change error to NFS4ERR_INVAL and add a comment in the code.

-Dai

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

In any case, whatever we decide:

#8 lore raw
Quoted 48 lines · Dai Ngo
Quoted 46 lines · Chuck Lever
Quoted 45 lines · Jeff Layton
Quoted 32 lines · Chuck Lever
Quoted 23 lines · Jeff Layton
Quoted 22 lines · Dai Ngo

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

---
  fs/nfsd/nfs4state.c | 5 +++++

  1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +0 -0
index 59a693f22452..be2ee641a22d 100644
@@ -6318,6 +6318,11 @@ 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)) { +            status = nfserr_bad_stateid;
+            goto out;

Quoted 8 lines
Quoted 4 lines

+        }
          stp = nfsd4_find_and_lock_existing_open(fp, open); } else {
          open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error
here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

I guess we're stuck with reporting that unless we want to amend the spec.

Quoted 7 lines
Quoted 4 lines

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Since the Linux client does not behave this way I can not test if this error get us into a loop.

Good point!

Quoted 11 lines

I used pynfs to force this behavior.

However, here is the comment in nfs4_do_open:

                /*
                 * BAD_STATEID on OPEN means that the server cancelled our
                 * state before it received the OPEN_CONFIRM.
                 * Recover by retrying the request as per the discussion
                 * on Page 181 of RFC3530.
                 */

Quoted 2 lines

So it guess BAD_STATEID will  get the client and server into a loop. I'll change error to NFS4ERR_INVAL and add a comment in the code.

Thanks, we'll start there. If that's problematic, it can always be changed later.

Maybe someone should file an errata against RFC 8881. <whistles tunelessly>

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In any case, whatever we decide:

Signature · 1 line
Chuck Lever
#9 lore raw

From: Chuck Lever [mailto:[email protected]]

Quoted 73 lines · Dai Ngo
Quoted 9 lines · Chuck Lever
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Chuck Lever
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Dai Ngo
Quoted 3 lines

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

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
---
  fs/nfsd/nfs4state.c | 5 +++++
  1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c index renamed from fs/nfsd/nfs4state.c +0 -0

59a693f22452..be2ee641a22d 100644

fs/nfsd/nfs4state.c +3 -0
@@ -6318,6 +6318,11 @@ 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)) {
+            status = nfserr_bad_stateid;
Quoted 8 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +2 -0
+            goto out;
+        }
          stp = nfsd4_find_and_lock_existing_open(fp, open);
      } else {
          open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

I guess we're stuck with reporting that unless we want to amend the spec.

Quoted 7 lines
Quoted 4 lines

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Since the Linux client does not behave this way I can not test if this error get us into a loop.

Good point!

Quoted 13 lines

I used pynfs to force this behavior.

However, here is the comment in nfs4_do_open:

/*
* BAD_STATEID on OPEN means that the server cancelled
our
* state before it received the OPEN_CONFIRM.
* Recover by retrying the request as per the
discussion
* on Page 181 of RFC3530.
*/

Quoted 7 lines
Quoted 2 lines

So it guess BAD_STATEID will get the client and server into a loop. I'll change error to NFS4ERR_INVAL and add a comment in the code.

Thanks, we'll start there. If that's problematic, it can always be changed later.

Maybe someone should file an errata against RFC 8881. <whistles tunelessly>

An interesting case. Ganesha doesn't handle this. It would definitely be good to see an errata for it. Also a pynfs test case.

Thanks

Frank

author reviewer
#10 lore raw
Quoted 70 lines · Frank Filz

From: Chuck Lever [mailto:[email protected]]

Quoted 69 lines · Dai Ngo
Quoted 8 lines · Chuck Lever
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Chuck Lever
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Dai Ngo
Quoted 3 lines

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

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
---
   fs/nfsd/nfs4state.c | 5 +++++
   1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c index renamed from fs/nfsd/nfs4state.c +0 -0

59a693f22452..be2ee641a22d 100644

fs/nfsd/nfs4state.c +3 -0
@@ -6318,6 +6318,11 @@ 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)) {
+            status = nfserr_bad_stateid;
Quoted 8 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +2 -0
+            goto out;
+        }
           stp = nfsd4_find_and_lock_existing_open(fp, open);
       } else {
           open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I guess we're stuck with reporting that unless we want to amend the spec.

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Since the Linux client does not behave this way I can not test if this error get us into a loop.

Good point!

Quoted 13 lines

I used pynfs to force this behavior.

However, here is the comment in nfs4_do_open:

/*
* BAD_STATEID on OPEN means that the server cancelled
our
* state before it received the OPEN_CONFIRM.
* Recover by retrying the request as per the
discussion
* on Page 181 of RFC3530.
*/

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

So it guess BAD_STATEID will get the client and server into a loop. I'll change error to NFS4ERR_INVAL and add a comment in the code.

Thanks, we'll start there. If that's problematic, it can always be changed later.

Maybe someone should file an errata against RFC 8881. <whistles tunelessly>

An interesting case. Ganesha doesn't handle this. It would definitely be good to see an errata for it. Also a pynfs test case.

Here is the pynfs test I used to test CLAIM_DELEG_CUR_FH:

def testClaimDeleg_CurFh(t, env):
"""Test OPEN with CLAIM_DELEG_CUR_FH with mismatch file file handle
and delegation stateid.

FLAGS: writedelegations deleg
CODE: DELEG32
"""

sess = env.c1.new_client_session(env.testname(t))

# create file-1 with read-only access (0444) no delegatation wanted,
# and leave the file opened
filename1 = b"file-1"
res = open_create_file(sess, filename1, open_create = OPEN4_CREATE, attrs={FATTR4_MODE: 0o444},
access = OPEN4_SHARE_ACCESS_BOTH, want_deleg = False)
check(res)
deleg = res.resarray[-2].delegation
if (_got_deleg(deleg)):
fail("Not expect to get delegation")
fh = res.resarray[-1].object
stateid = res.resarray[-2].stateid
print("----- CREATED ", filename1)

# create file-2 with access RW and delegation wanted filename2 = b"file-2"
res = open_create_file(sess, filename2, open_create = OPEN4_CREATE,
access = OPEN4_SHARE_ACCESS_BOTH, want_deleg = True)
check(res)
print("----- CREATED ", filename2)

wfh = res.resarray[-1].object
wdeleg = res.resarray[-2].delegation
if (not _got_deleg(wdeleg)):
fail("Could not get WRITE delegation")
wdelegstateid = wdeleg.write.stateid

# OPEN for WRITE with CLAIM_DELEG_CUR_FH using the file handle # of filename1 and the delegation stateid granted for filename2. # Since the file handle and the delegation stateid do not belong # to the same file, expect server to return NFS4ERR_BAD_STATEID.

claim = open_claim4(CLAIM_DELEG_CUR_FH, oc_delegate_stateid=wdelegstateid) owner = open_owner4(0, b"My Open Owner 2")
how = openflag4(OPEN4_NOCREATE)
open_op = op.open(0, OPEN4_SHARE_ACCESS_WRITE, OPEN4_SHARE_DENY_NONE,
owner, how, claim)
res = sess.compound([op.putfh(fh), open_op])
check(res, NFS4ERR_BAD_STATEID)

# close file-1
res = close_file(sess, fh, stateid)
check(res)

# return the write delegation
res = sess.compound([op.putfh(wfh), op.delegreturn(wdelegstateid)]) check(res)

Quoted 5 lines

Thanks

Frank

#11 lore raw
Quoted 74 lines · Dai Ngo
Quoted 72 lines · Frank Filz

From: Chuck Lever [mailto:[email protected]]

Quoted 71 lines · Dai Ngo
Quoted 8 lines · Chuck Lever
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Chuck Lever
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Dai Ngo
Quoted 3 lines

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

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines

---
   fs/nfsd/nfs4state.c | 5 +++++

   1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c index renamed from fs/nfsd/nfs4state.c +0 -0

59a693f22452..be2ee641a22d 100644

fs/nfsd/nfs4state.c +3 -0
@@ -6318,6 +6318,11 @@ 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)) {
+            status = nfserr_bad_stateid;
Quoted 8 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +2 -0
+            goto out;
+        }
            stp = nfsd4_find_and_lock_existing_open(fp, open);
        } else {

           open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle, return NFS4ERR_BAD_STATEID.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I guess we're stuck with reporting that unless we want to amend the spec.

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Since the Linux client does not behave this way I can not test if this error get us into a loop.

Good point!

Quoted 15 lines

I used pynfs to force this behavior.

However, here is the comment in nfs4_do_open:

                 /*
                  * BAD_STATEID on OPEN means that the server cancelled our
                  * state before it received the OPEN_CONFIRM.
                  * Recover by retrying the request as per the discussion
                  * on Page 181 of RFC3530.
                  */

So it guess BAD_STATEID will  get the client and server into a loop. I'll change error to NFS4ERR_INVAL and add a comment in the code.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Thanks, we'll start there. If that's problematic, it can always be changed later.

Maybe someone should file an errata against RFC 8881. <whistles tunelessly>

An interesting case. Ganesha doesn't handle this. It would definitely be good to see an errata for it. Also a pynfs test case.

Here is the pynfs test I used to test CLAIM_DELEG_CUR_FH:

Thanks Dai; would you like to submit that as a pynfs patch, please?

ta,
c.

Quoted 66 lines

def testClaimDeleg_CurFh(t, env):
    """Test OPEN with CLAIM_DELEG_CUR_FH with mismatch file file handle and delegation stateid.

    FLAGS: writedelegations deleg
    CODE: DELEG32
    """

    sess = env.c1.new_client_session(env.testname(t))

     # create file-1 with read-only access (0444) no delegatation wanted,
     # and leave the file opened
     filename1 = b"file-1"
     res = open_create_file(sess, filename1, open_create = OPEN4_CREATE, 
attrs={FATTR4_MODE: 0o444},
             access = OPEN4_SHARE_ACCESS_BOTH, want_deleg = False)
     check(res)
     deleg = res.resarray[-2].delegation
     if (_got_deleg(deleg)):
        fail("Not expect to get delegation")
     fh = res.resarray[-1].object
     stateid = res.resarray[-2].stateid
     print("----- CREATED ", filename1)
     # create file-2 with access RW and delegation wanted
     filename2 = b"file-2"
     res = open_create_file(sess, filename2, open_create = OPEN4_CREATE,
             access = OPEN4_SHARE_ACCESS_BOTH, want_deleg = True)
     check(res)
     print("----- CREATED ", filename2)

    wfh = res.resarray[-1].object
    wdeleg = res.resarray[-2].delegation
    if (not _got_deleg(wdeleg)):
       fail("Could not get WRITE delegation")
    wdelegstateid = wdeleg.write.stateid

    # OPEN for WRITE with CLAIM_DELEG_CUR_FH using the file handle

     # of filename1 and the delegation stateid granted for filename2.
     # Since the file handle and the delegation stateid do not belong
     # to the same file, expect server to return NFS4ERR_BAD_STATEID.

    claim = open_claim4(CLAIM_DELEG_CUR_FH,
oc_delegate_stateid=wdelegstateid)
    owner = open_owner4(0, b"My Open Owner 2")
    how = openflag4(OPEN4_NOCREATE)
    open_op = op.open(0, OPEN4_SHARE_ACCESS_WRITE, OPEN4_SHARE_DENY_NONE, owner, how, claim)
    res = sess.compound([op.putfh(fh), open_op])
    check(res, NFS4ERR_BAD_STATEID)

     # close file-1
     res = close_file(sess, fh, stateid)
     check(res)
     # return the write delegation
     res = sess.compound([op.putfh(wfh), op.delegreturn(wdelegstateid)])
     check(res)
Quoted 5 lines

Thanks

Frank

Signature · 3 lines
Calum Mackay
Linux Kernel Engineering
Oracle Linux and Virtualisation
author reviewer
#12 lore raw
Quoted 78 lines · Calum Mackay
Quoted 77 lines · Dai Ngo
Quoted 75 lines · Frank Filz

From: Chuck Lever [mailto:[email protected]]

Quoted 74 lines · Dai Ngo
Quoted 8 lines · Chuck Lever
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Chuck Lever
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Dai Ngo
Quoted 3 lines

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

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines

---
   fs/nfsd/nfs4state.c | 5 +++++

   1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c index renamed from fs/nfsd/nfs4state.c +0 -0

59a693f22452..be2ee641a22d 100644

fs/nfsd/nfs4state.c +3 -0
@@ -6318,6 +6318,11 @@ 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)) {
+            status = nfserr_bad_stateid;
Quoted 8 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +2 -0
+            goto out;
+        }
            stp = nfsd4_find_and_lock_existing_open(fp, open);
        } else {

           open->op_file = NULL;

This seems like a good idea. I wonder if BAD_STATEID is the right error here. It is a valid stateid, after all, it just doesn't match the current_fh. Maybe this should be nfserr_inval ?

Quoted 4 lines

I agree, NFS4ERR_BAD_STATEID /might/ cause a loop, so that needs to be tested. BAD_STATEID is mandated by the spec, so if we choose to return a different status code here, it needs a comment explaining why.

Oh, I didn't realize that error was mandated, but you're right. RFC8881, section 8.2.4:

- If the selected table entry does not match the current filehandle,
return NFS4ERR_BAD_STATEID.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I guess we're stuck with reporting that unless we want to amend the spec.

It is spec-mandated behavior, but we are always free to ignore the spec. I'm OK with NFS4ERR_INVAL if it results in better behavior (as long as there is a comment explaining why we deviate from the mandate).

Since the Linux client does not behave this way I can not test if this error get us into a loop.

Good point!

Quoted 13 lines

I used pynfs to force this behavior.

However, here is the comment in nfs4_do_open:

                 /*
                  * BAD_STATEID on OPEN means that the server cancelled our
                  * state before it received the OPEN_CONFIRM.
                  * Recover by retrying the request as per the discussion
                  * on Page 181 of RFC3530.
                  */

Quoted 2 lines

So it guess BAD_STATEID will  get the client and server into a loop. I'll change error to NFS4ERR_INVAL and add a comment in the code.

Thanks, we'll start there. If that's problematic, it can always be changed later.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Maybe someone should file an errata against RFC 8881. <whistles tunelessly>

An interesting case. Ganesha doesn't handle this. It would definitely be good to see an errata for it. Also a pynfs test case.

Here is the pynfs test I used to test CLAIM_DELEG_CUR_FH:

Thanks Dai; would you like to submit that as a pynfs patch, please?

Yes, I will change the expected error code to NFS4ERR_INVAL, as we discussed, and submit the patch.

-Dai

Quoted 70 lines

ta,
c.

Quoted 64 lines

def testClaimDeleg_CurFh(t, env):
     """Test OPEN with CLAIM_DELEG_CUR_FH with mismatch file file handle and delegation stateid.

     FLAGS: writedelegations deleg
     CODE: DELEG32
     """

     sess = env.c1.new_client_session(env.testname(t))

     # create file-1 with read-only access (0444) no delegatation wanted,
     # and leave the file opened
     filename1 = b"file-1"
     res = open_create_file(sess, filename1, open_create = OPEN4_CREATE, attrs={FATTR4_MODE: 0o444},
             access = OPEN4_SHARE_ACCESS_BOTH, want_deleg = False)
     check(res)
     deleg = res.resarray[-2].delegation
     if (_got_deleg(deleg)):
        fail("Not expect to get delegation")
     fh = res.resarray[-1].object
     stateid = res.resarray[-2].stateid
     print("----- CREATED ", filename1)
     # create file-2 with access RW and delegation wanted
     filename2 = b"file-2"
     res = open_create_file(sess, filename2, open_create = OPEN4_CREATE,
             access = OPEN4_SHARE_ACCESS_BOTH, want_deleg = True)
     check(res)
     print("----- CREATED ", filename2)

     wfh = res.resarray[-1].object
     wdeleg = res.resarray[-2].delegation
     if (not _got_deleg(wdeleg)):
        fail("Could not get WRITE delegation")
     wdelegstateid = wdeleg.write.stateid

     # OPEN for WRITE with CLAIM_DELEG_CUR_FH using the file handle

     # of filename1 and the delegation stateid granted for filename2.
     # Since the file handle and the delegation stateid do not belong
     # to the same file, expect server to return NFS4ERR_BAD_STATEID.

     claim = open_claim4(CLAIM_DELEG_CUR_FH, oc_delegate_stateid=wdelegstateid) owner = open_owner4(0, b"My Open Owner 2")
     how = openflag4(OPEN4_NOCREATE)
     open_op = op.open(0, OPEN4_SHARE_ACCESS_WRITE, OPEN4_SHARE_DENY_NONE, owner, how, claim)
     res = sess.compound([op.putfh(fh), open_op])
     check(res, NFS4ERR_BAD_STATEID)

     # close file-1
     res = close_file(sess, fh, stateid)
     check(res)
     # return the write delegation
     res = sess.compound([op.putfh(wfh), op.delegreturn(wdelegstateid)])
     check(res)
Quoted 5 lines

Thanks

Frank