Skip to contentSkip to conversation

NFS: Fix send buffer length calculation in nfs3_xdr_setaclargs()

PATCH In review Suresh Jayaraman 4 participants 7 messages Apr 15, 2009 – Apr 16, 2009 2 messages not in the archive

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

PATCH 1/1 NFS: Fix send buffer length calculation in nfs3_xdr_setaclargs()

The recent posixacl fix(commit ae46141ff08f1965b17c531b571953c39ce8b9e2) seems to have introduced a bug that will lead to -EINVAL errors during normal setfacl operations on file or dir. This patch attempts to fix this.

---

fs/nfs/nfs3xdr.c +7 -6
index e6a1932..7cd0069 100644
@@ -702,18 +702,19 @@ nfs3_xdr_setaclargs(struct rpc_rqst *req, __be32 *p,
                    struct nfs3_setaclargs *args)
 {
 	struct xdr_buf *buf = &req->rq_snd_buf;
-	unsigned int base;
+	unsigned int base, len;
+	unsigned int len_in_head = 2 * (2 + 3 * NFS_ACL_MAX_ENTRIES_INLINE);
 	int err;
 
 	p = xdr_encode_fhandle(p, NFS_FH(args->inode));
 	*p++ = htonl(args->mask);
-	req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
-	base = req->rq_slen;
+	len = xdr_adjust_iovec(req->rq_svec, p);
+	base = len;
+	len -= len_in_head; 
+	req->rq_slen = xdr_adjust_iovec(req->rq_svec, p + (len >> 2));
 
 	if (args->npages != 0)
-		xdr_encode_pages(buf, args->pages, 0, args->len);
-	else
-		req->rq_slen += args->len;
+		xdr_encode_pages(buf, args->pages, 0, len);
 
 	err = nfsacl_encode(buf, base, args->inode,
 			    (args->mask & NFS_ACL) ?
#1 lore raw
Quoted 4 lines · Suresh Jayaraman

The recent posixacl fix(commit ae46141ff08f1965b17c531b571953c39ce8b9e2) seems to have introduced a bug that will lead to -EINVAL errors during normal setfacl operations on file or dir. This patch attempts to fix this.

To start with, your len_in_head is in units of 32-bit _words_, whereas len, base, and req->rq_slen are in units of bytes.

Then, 'len' is initialised to the length of the currently encoded part of the RPC header before subtracting 'len_in_head'. The resulting number is then used both as the length of the page array, and to extend the length of the req->rq_svec??? That makes absolutely no sense...

Please check if the following patch fixes things for you.

Trond
------------------------------------------------------------

Quoted 1 line

From b273b42f8b793a4a446015b50a5c1473553af48b Mon Sep 17 00:00:00 2001

From: Trond Myklebust <[email protected]>
Date: Wed, 15 Apr 2009 13:58:45 -0400
Subject: [PATCH] NFS: Fix the XDR iovec calculation in nfs3_xdr_setaclargs

Commit ae46141ff08f1965b17c531b571953c39ce8b9e2 (NFSv3: Fix posix ACL code) introduces a bug in the calculation of the XDR header iovec. In the case where we are inlining the acls, we need to adjust the length of the iovec req->rq_svec, in addition to adjusting the total buffer length.

---
 fs/nfs/nfs3xdr.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/nfs/nfs3xdr.c +2 -1
index e6a1932..35869a4 100644
@@ -713,7 +713,8 @@ nfs3_xdr_setaclargs(struct rpc_rqst *req, __be32 *p,
 	if (args->npages != 0)
 		xdr_encode_pages(buf, args->pages, 0, args->len);
 	else
-		req->rq_slen += args->len;
+		req->rq_slen = xdr_adjust_iovec(req->rq_svec,
+				p + XDR_QUADLEN(args->len));
 
 	err = nfsacl_encode(buf, base, args->inode,
 			    (args->mask & NFS_ACL) ?
Signature · 10 lines
1.6.0.4


-- 
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

A message that is not in the archive (sent off-list or not yet received): 1239818456.5177.88.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#3 lore raw
Quoted 9 lines

Please check if the following patch fixes things for you.

Trond
------------------------------------------------------------

Quoted 1 line

From b273b42f8b793a4a446015b50a5c1473553af48b Mon Sep 17 00:00:00 2001

From: Trond Myklebust <[email protected]>
Date: Wed, 15 Apr 2009 13:58:45 -0400
Subject: [PATCH] NFS: Fix the XDR iovec calculation in nfs3_xdr_setaclargs

Quoted 6 lines

Commit ae46141ff08f1965b17c531b571953c39ce8b9e2 (NFSv3: Fix posix ACL code) introduces a bug in the calculation of the XDR header iovec. In the case where we are inlining the acls, we need to adjust the length of the iovec req->rq_svec, in addition to adjusting the total buffer length.

I just tested and it fixes the problem for me.

Thanks!
Leonardo

#4 lore raw
In reply to a message not in the archive
Quoted 11 lines · Trond Myklebust
Quoted 4 lines · Suresh Jayaraman

The recent posixacl fix(commit ae46141ff08f1965b17c531b571953c39ce8b9e2) seems to have introduced a bug that will lead to -EINVAL errors during normal setfacl operations on file or dir. This patch attempts to fix this.

To start with, your len_in_head is in units of 32-bit _words_, whereas len, base, and req->rq_slen are in units of bytes.

Then, 'len' is initialised to the length of the currently encoded part of the RPC header before subtracting 'len_in_head'. The resulting number

Doh, I got it wrong totally. Thanks for the explaination.

On a side note, I think it would be nice to add little comments in xdr code to explain non-obvious pieces.

Quoted 2 lines

Please check if the following patch fixes things for you.

Yes, the below patch fixes the issue for me too.

Thanks,

Quoted 31 lines

Trond
------------------------------------------------------------

Quoted 1 line

From b273b42f8b793a4a446015b50a5c1473553af48b Mon Sep 17 00:00:00 2001

From: Trond Myklebust <[email protected]>
Date: Wed, 15 Apr 2009 13:58:45 -0400
Subject: [PATCH] NFS: Fix the XDR iovec calculation in nfs3_xdr_setaclargs

Commit ae46141ff08f1965b17c531b571953c39ce8b9e2 (NFSv3: Fix posix ACL code) introduces a bug in the calculation of the XDR header iovec. In the case where we are inlining the acls, we need to adjust the length of the iovec req->rq_svec, in addition to adjusting the total buffer length.

---
 fs/nfs/nfs3xdr.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/nfs/nfs3xdr.c +2 -1
index e6a1932..35869a4 100644
@@ -713,7 +713,8 @@ nfs3_xdr_setaclargs(struct rpc_rqst *req, __be32 *p,
 	if (args->npages != 0)
 		xdr_encode_pages(buf, args->pages, 0, args->len);
 	else
-		req->rq_slen += args->len;
+		req->rq_slen = xdr_adjust_iovec(req->rq_svec,
+				p + XDR_QUADLEN(args->len));
 
 	err = nfsacl_encode(buf, base, args->inode,
 			    (args->mask & NFS_ACL) ?
Signature · 1 line
Suresh Jayaraman
#5 lore raw
Quoted 10 lines · Suresh Jayaraman
Quoted 9 lines · Trond Myklebust
Quoted 4 lines · Suresh Jayaraman

The recent posixacl fix(commit ae46141ff08f1965b17c531b571953c39ce8b9e2) seems to have introduced a bug that will lead to -EINVAL errors during normal setfacl operations on file or dir. This patch attempts to fix this.

To start with, your len_in_head is in units of 32-bit _words_, whereas len, base, and req->rq_slen are in units of bytes.

Quoted 7 lines
Quoted 2 lines

Then, 'len' is initialised to the length of the currently encoded part of the RPC header before subtracting 'len_in_head'. The resulting number

Doh, I got it wrong totally. Thanks for the explaination.

On a side note, I think it would be nice to add little comments in xdr code to explain non-obvious pieces.

As an aside, I think implementing this with xdr_streams might have some clarity benefits.

Quoted 46 lines
Quoted 1 line

Please check if the following patch fixes things for you.

Yes, the below patch fixes the issue for me too.

Thanks,

Quoted 32 lines

Trond
------------------------------------------------------------

Quoted 1 line

From b273b42f8b793a4a446015b50a5c1473553af48b Mon Sep 17 00:00:00 2001

From: Trond Myklebust <[email protected]>
Date: Wed, 15 Apr 2009 13:58:45 -0400
Subject: [PATCH] NFS: Fix the XDR iovec calculation in nfs3_xdr_setaclargs

Commit ae46141ff08f1965b17c531b571953c39ce8b9e2 (NFSv3: Fix posix ACL code) introduces a bug in the calculation of the XDR header iovec. In the case where we are inlining the acls, we need to adjust the length of the iovec req->rq_svec, in addition to adjusting the total buffer length.

---
fs/nfs/nfs3xdr.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
fs/nfs/nfs3xdr.c +2 -1
index e6a1932..35869a4 100644
@@ -713,7 +713,8 @@ nfs3_xdr_setaclargs(struct rpc_rqst *req,  
 __be32 *p,
 	if (args->npages != 0)
 		xdr_encode_pages(buf, args->pages, 0, args->len);
 	else
-		req->rq_slen += args->len;
+		req->rq_slen = xdr_adjust_iovec(req->rq_svec,
+				p + XDR_QUADLEN(args->len));
 
 	err = nfsacl_encode(buf, base, args->inode,
			    (args->mask & NFS_ACL) ?
Signature · 5 lines
Suresh Jayaraman
--
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
#6 lore raw
Quoted 19 lines · Chuck Lever
Quoted 18 lines · Suresh Jayaraman
Quoted 16 lines · Trond Myklebust
Quoted 6 lines · Suresh Jayaraman

The recent posixacl fix(commit ae46141ff08f1965b17c531b571953c39ce8b9e2)
seems to have introduced a bug that will lead to -EINVAL errors during
normal setfacl operations on file or dir. This patch attempts to fix this.

To start with, your len_in_head is in units of 32-bit _words_, whereas
len, base, and req->rq_slen are in units of bytes.

Then, 'len' is initialised to the length of the currently encoded part
of the RPC header before subtracting 'len_in_head'. The resulting number

Quoted 7 lines
Quoted 4 lines

Doh, I got it wrong totally. Thanks for the explaination.

On a side note, I think it would be nice to add little comments in xdr code to explain non-obvious pieces.

As an aside, I think implementing this with xdr_streams might have some clarity benefits.

Possibly, but right now, I just want to merge the one-liner fix into 2.6.30-rc2 and 2.6.29-stable...

Cheers
Trond

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

A message that is not in the archive (sent off-list or not yet received): 1239900127.4198.5.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#8 lore raw
Quoted 22 lines · Trond Myklebust
Quoted 21 lines · Chuck Lever
Quoted 20 lines · Suresh Jayaraman
Quoted 8 lines · Trond Myklebust
Quoted 6 lines · Suresh Jayaraman

The recent posixacl fix(commit ae46141ff08f1965b17c531b571953c39ce8b9e2)
seems to have introduced a bug that will lead to -EINVAL errors during
normal setfacl operations on file or dir. This patch attempts to fix this.

Quoted 8 lines

To start with, your len_in_head is in units of 32-bit _words_, whereas
len, base, and req->rq_slen are in units of bytes.

Then, 'len' is initialised to the length of the currently encoded part
of the RPC header before subtracting 'len_in_head'. The resulting number

Doh, I got it wrong totally. Thanks for the explaination.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

On a side note, I think it would be nice to add little comments in xdr code to explain non-obvious pieces.

As an aside, I think implementing this with xdr_streams might have some clarity benefits.

Possibly, but right now, I just want to merge the one-liner fix into 2.6.30-rc2 and 2.6.29-stable...

No rush, just a suggestion.

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com