aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2014-08-20 14:49:50 -0400
committerJ. Bruce Fields <bfields@redhat.com>2014-09-08 12:02:03 -0400
commitaee3776441461c14ba6d8ed9e2149933e65abb6e (patch)
tree3af702f6040859ed2e389218f2860407b3a3373b /fs
parent7d1311b93e58ed55f3a31cc8f94c4b8fe988a2b9 (diff)
nfsd4: fix rd_dircount enforcement
Commit 3b299709091b "nfsd4: enforce rd_dircount" totally misunderstood rd_dircount; it refers to total non-attribute bytes returned, not number of directory entries returned. Bring the code into agreement with RFC 3530 section 14.2.24. Cc: stable@vger.kernel.org Fixes: 3b299709091b "nfsd4: enforce rd_dircount" Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfsd/nfs4xdr.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index f9821ce6658a..e94457c33ad6 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2657,6 +2657,7 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
2657 struct xdr_stream *xdr = cd->xdr; 2657 struct xdr_stream *xdr = cd->xdr;
2658 int start_offset = xdr->buf->len; 2658 int start_offset = xdr->buf->len;
2659 int cookie_offset; 2659 int cookie_offset;
2660 u32 name_and_cookie;
2660 int entry_bytes; 2661 int entry_bytes;
2661 __be32 nfserr = nfserr_toosmall; 2662 __be32 nfserr = nfserr_toosmall;
2662 __be64 wire_offset; 2663 __be64 wire_offset;
@@ -2718,7 +2719,14 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
2718 cd->rd_maxcount -= entry_bytes; 2719 cd->rd_maxcount -= entry_bytes;
2719 if (!cd->rd_dircount) 2720 if (!cd->rd_dircount)
2720 goto fail; 2721 goto fail;
2721 cd->rd_dircount--; 2722 /*
2723 * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
2724 * let's always let through the first entry, at least:
2725 */
2726 name_and_cookie = 4 * XDR_QUADLEN(namlen) + 8;
2727 if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
2728 goto fail;
2729 cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
2722 cd->cookie_offset = cookie_offset; 2730 cd->cookie_offset = cookie_offset;
2723skip_entry: 2731skip_entry:
2724 cd->common.err = nfs_ok; 2732 cd->common.err = nfs_ok;
@@ -3321,6 +3329,10 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
3321 } 3329 }
3322 maxcount = min_t(int, maxcount-16, bytes_left); 3330 maxcount = min_t(int, maxcount-16, bytes_left);
3323 3331
3332 /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */
3333 if (!readdir->rd_dircount)
3334 readdir->rd_dircount = INT_MAX;
3335
3324 readdir->xdr = xdr; 3336 readdir->xdr = xdr;
3325 readdir->rd_maxcount = maxcount; 3337 readdir->rd_maxcount = maxcount;
3326 readdir->common.err = 0; 3338 readdir->common.err = 0;