Re: acl trouble after upgrading ubuntu
[safe/jmp/linux-2.6] / fs / nfs / nfs4xdr.c
index f69aafc..3a71b40 100644 (file)
@@ -39,7 +39,6 @@
 #include <linux/time.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
-#include <linux/utsname.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/in.h>
@@ -2097,7 +2096,7 @@ nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
        encode_compound_hdr(&xdr, req, &hdr);
        encode_sequence(&xdr, &args->seq_args, &hdr);
        encode_putfh(&xdr, args->fh, &hdr);
-       replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
+       replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
        encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
 
        xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
@@ -2423,24 +2422,6 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
 }
 #endif /* CONFIG_NFS_V4_1 */
 
-/*
- * START OF "GENERIC" DECODE ROUTINES.
- *   These may look a little ugly since they are imported from a "generic"
- * set of XDR encode/decode routines which are intended to be shared by
- * all of our NFSv4 implementations (OpenBSD, MacOS X...).
- *
- * If the pain of reading these is too great, it should be a straightforward
- * task to translate them into Linux-specific versions which are more
- * consistent with the style used in NFSv2/v3...
- */
-#define READ_BUF(nbytes)  do { \
-       p = xdr_inline_decode(xdr, nbytes); \
-       if (unlikely(!p)) { \
-               print_overflow_msg(__func__, xdr); \
-               return -EIO; \
-       } \
-} while (0)
-
 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
 {
        dprintk("nfs: %s: prematurely hit end of receive buffer. "
@@ -2452,28 +2433,42 @@ static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char
 {
        __be32 *p;
 
-       READ_BUF(4);
-       *len = be32_to_cpup(p++);
-       READ_BUF(*len);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       *len = be32_to_cpup(p);
+       p = xdr_inline_decode(xdr, *len);
+       if (unlikely(!p))
+               goto out_overflow;
        *string = (char *)p;
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
 {
        __be32 *p;
 
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        hdr->status = be32_to_cpup(p++);
-       hdr->taglen = be32_to_cpup(p++);
+       hdr->taglen = be32_to_cpup(p);
 
-       READ_BUF(hdr->taglen + 4);
+       p = xdr_inline_decode(xdr, hdr->taglen + 4);
+       if (unlikely(!p))
+               goto out_overflow;
        hdr->tag = (char *)p;
        p += XDR_QUADLEN(hdr->taglen);
-       hdr->nops = be32_to_cpup(p++);
+       hdr->nops = be32_to_cpup(p);
        if (unlikely(hdr->nops < 1))
                return nfs4_stat_to_errno(hdr->status);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
@@ -2482,7 +2477,9 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
        uint32_t opnum;
        int32_t nfserr;
 
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        opnum = be32_to_cpup(p++);
        if (opnum != expected) {
                dprintk("nfs: Server returned operation"
@@ -2490,10 +2487,13 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
                                opnum, expected);
                return -EIO;
        }
-       nfserr = be32_to_cpup(p++);
+       nfserr = be32_to_cpup(p);
        if (nfserr != NFS_OK)
                return nfs4_stat_to_errno(nfserr);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 /* Dummy routine */
@@ -2503,8 +2503,11 @@ static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
        unsigned int strlen;
        char *str;
 
-       READ_BUF(12);
-       return decode_opaque_inline(xdr, &strlen, &str);
+       p = xdr_inline_decode(xdr, 12);
+       if (likely(p))
+               return decode_opaque_inline(xdr, &strlen, &str);
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
@@ -2512,27 +2515,39 @@ static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
        uint32_t bmlen;
        __be32 *p;
 
-       READ_BUF(4);
-       bmlen = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       bmlen = be32_to_cpup(p);
 
        bitmap[0] = bitmap[1] = 0;
-       READ_BUF((bmlen << 2));
+       p = xdr_inline_decode(xdr, (bmlen << 2));
+       if (unlikely(!p))
+               goto out_overflow;
        if (bmlen > 0) {
                bitmap[0] = be32_to_cpup(p++);
                if (bmlen > 1)
-                       bitmap[1] = be32_to_cpup(p++);
+                       bitmap[1] = be32_to_cpup(p);
        }
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
 {
        __be32 *p;
 
-       READ_BUF(4);
-       *attrlen = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       *attrlen = be32_to_cpup(p);
        *savep = xdr->p;
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
@@ -2555,8 +2570,10 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
        if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
-               READ_BUF(4);
-               *type = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *type = be32_to_cpup(p);
                if (*type < NF4REG || *type > NF4NAMEDATTR) {
                        dprintk("%s: bad type %d\n", __func__, *type);
                        return -EIO;
@@ -2566,6 +2583,9 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
        }
        dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
@@ -2577,14 +2597,19 @@ static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
        if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, change);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, change);
                bitmap[0] &= ~FATTR4_WORD0_CHANGE;
                ret = NFS_ATTR_FATTR_CHANGE;
        }
        dprintk("%s: change attribute=%Lu\n", __func__,
                        (unsigned long long)*change);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
@@ -2596,13 +2621,18 @@ static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *
        if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, size);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, size);
                bitmap[0] &= ~FATTR4_WORD0_SIZE;
                ret = NFS_ATTR_FATTR_SIZE;
        }
        dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2613,12 +2643,17 @@ static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, ui
        if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
-               READ_BUF(4);
-               *res = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *res = be32_to_cpup(p);
                bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
        }
        dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2629,12 +2664,17 @@ static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap,
        if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
-               READ_BUF(4);
-               *res = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *res = be32_to_cpup(p);
                bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
        }
        dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
@@ -2647,9 +2687,11 @@ static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs
        if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
-               READ_BUF(16);
+               p = xdr_inline_decode(xdr, 16);
+               if (unlikely(!p))
+                       goto out_overflow;
                p = xdr_decode_hyper(p, &fsid->major);
-               p = xdr_decode_hyper(p, &fsid->minor);
+               xdr_decode_hyper(p, &fsid->minor);
                bitmap[0] &= ~FATTR4_WORD0_FSID;
                ret = NFS_ATTR_FATTR_FSID;
        }
@@ -2657,6 +2699,9 @@ static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs
                        (unsigned long long)fsid->major,
                        (unsigned long long)fsid->minor);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2667,12 +2712,17 @@ static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint
        if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
-               READ_BUF(4);
-               *res = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *res = be32_to_cpup(p);
                bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
        }
        dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2683,12 +2733,17 @@ static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint
        if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
-               READ_BUF(4);
-               *res = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *res = be32_to_cpup(p);
                bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
        }
        dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
@@ -2700,13 +2755,18 @@ static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, fileid);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, fileid);
                bitmap[0] &= ~FATTR4_WORD0_FILEID;
                ret = NFS_ATTR_FATTR_FILEID;
        }
        dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
@@ -2718,13 +2778,18 @@ static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitma
        if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, fileid);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, fileid);
                bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
                ret = NFS_ATTR_FATTR_FILEID;
        }
        dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -2736,12 +2801,17 @@ static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
        }
        dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -2753,12 +2823,17 @@ static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
        }
        dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -2770,12 +2845,17 @@ static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
        }
        dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
@@ -2784,8 +2864,10 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
        __be32 *p;
        int status = 0;
 
-       READ_BUF(4);
-       n = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       n = be32_to_cpup(p);
        if (n == 0)
                goto root_path;
        dprintk("path ");
@@ -2819,6 +2901,9 @@ out_eio:
        dprintk(" status %d", status);
        status = -EIO;
        goto out;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
@@ -2836,8 +2921,10 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
        status = decode_pathname(xdr, &res->fs_path);
        if (unlikely(status != 0))
                goto out;
-       READ_BUF(4);
-       n = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       n = be32_to_cpup(p);
        if (n <= 0)
                goto out_eio;
        res->nlocations = 0;
@@ -2845,8 +2932,10 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
                u32 m;
                struct nfs4_fs_location *loc = &res->locations[res->nlocations];
 
-               READ_BUF(4);
-               m = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               m = be32_to_cpup(p);
 
                loc->nservers = 0;
                dprintk("%s: servers ", __func__);
@@ -2885,6 +2974,8 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
 out:
        dprintk("%s: fs_locations done, error = %d\n", __func__, status);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
 out_eio:
        status = -EIO;
        goto out;
@@ -2899,12 +2990,17 @@ static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uin
        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
        }
        dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
@@ -2916,12 +3012,17 @@ static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
-               READ_BUF(4);
-               *maxlink = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *maxlink = be32_to_cpup(p);
                bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
        }
        dprintk("%s: maxlink=%u\n", __func__, *maxlink);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
@@ -2933,12 +3034,17 @@ static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
-               READ_BUF(4);
-               *maxname = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *maxname = be32_to_cpup(p);
                bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
        }
        dprintk("%s: maxname=%u\n", __func__, *maxname);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2951,8 +3057,10 @@ static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
                uint64_t maxread;
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, &maxread);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, &maxread);
                if (maxread > 0x7FFFFFFF)
                        maxread = 0x7FFFFFFF;
                *res = (uint32_t)maxread;
@@ -2960,6 +3068,9 @@ static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
        }
        dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
@@ -2972,8 +3083,10 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
                return -EIO;
        if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
                uint64_t maxwrite;
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, &maxwrite);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, &maxwrite);
                if (maxwrite > 0x7FFFFFFF)
                        maxwrite = 0x7FFFFFFF;
                *res = (uint32_t)maxwrite;
@@ -2981,6 +3094,9 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
        }
        dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
@@ -2993,14 +3109,19 @@ static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *m
        if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
-               READ_BUF(4);
-               tmp = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               tmp = be32_to_cpup(p);
                *mode = tmp & ~S_IFMT;
                bitmap[1] &= ~FATTR4_WORD1_MODE;
                ret = NFS_ATTR_FATTR_MODE;
        }
        dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
@@ -3012,16 +3133,22 @@ static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t
        if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
-               READ_BUF(4);
-               *nlink = be32_to_cpup(p++);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               *nlink = be32_to_cpup(p);
                bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
                ret = NFS_ATTR_FATTR_NLINK;
        }
        dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
-static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
+static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
+               struct nfs_client *clp, uint32_t *uid, int may_sleep)
 {
        uint32_t len;
        __be32 *p;
@@ -3031,10 +3158,16 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
        if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
-               READ_BUF(4);
-               len = be32_to_cpup(p++);
-               READ_BUF(len);
-               if (len < XDR_MAX_NETOBJ) {
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               len = be32_to_cpup(p);
+               p = xdr_inline_decode(xdr, len);
+               if (unlikely(!p))
+                       goto out_overflow;
+               if (!may_sleep) {
+                       /* do nothing */
+               } else if (len < XDR_MAX_NETOBJ) {
                        if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
                                ret = NFS_ATTR_FATTR_OWNER;
                        else
@@ -3047,9 +3180,13 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
        }
        dprintk("%s: uid=%d\n", __func__, (int)*uid);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
-static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
+static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
+               struct nfs_client *clp, uint32_t *gid, int may_sleep)
 {
        uint32_t len;
        __be32 *p;
@@ -3059,10 +3196,16 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
        if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
-               READ_BUF(4);
-               len = be32_to_cpup(p++);
-               READ_BUF(len);
-               if (len < XDR_MAX_NETOBJ) {
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               len = be32_to_cpup(p);
+               p = xdr_inline_decode(xdr, len);
+               if (unlikely(!p))
+                       goto out_overflow;
+               if (!may_sleep) {
+                       /* do nothing */
+               } else if (len < XDR_MAX_NETOBJ) {
                        if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
                                ret = NFS_ATTR_FATTR_GROUP;
                        else
@@ -3075,6 +3218,9 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
        }
        dprintk("%s: gid=%d\n", __func__, (int)*gid);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
@@ -3089,9 +3235,11 @@ static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rde
        if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
                dev_t tmp;
 
-               READ_BUF(8);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
                major = be32_to_cpup(p++);
-               minor = be32_to_cpup(p++);
+               minor = be32_to_cpup(p);
                tmp = MKDEV(major, minor);
                if (MAJOR(tmp) == major && MINOR(tmp) == minor)
                        *rdev = tmp;
@@ -3100,6 +3248,9 @@ static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rde
        }
        dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -3111,12 +3262,17 @@ static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
        }
        dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -3128,12 +3284,17 @@ static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
        }
        dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
@@ -3145,12 +3306,17 @@ static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, res);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, res);
                bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
        }
        dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
@@ -3162,14 +3328,19 @@ static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint
        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
                return -EIO;
        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
-               READ_BUF(8);
-               p = xdr_decode_hyper(p, used);
+               p = xdr_inline_decode(xdr, 8);
+               if (unlikely(!p))
+                       goto out_overflow;
+               xdr_decode_hyper(p, used);
                bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
                ret = NFS_ATTR_FATTR_SPACE_USED;
        }
        dprintk("%s: space used=%Lu\n", __func__,
                        (unsigned long long)*used);
        return ret;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
@@ -3178,12 +3349,17 @@ static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
        uint64_t sec;
        uint32_t nsec;
 
-       READ_BUF(12);
+       p = xdr_inline_decode(xdr, 12);
+       if (unlikely(!p))
+               goto out_overflow;
        p = xdr_decode_hyper(p, &sec);
-       nsec = be32_to_cpup(p++);
+       nsec = be32_to_cpup(p);
        time->tv_sec = (time_t)sec;
        time->tv_nsec = (long)nsec;
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
@@ -3261,11 +3437,16 @@ static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *c
 {
        __be32 *p;
 
-       READ_BUF(20);
+       p = xdr_inline_decode(xdr, 20);
+       if (unlikely(!p))
+               goto out_overflow;
        cinfo->atomic = be32_to_cpup(p++);
        p = xdr_decode_hyper(p, &cinfo->before);
-       p = xdr_decode_hyper(p, &cinfo->after);
+       xdr_decode_hyper(p, &cinfo->after);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
@@ -3277,12 +3458,17 @@ static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
        status = decode_op_hdr(xdr, OP_ACCESS);
        if (status)
                return status;
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        supp = be32_to_cpup(p++);
-       acc = be32_to_cpup(p++);
+       acc = be32_to_cpup(p);
        access->supported = supp;
        access->access = acc;
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
@@ -3341,10 +3527,16 @@ static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
                return status;
        if ((status = decode_change_info(xdr, cinfo)))
                return status;
-       READ_BUF(4);
-       bmlen = be32_to_cpup(p++);
-       READ_BUF(bmlen << 2);
-       return 0;
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       bmlen = be32_to_cpup(p);
+       p = xdr_inline_decode(xdr, bmlen << 2);
+       if (likely(p))
+               return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
@@ -3429,7 +3621,8 @@ xdr_error:
        return status;
 }
 
-static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
+static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
+               const struct nfs_server *server, int may_sleep)
 {
        __be32 *savep;
        uint32_t attrlen,
@@ -3501,12 +3694,14 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
                goto xdr_error;
        fattr->valid |= status;
 
-       status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
+       status = decode_attr_owner(xdr, bitmap, server->nfs_client,
+                       &fattr->uid, may_sleep);
        if (status < 0)
                goto xdr_error;
        fattr->valid |= status;
 
-       status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
+       status = decode_attr_group(xdr, bitmap, server->nfs_client,
+                       &fattr->gid, may_sleep);
        if (status < 0)
                goto xdr_error;
        fattr->valid |= status;
@@ -3596,14 +3791,21 @@ static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
        if (status)
                return status;
 
-       READ_BUF(4);
-       len = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       len = be32_to_cpup(p);
        if (len > NFS4_FHSIZE)
                return -EIO;
        fh->size = len;
-       READ_BUF(len);
+       p = xdr_inline_decode(xdr, len);
+       if (unlikely(!p))
+               goto out_overflow;
        memcpy(fh->data, p, len);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
@@ -3625,7 +3827,9 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
        __be32 *p;
        uint32_t namelen, type;
 
-       READ_BUF(32);
+       p = xdr_inline_decode(xdr, 32);
+       if (unlikely(!p))
+               goto out_overflow;
        p = xdr_decode_hyper(p, &offset);
        p = xdr_decode_hyper(p, &length);
        type = be32_to_cpup(p++);
@@ -3640,9 +3844,13 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
                fl->fl_pid = 0;
        }
        p = xdr_decode_hyper(p, &clientid);
-       namelen = be32_to_cpup(p++);
-       READ_BUF(namelen);
-       return -NFS4ERR_DENIED;
+       namelen = be32_to_cpup(p);
+       p = xdr_inline_decode(xdr, namelen);
+       if (likely(p))
+               return -NFS4ERR_DENIED;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
@@ -3697,18 +3905,23 @@ static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
        __be32 *p;
        uint32_t limit_type, nblocks, blocksize;
 
-       READ_BUF(12);
+       p = xdr_inline_decode(xdr, 12);
+       if (unlikely(!p))
+               goto out_overflow;
        limit_type = be32_to_cpup(p++);
        switch (limit_type) {
        case 1:
-               p = xdr_decode_hyper(p, maxsize);
+               xdr_decode_hyper(p, maxsize);
                break;
        case 2:
                nblocks = be32_to_cpup(p++);
-               blocksize = be32_to_cpup(p++);
+               blocksize = be32_to_cpup(p);
                *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
        }
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
@@ -3717,8 +3930,10 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
        uint32_t delegation_type;
        int status;
 
-       READ_BUF(4);
-       delegation_type = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       delegation_type = be32_to_cpup(p);
        if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
                res->delegation_type = 0;
                return 0;
@@ -3726,8 +3941,10 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
        status = decode_stateid(xdr, &res->delegation);
        if (unlikely(status))
                return status;
-       READ_BUF(4);
-       res->do_recall = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       res->do_recall = be32_to_cpup(p);
 
        switch (delegation_type) {
        case NFS4_OPEN_DELEGATE_READ:
@@ -3739,6 +3956,9 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
                                return -EIO;
        }
        return decode_ace(xdr, NULL, res->server->nfs_client);
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
@@ -3757,13 +3977,17 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
 
        decode_change_info(xdr, &res->cinfo);
 
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        res->rflags = be32_to_cpup(p++);
-       bmlen = be32_to_cpup(p++);
+       bmlen = be32_to_cpup(p);
        if (bmlen > 10)
                goto xdr_error;
 
-       READ_BUF(bmlen << 2);
+       p = xdr_inline_decode(xdr, bmlen << 2);
+       if (unlikely(!p))
+               goto out_overflow;
        savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
        for (i = 0; i < savewords; ++i)
                res->attrset[i] = be32_to_cpup(p++);
@@ -3774,6 +3998,9 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
 xdr_error:
        dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
        return -EIO;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
@@ -3820,9 +4047,11 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_
        status = decode_op_hdr(xdr, OP_READ);
        if (status)
                return status;
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        eof = be32_to_cpup(p++);
-       count = be32_to_cpup(p++);
+       count = be32_to_cpup(p);
        hdrlen = (u8 *) p - (u8 *) iov->iov_base;
        recvd = req->rq_rcv_buf.len - hdrlen;
        if (count > recvd) {
@@ -3835,6 +4064,9 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_
        res->eof = eof;
        res->count = count;
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
@@ -3947,8 +4179,10 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
                return status;
 
        /* Convert length of symlink */
-       READ_BUF(4);
-       len = be32_to_cpup(p++);
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       len = be32_to_cpup(p);
        if (len >= rcvbuf->page_len || len <= 0) {
                dprintk("nfs: server returned giant symlink!\n");
                return -ENAMETOOLONG;
@@ -3972,6 +4206,9 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
        kaddr[len+rcvbuf->page_base] = '\0';
        kunmap_atomic(kaddr, KM_USER0);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
@@ -4069,10 +4306,16 @@ static int decode_setattr(struct xdr_stream *xdr)
        status = decode_op_hdr(xdr, OP_SETATTR);
        if (status)
                return status;
-       READ_BUF(4);
-       bmlen = be32_to_cpup(p++);
-       READ_BUF(bmlen << 2);
-       return 0;
+       p = xdr_inline_decode(xdr, 4);
+       if (unlikely(!p))
+               goto out_overflow;
+       bmlen = be32_to_cpup(p);
+       p = xdr_inline_decode(xdr, bmlen << 2);
+       if (likely(p))
+               return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
@@ -4081,35 +4324,50 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
        uint32_t opnum;
        int32_t nfserr;
 
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        opnum = be32_to_cpup(p++);
        if (opnum != OP_SETCLIENTID) {
                dprintk("nfs: decode_setclientid: Server returned operation"
                        " %d\n", opnum);
                return -EIO;
        }
-       nfserr = be32_to_cpup(p++);
+       nfserr = be32_to_cpup(p);
        if (nfserr == NFS_OK) {
-               READ_BUF(8 + NFS4_VERIFIER_SIZE);
+               p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
+               if (unlikely(!p))
+                       goto out_overflow;
                p = xdr_decode_hyper(p, &clp->cl_clientid);
                memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
        } else if (nfserr == NFSERR_CLID_INUSE) {
                uint32_t len;
 
                /* skip netid string */
-               READ_BUF(4);
-               len = be32_to_cpup(p++);
-               READ_BUF(len);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               len = be32_to_cpup(p);
+               p = xdr_inline_decode(xdr, len);
+               if (unlikely(!p))
+                       goto out_overflow;
 
                /* skip uaddr string */
-               READ_BUF(4);
-               len = be32_to_cpup(p++);
-               READ_BUF(len);
+               p = xdr_inline_decode(xdr, 4);
+               if (unlikely(!p))
+                       goto out_overflow;
+               len = be32_to_cpup(p);
+               p = xdr_inline_decode(xdr, len);
+               if (unlikely(!p))
+                       goto out_overflow;
                return -NFSERR_CLID_INUSE;
        } else
                return nfs4_stat_to_errno(nfserr);
 
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_setclientid_confirm(struct xdr_stream *xdr)
@@ -4126,11 +4384,16 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
        if (status)
                return status;
 
-       READ_BUF(16);
+       p = xdr_inline_decode(xdr, 16);
+       if (unlikely(!p))
+               goto out_overflow;
        res->count = be32_to_cpup(p++);
        res->verf->committed = be32_to_cpup(p++);
        memcpy(res->verf->verifier, p, 8);
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_delegreturn(struct xdr_stream *xdr)
@@ -4144,6 +4407,7 @@ static int decode_exchange_id(struct xdr_stream *xdr,
 {
        __be32 *p;
        uint32_t dummy;
+       char *dummy_str;
        int status;
        struct nfs_client *clp = res->client;
 
@@ -4151,36 +4415,45 @@ static int decode_exchange_id(struct xdr_stream *xdr,
        if (status)
                return status;
 
-       READ_BUF(8);
-       p = xdr_decode_hyper(p, &clp->cl_ex_clid);
-       READ_BUF(12);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
+       xdr_decode_hyper(p, &clp->cl_ex_clid);
+       p = xdr_inline_decode(xdr, 12);
+       if (unlikely(!p))
+               goto out_overflow;
        clp->cl_seqid = be32_to_cpup(p++);
        clp->cl_exchange_flags = be32_to_cpup(p++);
 
        /* We ask for SP4_NONE */
-       dummy = be32_to_cpup(p++);
+       dummy = be32_to_cpup(p);
        if (dummy != SP4_NONE)
                return -EIO;
 
        /* Throw away minor_id */
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
 
        /* Throw away Major id */
-       READ_BUF(4);
-       dummy = be32_to_cpup(p++);
-       READ_BUF(dummy);
+       status = decode_opaque_inline(xdr, &dummy, &dummy_str);
+       if (unlikely(status))
+               return status;
 
        /* Throw away server_scope */
-       READ_BUF(4);
-       dummy = be32_to_cpup(p++);
-       READ_BUF(dummy);
+       status = decode_opaque_inline(xdr, &dummy, &dummy_str);
+       if (unlikely(status))
+               return status;
 
        /* Throw away Implementation id array */
-       READ_BUF(4);
-       dummy = be32_to_cpup(p++);
-       READ_BUF(dummy);
+       status = decode_opaque_inline(xdr, &dummy, &dummy_str);
+       if (unlikely(status))
+               return status;
 
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_chan_attrs(struct xdr_stream *xdr,
@@ -4189,22 +4462,30 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
        __be32 *p;
        u32 nr_attrs;
 
-       READ_BUF(28);
+       p = xdr_inline_decode(xdr, 28);
+       if (unlikely(!p))
+               goto out_overflow;
        attrs->headerpadsz = be32_to_cpup(p++);
        attrs->max_rqst_sz = be32_to_cpup(p++);
        attrs->max_resp_sz = be32_to_cpup(p++);
        attrs->max_resp_sz_cached = be32_to_cpup(p++);
        attrs->max_ops = be32_to_cpup(p++);
        attrs->max_reqs = be32_to_cpup(p++);
-       nr_attrs = be32_to_cpup(p++);
+       nr_attrs = be32_to_cpup(p);
        if (unlikely(nr_attrs > 1)) {
                printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
                        __func__, nr_attrs);
                return -EINVAL;
        }
-       if (nr_attrs == 1)
-               READ_BUF(4); /* skip rdma_attrs */
+       if (nr_attrs == 1) {
+               p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
+               if (unlikely(!p))
+                       goto out_overflow;
+       }
        return 0;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
@@ -4227,15 +4508,20 @@ static int decode_create_session(struct xdr_stream *xdr,
                return status;
 
        /* seqid, flags */
-       READ_BUF(8);
+       p = xdr_inline_decode(xdr, 8);
+       if (unlikely(!p))
+               goto out_overflow;
        clp->cl_seqid = be32_to_cpup(p++);
-       session->flags = be32_to_cpup(p++);
+       session->flags = be32_to_cpup(p);
 
        /* Channel attributes */
        status = decode_chan_attrs(xdr, &session->fc_attrs);
        if (!status)
                status = decode_chan_attrs(xdr, &session->bc_attrs);
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       return -EIO;
 }
 
 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
@@ -4276,7 +4562,9 @@ static int decode_sequence(struct xdr_stream *xdr,
                goto out_err;
        }
 
-       READ_BUF(20);
+       p = xdr_inline_decode(xdr, 20);
+       if (unlikely(!p))
+               goto out_overflow;
 
        /* seqid */
        slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
@@ -4296,11 +4584,15 @@ static int decode_sequence(struct xdr_stream *xdr,
        /* target highest slot id - currently not processed */
        dummy = be32_to_cpup(p++);
        /* result flags - currently not processed */
-       dummy = be32_to_cpup(p++);
+       dummy = be32_to_cpup(p);
        status = 0;
 out_err:
        res->sr_status = status;
        return status;
+out_overflow:
+       print_overflow_msg(__func__, xdr);
+       status = -EIO;
+       goto out_err;
 #else  /* CONFIG_NFS_V4_1 */
        return 0;
 #endif /* CONFIG_NFS_V4_1 */
@@ -4332,7 +4624,8 @@ static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct
        status = decode_open_downgrade(&xdr, res);
        if (status != 0)
                goto out;
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4359,7 +4652,8 @@ static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_ac
        status = decode_access(&xdr, res);
        if (status != 0)
                goto out;
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4386,7 +4680,8 @@ static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lo
                goto out;
        if ((status = decode_getfh(&xdr, res->fh)) != 0)
                goto out;
-       status = decode_getfattr(&xdr, res->fattr, res->server);
+       status = decode_getfattr(&xdr, res->fattr, res->server
+                       ,!RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4410,7 +4705,8 @@ static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nf
        if ((status = decode_putrootfh(&xdr)) != 0)
                goto out;
        if ((status = decode_getfh(&xdr, res->fh)) == 0)
-               status = decode_getfattr(&xdr, res->fattr, res->server);
+               status = decode_getfattr(&xdr, res->fattr, res->server,
+                               !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4435,7 +4731,8 @@ static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_rem
                goto out;
        if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
                goto out;
-       decode_getfattr(&xdr, &res->dir_attr, res->server);
+       decode_getfattr(&xdr, &res->dir_attr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4465,11 +4762,13 @@ static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_re
        if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
                goto out;
        /* Current FH is target directory */
-       if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
+       if (decode_getfattr(&xdr, res->new_fattr, res->server,
+                               !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
                goto out;
        if ((status = decode_restorefh(&xdr)) != 0)
                goto out;
-       decode_getfattr(&xdr, res->old_fattr, res->server);
+       decode_getfattr(&xdr, res->old_fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4502,11 +4801,13 @@ static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link
         * Note order: OP_LINK leaves the directory as the current
         *             filehandle.
         */
-       if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
+       if (decode_getfattr(&xdr, res->dir_attr, res->server,
+                               !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
                goto out;
        if ((status = decode_restorefh(&xdr)) != 0)
                goto out;
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4535,11 +4836,13 @@ static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_cr
                goto out;
        if ((status = decode_getfh(&xdr, res->fh)) != 0)
                goto out;
-       if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
+       if (decode_getfattr(&xdr, res->fattr, res->server,
+                               !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
                goto out;
        if ((status = decode_restorefh(&xdr)) != 0)
                goto out;
-       decode_getfattr(&xdr, res->dir_fattr, res->server);
+       decode_getfattr(&xdr, res->dir_fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4571,7 +4874,8 @@ static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_g
        status = decode_putfh(&xdr);
        if (status)
                goto out;
-       status = decode_getfattr(&xdr, res->fattr, res->server);
+       status = decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4678,7 +4982,8 @@ static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_clos
         *      an ESTALE error. Shouldn't be a problem,
         *      though, since fattr->valid will remain unset.
         */
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4710,11 +5015,13 @@ static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openr
                goto out;
        if (decode_getfh(&xdr, &res->fh) != 0)
                goto out;
-       if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
+       if (decode_getfattr(&xdr, res->f_attr, res->server,
+                               !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
                goto out;
        if (decode_restorefh(&xdr) != 0)
                goto out;
-       decode_getfattr(&xdr, res->dir_attr, res->server);
+       decode_getfattr(&xdr, res->dir_attr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4762,7 +5069,8 @@ static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nf
        status = decode_open(&xdr, res);
        if (status)
                goto out;
-       decode_getfattr(&xdr, res->f_attr, res->server);
+       decode_getfattr(&xdr, res->f_attr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4789,7 +5097,8 @@ static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_se
        status = decode_setattr(&xdr);
        if (status)
                goto out;
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -4963,7 +5272,8 @@ static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writ
        status = decode_write(&xdr, res);
        if (status)
                goto out;
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
        if (!status)
                status = res->count;
 out:
@@ -4992,7 +5302,8 @@ static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_wri
        status = decode_commit(&xdr, res);
        if (status)
                goto out;
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -5156,7 +5467,8 @@ static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nf
        if (status != 0)
                goto out;
        status = decode_delegreturn(&xdr);
-       decode_getfattr(&xdr, res->fattr, res->server);
+       decode_getfattr(&xdr, res->fattr, res->server,
+                       !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
 }
@@ -5184,7 +5496,8 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
                goto out;
        xdr_enter_page(&xdr, PAGE_SIZE);
        status = decode_getfattr(&xdr, &res->fs_locations->fattr,
-                                res->fs_locations->server);
+                                res->fs_locations->server,
+                                !RPC_IS_ASYNC(req->rq_task));
 out:
        return status;
 }
@@ -5368,7 +5681,6 @@ static struct {
        { NFS4ERR_SERVERFAULT,  -ESERVERFAULT   },
        { NFS4ERR_BADTYPE,      -EBADTYPE       },
        { NFS4ERR_LOCKED,       -EAGAIN         },
-       { NFS4ERR_RESOURCE,     -EREMOTEIO      },
        { NFS4ERR_SYMLINK,      -ELOOP          },
        { NFS4ERR_OP_ILLEGAL,   -EOPNOTSUPP     },
        { NFS4ERR_DEADLOCK,     -EDEADLK        },