c7a536b
From: Andy Adamson <andros@xxxxxxxxxx>
c7a536b
c7a536b
The NFSv4 bitmap size is unbounded: a server can return an arbitrary
c7a536b
sized bitmap in an FATTR4_WORD0_ACL request.  Replace using the
c7a536b
nfs4_fattr_bitmap_maxsz as a guess to the maximum bitmask returned by a server
c7a536b
with the inclusion of the bitmap (xdr length plus bitmasks) and the acl data
c7a536b
xdr length to the (cached) acl page data.
c7a536b
c7a536b
This is a general solution to commit e5012d1f "NFSv4.1: update
c7a536b
nfs4_fattr_bitmap_maxsz" and fixes hitting a BUG_ON in xdr_shrink_bufhead
c7a536b
when getting ACLs.
c7a536b
c7a536b
Cc:stable@xxxxxxxxxx
c7a536b
Signed-off-by: Andy Adamson <andros@xxxxxxxxxx>
c7a536b
---
c7a536b
 fs/nfs/nfs4proc.c |   20 ++++++++++++++++++--
c7a536b
 fs/nfs/nfs4xdr.c  |   15 ++++++++++++---
c7a536b
 2 files changed, 30 insertions(+), 5 deletions(-)
c7a536b
c7a536b
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
c7a536b
index deb88d9..97014dd 100644
c7a536b
--- a/fs/nfs/nfs4proc.c
c7a536b
+++ b/fs/nfs/nfs4proc.c
c7a536b
@@ -3671,6 +3671,22 @@ static void nfs4_zap_acl_attr(struct inode *inode)
c7a536b
 	nfs4_set_cached_acl(inode, NULL);
c7a536b
 }
c7a536b
 
c7a536b
+/*
c7a536b
+ * The bitmap xdr length, bitmasks, and the attr xdr length are stored in
c7a536b
+ * the acl cache to handle variable length bitmasks. Just copy the acl data.
c7a536b
+ */
c7a536b
+static void nfs4_copy_acl(char *buf, char *acl_data, size_t acl_len)
c7a536b
+{
c7a536b
+	__be32 *q, *p = (__be32 *)acl_data;
c7a536b
+	int32_t len;
c7a536b
+
c7a536b
+	len = be32_to_cpup(p); /* number of bitmasks */
c7a536b
+	len += 2;  /* add words for bitmap and attr xdr len */
c7a536b
+	q = p + len;
c7a536b
+	len = len << 2; /* convert to bytes for acl_len math */
c7a536b
+	memcpy(buf, (char *)q, acl_len - len);
c7a536b
+}
c7a536b
+
c7a536b
 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
c7a536b
 {
c7a536b
 	struct nfs_inode *nfsi = NFS_I(inode);
c7a536b
@@ -3688,7 +3704,7 @@ static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_
c7a536b
 	ret = -ERANGE; /* see getxattr(2) man page */
c7a536b
 	if (acl->len > buflen)
c7a536b
 		goto out;
c7a536b
-	memcpy(buf, acl->data, acl->len);
c7a536b
+	nfs4_copy_acl(buf, acl->data, acl->len);
c7a536b
 out_len:
c7a536b
 	ret = acl->len;
c7a536b
 out:
c7a536b
@@ -3763,7 +3779,7 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
c7a536b
 		if (res.acl_len > buflen)
c7a536b
 			goto out_free;
c7a536b
 		if (localpage)
c7a536b
-			memcpy(buf, resp_buf, res.acl_len);
c7a536b
+			nfs4_copy_acl(buf, resp_buf, res.acl_len);
c7a536b
 	}
c7a536b
 	ret = res.acl_len;
c7a536b
 out_free:
c7a536b
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
c7a536b
index f9fd96d..9c07380 100644
c7a536b
--- a/fs/nfs/nfs4xdr.c
c7a536b
+++ b/fs/nfs/nfs4xdr.c
c7a536b
@@ -2513,7 +2513,7 @@ static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
c7a536b
 	encode_compound_hdr(xdr, req, &hdr);
c7a536b
 	encode_sequence(xdr, &args->seq_args, &hdr);
c7a536b
 	encode_putfh(xdr, args->fh, &hdr);
c7a536b
-	replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
c7a536b
+	replen = hdr.replen + op_decode_hdr_maxsz + 1;
c7a536b
 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
c7a536b
 
c7a536b
 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
c7a536b
@@ -4955,7 +4955,7 @@ decode_restorefh(struct xdr_stream *xdr)
c7a536b
 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
c7a536b
 		size_t *acl_len)
c7a536b
 {
c7a536b
-	__be32 *savep;
c7a536b
+	__be32 *savep, *bm_p;
c7a536b
 	uint32_t attrlen,
c7a536b
 		 bitmap[3] = {0};
c7a536b
 	struct kvec *iov = req->rq_rcv_buf.head;
c7a536b
@@ -4964,6 +4964,7 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
c7a536b
 	*acl_len = 0;
c7a536b
 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
c7a536b
 		goto out;
c7a536b
+	bm_p = xdr->p;
c7a536b
 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
c7a536b
 		goto out;
c7a536b
 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
c7a536b
@@ -4972,12 +4973,20 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
c7a536b
 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
c7a536b
 		return -EIO;
c7a536b
 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
c7a536b
-		size_t hdrlen;
c7a536b
+		size_t hdrlen, len;
c7a536b
 		u32 recvd;
c7a536b
 
c7a536b
+		/*The bitmap (xdr len + bitmasks) and the attr xdr len words
c7a536b
+		 * are stored with the acl data to handle the problem of
c7a536b
+		 * variable length bitmasks.*/
c7a536b
+		xdr->p = bm_p;
c7a536b
+		len = be32_to_cpup(bm_p);
c7a536b
+		len += 2; /* add bitmap and attr xdr len words */
c7a536b
+
c7a536b
 		/* We ignore &savep and don't do consistency checks on
c7a536b
 		 * the attr length.  Let userspace figure it out.... */
c7a536b
 		hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
c7a536b
+		attrlen += len << 2; /* attrlen is in bytes */
c7a536b
 		recvd = req->rq_rcv_buf.len - hdrlen;
c7a536b
 		if (attrlen > recvd) {
c7a536b
 			dprintk("NFS: server cheating in getattr"
c7a536b
-- 
c7a536b
1.7.6.4