nfsd4: fix rd_dircount enforcement
Commit3b29970909
"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:3b29970909
"nfsd4: enforce rd_dircount" Signed-off-by: J. Bruce Fields <bfields@redhat.com>
This commit is contained in:
parent
7d1311b93e
commit
aee3776441
|
@ -2657,6 +2657,7 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
|
||||||
struct xdr_stream *xdr = cd->xdr;
|
struct xdr_stream *xdr = cd->xdr;
|
||||||
int start_offset = xdr->buf->len;
|
int start_offset = xdr->buf->len;
|
||||||
int cookie_offset;
|
int cookie_offset;
|
||||||
|
u32 name_and_cookie;
|
||||||
int entry_bytes;
|
int entry_bytes;
|
||||||
__be32 nfserr = nfserr_toosmall;
|
__be32 nfserr = nfserr_toosmall;
|
||||||
__be64 wire_offset;
|
__be64 wire_offset;
|
||||||
|
@ -2718,7 +2719,14 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
|
||||||
cd->rd_maxcount -= entry_bytes;
|
cd->rd_maxcount -= entry_bytes;
|
||||||
if (!cd->rd_dircount)
|
if (!cd->rd_dircount)
|
||||||
goto fail;
|
goto fail;
|
||||||
cd->rd_dircount--;
|
/*
|
||||||
|
* RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
|
||||||
|
* let's always let through the first entry, at least:
|
||||||
|
*/
|
||||||
|
name_and_cookie = 4 * XDR_QUADLEN(namlen) + 8;
|
||||||
|
if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
|
||||||
|
goto fail;
|
||||||
|
cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
|
||||||
cd->cookie_offset = cookie_offset;
|
cd->cookie_offset = cookie_offset;
|
||||||
skip_entry:
|
skip_entry:
|
||||||
cd->common.err = nfs_ok;
|
cd->common.err = nfs_ok;
|
||||||
|
@ -3321,6 +3329,10 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
|
||||||
}
|
}
|
||||||
maxcount = min_t(int, maxcount-16, bytes_left);
|
maxcount = min_t(int, maxcount-16, bytes_left);
|
||||||
|
|
||||||
|
/* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */
|
||||||
|
if (!readdir->rd_dircount)
|
||||||
|
readdir->rd_dircount = INT_MAX;
|
||||||
|
|
||||||
readdir->xdr = xdr;
|
readdir->xdr = xdr;
|
||||||
readdir->rd_maxcount = maxcount;
|
readdir->rd_maxcount = maxcount;
|
||||||
readdir->common.err = 0;
|
readdir->common.err = 0;
|
||||||
|
|
Loading…
Reference in New Issue