Skip to contentSkip to conversation

RPC: add wrapper for svc_reserve to account for checksum

PATCH In review Jeff Layton 3 participants 8 messages Apr 21, 2007 – May 2, 2007

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

PATCH 1/1 RPC: add wrapper for svc_reserve to account for checksum

When the kernel calls svc_reserve to downsize the expected size of an RPC reply, it fails to account for the possibility of a checksum at the end of the packet. If a client mounts a NFSv2/3 with sec=krb5i/p, and does I/O then you'll generally see messages similar to this in the server's ring buffer:

RPC request reserved 164 but used 208

While I was never able to verify it, I suspect that this problem is also the root cause of some oopses I've seen under these conditions:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=227726

This is probably also a problem for other sec= types and for NFSv4. The large reserved size for NFSv4 compound packets seems to generally paper over the problem, however.

This patch adds a wrapper for svc_reserve that accounts for the possibility of a checksum. It also fixes up the appropriate callers of svc_reserve to call the wrapper. For now, it just uses a hardcoded value that I determined via testing. That value may need to be revised upward as things change, or we may want to eventually add a new auth_op that attempts to calculate this somehow.

Unfortunately, there doesn't seem to be a good way to reliably determine the expected checksum length prior to actually calculating it, particularly with schemes like spkm3.

fs/nfsd/nfs3proc.c +1 -1
index f61142a..7d47c16 100644
@@ -175,7 +175,7 @@ nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
 	if (NFSSVC_MAXBLKSIZE < resp->count)
 		resp->count = NFSSVC_MAXBLKSIZE;
 
-	svc_reserve(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
+	svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
 
 	fh_copy(&resp->fh, &argp->fh);
 	nfserr = nfsd_read(rqstp, &resp->fh, NULL,
fs/nfsd/nfsproc.c +1 -1
index 4e06810..21f2ff7 100644
@@ -154,7 +154,7 @@ nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
 				argp->count);
 		argp->count = NFSSVC_MAXBLKSIZE;
 	}
-	svc_reserve(rqstp, (19<<2) + argp->count + 4);
+	svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
 
 	resp->count = argp->count;
 	nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
include/linux/sunrpc/svc.h +20 -0
index 94350f5..60f24d6 100644
@@ -326,4 +326,24 @@ int		   svc_register(struct svc_serv *, int, unsigned short);
 void		   svc_wake_up(struct svc_serv *);
 void		   svc_reserve(struct svc_rqst *rqstp, int space);
 
+/*
+ * When we want to reduce the size of the reserved space in the response
+ * buffer, we need to take into account the size of any checksum data that
+ * may be at the end of the packet. For now, just use a hardcoded value
+ * for each possible authflavor. This will need to be updated when new
+ * encryption types or algorithms are added, or we'll have to come up with
+ * a way to reasonably calculate this on the fly (maybe via a new auth_op).
+ */
+static inline void 
+svc_reserve_auth(struct svc_rqst *rqstp, int space)
+{
+	int			added_space = 0;
+
+	switch(rqstp->rq_authop->flavour) {
+		case RPC_AUTH_GSS:
+			added_space = 56; /* determined empirically */
+	}
+	return svc_reserve(rqstp, space + added_space);
+}
+
 #endif /* SUNRPC_SVC_H */
net/sunrpc/svc.c +1 -1
index 0aab5b5..2d390d1 100644
@@ -379,7 +379,7 @@ svc_process(struct svc_serv *serv, struct svc_rqst *rqstp)
 	 * better idea of reply size
 	 */
 	if (procp->pc_xdrressize)
-		svc_reserve(rqstp, procp->pc_xdrressize<<2);
+		svc_reserve_auth(rqstp, procp->pc_xdrressize<<2);
 
 	/* Call the function that processes the request. */
 	if (!versp->vs_dispatch) {
net/sunrpc/svcsock.c +0 -0

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#1 lore raw
Quoted 11 lines · On Saturday April 21, [email protected] wrote:

When the kernel calls svc_reserve to downsize the expected size of an RPC reply, it fails to account for the possibility of a checksum at the end of the packet. If a client mounts a NFSv2/3 with sec=krb5i/p, and does I/O then you'll generally see messages similar to this in the server's ring buffer:

RPC request reserved 164 but used 208

While I was never able to verify it, I suspect that this problem is also the root cause of some oopses I've seen under these conditions:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=227726

I don't think to two are that closely related.
The space reservation mentioned in the "RPC request reserved ..." messages is a fairly soft reservation. We try to make sure the network stack reserves a certain amount of space, then try never to start processing a request unless we will be able to reply without exceeding that allocation.
If we get it wrong and do exceed the allocation, the worst that might happen is that we might block while writing the reply and maybe have to close a connection, or send out an incomplete packet, or something like that. Certainly not an oops.

The extra space needed at the end of the message of integrity information which we weren't accounting for properly does seemed to be accounted correctly in svcauth_gss_wrap_resp_integ (I'm less sure of _wrp_resp_priv, but it is probably right).

Of the two Oops in that BUG, the first seems to be the

		BUG_ON(resbuf->tail[0].iov_len);

in svcauth_gss_wrap_resp_integ (assuming code in 2.6.9-44.ELxenU is at least vaguely similar to current -mm).

I don't think this BUG_ON is correct. If a readdir finds zero entries, then will be some trailer information in the 'tail', but page_len will be 0. I think the following patch is correct and could fix that.
Bruce: does it look OK to you?

The second oops is harder to interpret.
I looks like tcp_send_page is getting a NULL page, though it could be getting a length > PAGE_SIZE which might have the same effect.

It reminds me of
http://bugzilla.kernel.org/show_bug.cgi?id=7795
but I'm not convinced it is the same.

Quoted 4 lines

Unfortunately, there doesn't seem to be a good way to reliably determine the expected checksum length prior to actually calculating it, particularly with schemes like spkm3.

Yes, that asn1 encoding does seem rather awkward.

Maybe we should just use RPC_MAX_AUTH_SIZE like other bits of GSS code does. There is no great cost in reserving too much space - it just might slow things down a little when tight on memory.
What would you think of submitting an incremental patch which replaces the "56" with "RPC_MAX_AUTH_SIZE" ?

Thanks (and sorry for the delay).
NeilBrown

--
Simplify (and fix) adding of integrity data to end of rpc message

There is no value in a special case for adding integ data to the 'head' part of the reply in the case where there is no body. Always put it in the 'tail', placing that after the current head if it doesn't have a place yet.
As readdir can potentially return an empty body and a non-empty tail, the BUG_ON can fire.

### Diffstat output

 ./net/sunrpc/auth_gss/svcauth_gss.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +1 -7
diff .prev/net/sunrpc/auth_gss/svcauth_gss.c ./net/sunrpc/auth_gss/svcauth_gss.c
@@ -1210,13 +1210,7 @@ svcauth_gss_wrap_resp_integ(struct svc_r
 	if (xdr_buf_subsegment(resbuf, &integ_buf, integ_offset,
 				integ_len))
 		BUG();
-	if (resbuf->page_len == 0
-			&& resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE
-			< PAGE_SIZE) {
-		BUG_ON(resbuf->tail[0].iov_len);
-		/* Use head for everything */
-		resv = &resbuf->head[0];
-	} else if (resbuf->tail[0].iov_base == NULL) {
+	if (resbuf->tail[0].iov_base == NULL) {
 		if (resbuf->head[0].iov_len + RPC_MAX_AUTH_SIZE > PAGE_SIZE)
 			goto out_err;
 		resbuf->tail[0].iov_base = resbuf->head[0].iov_base

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#2 lore raw
Quoted 3 lines · Neil Brown

I don't think this BUG_ON is correct. If a readdir finds zero entries, then will be some trailer information in the 'tail', but page_len will be 0. I think the following patch is correct and could fix that.

Yep.

Quoted 1 line

Bruce: does it look OK to you?

It looks sensible, but it's a little late for me--I'll take another look at it and run some tests tommorow.

--b.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#3 lore raw
Quoted 5 lines · bfields
Quoted 1 line · Neil Brown

Bruce: does it look OK to you?

It looks sensible, but it's a little late for me--I'll take another look at it and run some tests tommorow.

Just to confirm--yep, loks fine. And I did a quick connectathon run over krb5i just to make sure. If someone wants it:

--b.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#4 lore raw
In reply to Neil Brown
Quoted 55 lines · Neil Brown
Quoted 11 lines · On Saturday April 21, [email protected] wrote:

When the kernel calls svc_reserve to downsize the expected size of an RPC reply, it fails to account for the possibility of a checksum at the end of the packet. If a client mounts a NFSv2/3 with sec=krb5i/p, and does I/O then you'll generally see messages similar to this in the server's ring buffer:

RPC request reserved 164 but used 208

While I was never able to verify it, I suspect that this problem is also the root cause of some oopses I've seen under these conditions:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=227726

I don't think to two are that closely related.
The space reservation mentioned in the "RPC request reserved ..." messages is a fairly soft reservation. We try to make sure the network stack reserves a certain amount of space, then try never to start processing a request unless we will be able to reply without exceeding that allocation.
If we get it wrong and do exceed the allocation, the worst that might happen is that we might block while writing the reply and maybe have to close a connection, or send out an incomplete packet, or something like that. Certainly not an oops.

The extra space needed at the end of the message of integrity information which we weren't accounting for properly does seemed to be accounted correctly in svcauth_gss_wrap_resp_integ (I'm less sure of _wrp_resp_priv, but it is probably right).

Of the two Oops in that BUG, the first seems to be the

		BUG_ON(resbuf->tail[0].iov_len);

in svcauth_gss_wrap_resp_integ (assuming code in 2.6.9-44.ELxenU is at least vaguely similar to current -mm).

I don't think this BUG_ON is correct. If a readdir finds zero entries, then will be some trailer information in the 'tail', but page_len will be 0. I think the following patch is correct and could fix that.
Bruce: does it look OK to you?

The second oops is harder to interpret.
I looks like tcp_send_page is getting a NULL page, though it could be getting a length > PAGE_SIZE which might have the same effect.

It reminds me of
http://bugzilla.kernel.org/show_bug.cgi?id=7795
but I'm not convinced it is the same.

Quoted 4 lines

Unfortunately, there doesn't seem to be a good way to reliably determine the expected checksum length prior to actually calculating it, particularly with schemes like spkm3.

Yes, that asn1 encoding does seem rather awkward.

Quoted 9 lines

Maybe we should just use RPC_MAX_AUTH_SIZE like other bits of GSS code does. There is no great cost in reserving too much space - it just might slow things down a little when tight on memory.
What would you think of submitting an incremental patch which replaces the "56" with "RPC_MAX_AUTH_SIZE" ?

Thanks (and sorry for the delay).
NeilBrown

Thanks for looking into this, Neil. I wasn't sure how hard a reservation that was (still working on wrapping my brain around the RPC code). I'll have a look at the patch you posted. Hopefully that is the problem...

As far as your suggestion to use RPC_MAX_AUTH_SIZE, that sounds like a good idea to me. I'm all for avoiding "magic" numbers. How does this look? I also cleaned up the comments as well.

include/linux/sunrpc/svc.h +4 -5
index 9114f11..ed7cbf1 100644
@@ -399,10 +399,9 @@ char *		   svc_print_addr(struct svc_rqst *, char *, size_t);
 /*
  * When we want to reduce the size of the reserved space in the response
  * buffer, we need to take into account the size of any checksum data that
- * may be at the end of the packet. For now, just use a hardcoded value
- * for each possible authflavor. This will need to be updated when new
- * encryption types or algorithms are added, or we'll have to come up with
- * a way to reasonably calculate this on the fly (maybe via a new auth_op).
+ * may be at the end of the packet. This is difficult to determine exactly
+ * for all cases without actually generating the checksum, so we just use a
+ * static value.
  */
 static inline void 
 svc_reserve_auth(struct svc_rqst *rqstp, int space)
@@ -411,7 +410,7 @@ svc_reserve_auth(struct svc_rqst *rqstp, int space)
 
 	switch(rqstp->rq_authop->flavour) {
 		case RPC_AUTH_GSS:
-			added_space = 56; /* determined empirically */
+			added_space = RPC_MAX_AUTH_SIZE;
 	}
 	return svc_reserve(rqstp, space + added_space);
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#5 lore raw
Quoted 14 lines · Jeff Layton
Quoted 12 lines · Neil Brown

Yes, that asn1 encoding does seem rather awkward.

Maybe we should just use RPC_MAX_AUTH_SIZE like other bits of GSS code does. There is no great cost in reserving too much space - it just might slow things down a little when tight on memory.
What would you think of submitting an incremental patch which replaces the "56" with "RPC_MAX_AUTH_SIZE" ?

Thanks (and sorry for the delay).
NeilBrown

Quoted 8 lines

Thanks for looking into this, Neil. I wasn't sure how hard a reservation that was (still working on wrapping my brain around the RPC code). I'll have a look at the patch you posted. Hopefully that is the problem...

As far as your suggestion to use RPC_MAX_AUTH_SIZE, that sounds like a good idea to me. I'm all for avoiding "magic" numbers. How does this look? I also cleaned up the comments as well.

Resending patch with a proper signed-off-by line. Also cc'ing Andrew:

include/linux/sunrpc/svc.h +4 -5
index 9114f11..ed7cbf1 100644
@@ -399,10 +399,9 @@ char *		   svc_print_addr(struct svc_rqst *, char *, size_t);
 /*
  * When we want to reduce the size of the reserved space in the response
  * buffer, we need to take into account the size of any checksum data that
- * may be at the end of the packet. For now, just use a hardcoded value
- * for each possible authflavor. This will need to be updated when new
- * encryption types or algorithms are added, or we'll have to come up with
- * a way to reasonably calculate this on the fly (maybe via a new auth_op).
+ * may be at the end of the packet. This is difficult to determine exactly
+ * for all cases without actually generating the checksum, so we just use a
+ * static value.
  */
 static inline void 
 svc_reserve_auth(struct svc_rqst *rqstp, int space)
@@ -411,7 +410,7 @@ svc_reserve_auth(struct svc_rqst *rqstp, int space)
 
 	switch(rqstp->rq_authop->flavour) {
 		case RPC_AUTH_GSS:
-			added_space = 56; /* determined empirically */
+			added_space = RPC_MAX_AUTH_SIZE;
 	}
 	return svc_reserve(rqstp, space + added_space);
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

Acked-by
#6 lore raw
Quoted 2 lines · On Tuesday May 1, [email protected] wrote:

Resending patch with a proper signed-off-by line. Also cc'ing Andrew:

Thanks, but it isn't much good to Andrew without a changelog entry, though probably it should just go in as
rpc--add-wrapper-for-svc_reserve-to-account-for-checksum-fix

(If it doesn't appear in the next -mm, I'll send it all nicely formated and changeloged).

NeilBrown

Quoted 30 lines
include/linux/sunrpc/svc.h +4 -5
index 9114f11..ed7cbf1 100644
@@ -399,10 +399,9 @@ char *		   svc_print_addr(struct svc_rqst *, char *, size_t);
 /*
  * When we want to reduce the size of the reserved space in the response
  * buffer, we need to take into account the size of any checksum data that
- * may be at the end of the packet. For now, just use a hardcoded value
- * for each possible authflavor. This will need to be updated when new
- * encryption types or algorithms are added, or we'll have to come up with
- * a way to reasonably calculate this on the fly (maybe via a new auth_op).
+ * may be at the end of the packet. This is difficult to determine exactly
+ * for all cases without actually generating the checksum, so we just use a
+ * static value.
  */
 static inline void 
 svc_reserve_auth(struct svc_rqst *rqstp, int space)
@@ -411,7 +410,7 @@ svc_reserve_auth(struct svc_rqst *rqstp, int space)
 
 	switch(rqstp->rq_authop->flavour) {
 		case RPC_AUTH_GSS:
-			added_space = 56; /* determined empirically */
+			added_space = RPC_MAX_AUTH_SIZE;
 	}
 	return svc_reserve(rqstp, space + added_space);
 }
#7 lore raw
In reply to Neil Brown
Quoted 67 lines · Neil Brown
Quoted 11 lines · On Saturday April 21, [email protected] wrote:

When the kernel calls svc_reserve to downsize the expected size of an RPC reply, it fails to account for the possibility of a checksum at the end of the packet. If a client mounts a NFSv2/3 with sec=krb5i/p, and does I/O then you'll generally see messages similar to this in the server's ring buffer:

RPC request reserved 164 but used 208

While I was never able to verify it, I suspect that this problem is also the root cause of some oopses I've seen under these conditions:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=227726

I don't think to two are that closely related.
The space reservation mentioned in the "RPC request reserved ..." messages is a fairly soft reservation. We try to make sure the network stack reserves a certain amount of space, then try never to start processing a request unless we will be able to reply without exceeding that allocation.
If we get it wrong and do exceed the allocation, the worst that might happen is that we might block while writing the reply and maybe have to close a connection, or send out an incomplete packet, or something like that. Certainly not an oops.

The extra space needed at the end of the message of integrity information which we weren't accounting for properly does seemed to be accounted correctly in svcauth_gss_wrap_resp_integ (I'm less sure of _wrp_resp_priv, but it is probably right).

Of the two Oops in that BUG, the first seems to be the

		BUG_ON(resbuf->tail[0].iov_len);

in svcauth_gss_wrap_resp_integ (assuming code in 2.6.9-44.ELxenU is at least vaguely similar to current -mm).

I don't think this BUG_ON is correct. If a readdir finds zero entries, then will be some trailer information in the 'tail', but page_len will be 0. I think the following patch is correct and could fix that.
Bruce: does it look OK to you?

The second oops is harder to interpret.
I looks like tcp_send_page is getting a NULL page, though it could be getting a length > PAGE_SIZE which might have the same effect.

It reminds me of
http://bugzilla.kernel.org/show_bug.cgi?id=7795
but I'm not convinced it is the same.

Quoted 4 lines

Unfortunately, there doesn't seem to be a good way to reliably determine the expected checksum length prior to actually calculating it, particularly with schemes like spkm3.

Yes, that asn1 encoding does seem rather awkward.

Maybe we should just use RPC_MAX_AUTH_SIZE like other bits of GSS code does. There is no great cost in reserving too much space - it just might slow things down a little when tight on memory.
What would you think of submitting an incremental patch which replaces the "56" with "RPC_MAX_AUTH_SIZE" ?

Thanks (and sorry for the delay).
NeilBrown

--
Simplify (and fix) adding of integrity data to end of rpc message

Quoted 9 lines

There is no value in a special case for adding integ data to the 'head' part of the reply in the case where there is no body. Always put it in the 'tail', placing that after the current head if it doesn't have a place yet.
As readdir can potentially return an empty body and a non-empty tail, the BUG_ON can fire.

Just got through testing this patch. Unfortunately, this panic seems to much more difficult for me to reproduce all of a sudden. I saw it quite a few times at connectathon, but I've tried to get it to occur on fairly recent kernels today and haven't been able to. Perhaps some other change is papering over it somehow.

The patch doesn't seem to break anything, but I can't really confirm whether it fixes these oopses. Still, it seems like a sensible change AFAICT...

-- Jeff

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs