Skip to contentSkip to conversation

NFSD: TEST_STATEID should not return NFS4ERR_STALE_STATEID

PATCH In review Chuck Lever 2 participants 5 messages May 24, 2012 – May 29, 2012

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

PATCH 1/1 NFSD: TEST_STATEID should not return NFS4ERR_STALE_STATEID

The error values that TEST_STATEID is allowed to return does not include NFS4ERR_STALE_STATEID. In addition, RFC 5661 says:

15.1.16.5. NFS4ERR_STALE_STATEID (Error Code 10023)

A stateid generated by an earlier server instance was used. This error is moot in NFSv4.1 because all operations that take a stateid MUST be preceded by the SEQUENCE operation, and the earlier server instance is detected by the session infrastructure that supports SEQUENCE.

I triggered the NFS4ERR_STALE_STATEID during nograce recovery testing. My client had updated its boot verifier, so the server instance hadn't changed, but the client instance had. Thus the server allowed the SEQUENCE operation, but returned NFS4ERR_STALE_STATEID on the TEST_STATEID operation.

After a client's lease expires, TEST_STATEID should report NFS4ERR_EXPIRED for state IDs that the client tries to recover. I don't see a way to make that happen, though.

Finally, RFC 5661, section 18.48.3 has this:

o Special stateids are always considered invalid (they result in the error code NFS4ERR_BAD_STATEID).

---

Bruce, would you consider taking something like this?

 fs/nfsd/nfs4state.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +4 -3
index 9235cfa..ae1fab3 100644
@@ -3365,12 +3365,13 @@ __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
 	struct nfs4_ol_stateid *ols;
 	__be32 status;
 
+	if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
+		return nfserr_bad_stateid;
 	if (STALE_STATEID(stateid))
-		return nfserr_stale_stateid;
-
+		return nfserr_bad_stateid;
 	s = find_stateid(cl, stateid);
 	if (!s)
-		 return nfserr_stale_stateid;
+		 return nfserr_bad_stateid;
 	status = check_stateid_generation(stateid, &s->sc_stateid, 1);
 	if (status)
 		return status;
#1 lore raw
Quoted 17 lines · Chuck Lever

The error values that TEST_STATEID is allowed to return does not include NFS4ERR_STALE_STATEID. In addition, RFC 5661 says:

15.1.16.5. NFS4ERR_STALE_STATEID (Error Code 10023)

A stateid generated by an earlier server instance was used. This error is moot in NFSv4.1 because all operations that take a stateid MUST be preceded by the SEQUENCE operation, and the earlier server instance is detected by the session infrastructure that supports SEQUENCE.

I triggered the NFS4ERR_STALE_STATEID during nograce recovery testing. My client had updated its boot verifier, so the server instance hadn't changed, but the client instance had. Thus the server allowed the SEQUENCE operation, but returned NFS4ERR_STALE_STATEID on the TEST_STATEID operation.

Quoted 3 lines

After a client's lease expires, TEST_STATEID should report NFS4ERR_EXPIRED for state IDs that the client tries to recover. I don't see a way to make that happen, though.

After the client's lease expires, the SEQUENCE operation will fail.

(Which I believe to be a valid, if unforgiving, server implementation. If we were to implement "courtesy locks" in this case, I believe we'd remember the clientid for longer, permit the SEQUENCE, and fail individual stateid's with EXPIRED as appropriate?)

Quoted 4 lines

Finally, RFC 5661, section 18.48.3 has this:

o Special stateids are always considered invalid (they result in the error code NFS4ERR_BAD_STATEID).

Thanks for the explanation!

Quoted 5 lines

---

Bruce, would you consider taking something like this?

Sure; nits:

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3369

Quoted 13 lines
 fs/nfsd/nfs4state.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +2 -0
index 9235cfa..ae1fab3 100644
@@ -3365,12 +3365,13 @@ __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
 	struct nfs4_ol_stateid *ols;
 	__be32 status;
 
+	if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
+		return nfserr_bad_stateid;

Or inval? This is just a buggy client.

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3371

Quoted 4 lines
fs/nfsd/nfs4state.c +1 -2
 	if (STALE_STATEID(stateid))
-		return nfserr_stale_stateid;
-
+		return nfserr_bad_stateid;

Again, this is just a buggy client, since we shouldn't have gotten past the SEQUENCE in this case unless the client's sending a stateid that's actually someone else's.

If you think it's worth checking for those buggy client cases, we could instaed check that stateid->si_opaque.so_clid and cl->clientid agree. That'd cover the special-stateid checks too.

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3374

Quoted 4 lines
fs/nfsd/nfs4state.c +1 -1
 	s = find_stateid(cl, stateid);
 	if (!s)
-		 return nfserr_stale_stateid;
+		 return nfserr_bad_stateid;

So this must be the case you actually hit. Agreed with this change.

--b.

Quoted 4 lines
fs/nfsd/nfs4state.c +0 -0
 	status = check_stateid_generation(stateid, &s->sc_stateid, 1);
 	if (status)
 		return status;
#2 lore raw
Quoted 55 lines · J. Bruce Fields
Quoted 17 lines · Chuck Lever

The error values that TEST_STATEID is allowed to return does not include NFS4ERR_STALE_STATEID. In addition, RFC 5661 says:

15.1.16.5. NFS4ERR_STALE_STATEID (Error Code 10023)

A stateid generated by an earlier server instance was used. This error is moot in NFSv4.1 because all operations that take a stateid MUST be preceded by the SEQUENCE operation, and the earlier server instance is detected by the session infrastructure that supports SEQUENCE.

I triggered the NFS4ERR_STALE_STATEID during nograce recovery testing. My client had updated its boot verifier, so the server instance hadn't changed, but the client instance had. Thus the server allowed the SEQUENCE operation, but returned NFS4ERR_STALE_STATEID on the TEST_STATEID operation.

Quoted 3 lines

After a client's lease expires, TEST_STATEID should report NFS4ERR_EXPIRED for state IDs that the client tries to recover. I don't see a way to make that happen, though.

After the client's lease expires, the SEQUENCE operation will fail.

(Which I believe to be a valid, if unforgiving, server implementation. If we were to implement "courtesy locks" in this case, I believe we'd remember the clientid for longer, permit the SEQUENCE, and fail individual stateid's with EXPIRED as appropriate?)

Quoted 4 lines

Finally, RFC 5661, section 18.48.3 has this:

o Special stateids are always considered invalid (they result in the error code NFS4ERR_BAD_STATEID).

Thanks for the explanation!

Quoted 5 lines

---

Bruce, would you consider taking something like this?

Sure; nits:

Quoted 11 lines

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

1 files changed, 4 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +0 -0
index 9235cfa..ae1fab3 100644
@@ -3365,12 +3365,13 @@ __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
 	struct nfs4_ol_stateid *ols;
 	__be32 status;
 
Quoted 4 lines

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3369

Quoted 2 lines
fs/nfsd/nfs4state.c +2 -0
+	if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
+		return nfserr_bad_stateid;

Or inval? This is just a buggy client.

RFC 5661 says specifically that TEST_STATEID should return NFS4ERR_BAD_STATEID in this case.

Quoted 9 lines

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3371

Quoted 5 lines
fs/nfsd/nfs4state.c +1 -2
 	if (STALE_STATEID(stateid))
-		return nfserr_stale_stateid;
-
+		return nfserr_bad_stateid;

Again, this is just a buggy client, since we shouldn't have gotten past the SEQUENCE in this case unless the client's sending a stateid that's actually someone else's.

In my nograce test, the server does get past the SEQUENCE. So maybe there's a bug there too?

Quoted 3 lines

If you think it's worth checking for those buggy client cases, we could instaed check that stateid->si_opaque.so_clid and cl->clientid agree. That'd cover the special-stateid checks too.

That's interesting. I can redrive this patch with this change.

Yes, I think checking for buggy clients is a good idea.

Quoted 19 lines

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3374

Quoted 5 lines
fs/nfsd/nfs4state.c +1 -1
 	s = find_stateid(cl, stateid);
 	if (!s)
-		 return nfserr_stale_stateid;
+		 return nfserr_bad_stateid;

So this must be the case you actually hit. Agreed with this change.

--b.

fs/nfsd/nfs4state.c __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) · line 3377

Quoted 4 lines
fs/nfsd/nfs4state.c +0 -0
 	status = check_stateid_generation(stateid, &s->sc_stateid, 1);
 	if (status)
 		return status;

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#3 lore raw

Hi-

Quoted 7 lines · Chuck Lever
Quoted 3 lines · J. Bruce Fields

If you think it's worth checking for those buggy client cases, we could instaed check that stateid->si_opaque.so_clid and cl->clientid agree. That'd cover the special-stateid checks too.

That's interesting. I can redrive this patch with this change.

Doesn't a positive find_stateid(cl, stateid) result guarantee that so_clid and clientid are the same?

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#4 lore raw
Quoted 6 lines · Chuck Lever

Hi-

Quoted 2 lines · Chuck Lever

On May 25, 2012, at 9:46 AM, J. Bruce Fields wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

If you think it's worth checking for those buggy client cases, we could instaed check that stateid->si_opaque.so_clid and cl->clientid agree. That'd cover the special-stateid checks too.

That's interesting. I can redrive this patch with this change.

Doesn't a positive find_stateid(cl, stateid) result guarantee that so_clid and clientid are the same?

No, it only looks at the si_opaque.so_id, and assumes this stateid belongs to the given client. The passed-in client was actually extracted from the sequence at the start of the compound:

	nfsd4_sequence(...)
	{
		...
		session = find_in_sessionid_hashtbl(&seq->sessionid);
		...
		cstate->session = session;
	}

	nfsd4_free_stateid(...)
	{
		struct nfs4_client *cl = cstate->session->se_client;
		...
			... nfs4_validate_stateid(cl, &stateid->ts_id_stateid);
	}

So in theory a confused client sent a free_stateid referencing a stateid that belonged to a client other than the one that the session belonged to, and then we'd see this inconsistency.

--b.