Skip to content

Commit de8a646

Browse files
J. Bruce Fieldsgregkh
authored andcommitted
nfsd4: fix rd_dircount enforcement
commit aee3776 upstream. Commit 3b29970 "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. Fixes: 3b29970 "nfsd4: enforce rd_dircount" Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0203e57 commit de8a646

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎fs/nfsd/nfs4xdr.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,7 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
26622662
struct xdr_stream *xdr = cd->xdr;
26632663
int start_offset = xdr->buf->len;
26642664
int cookie_offset;
2665+
u32 name_and_cookie;
26652666
int entry_bytes;
26662667
__be32 nfserr = nfserr_toosmall;
26672668
__be64 wire_offset;
@@ -2723,7 +2724,14 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
27232724
cd->rd_maxcount -= entry_bytes;
27242725
if (!cd->rd_dircount)
27252726
goto fail;
2726-
cd->rd_dircount--;
2727+
/*
2728+
* RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
2729+
* let's always let through the first entry, at least:
2730+
*/
2731+
name_and_cookie = 4 * XDR_QUADLEN(namlen) + 8;
2732+
if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
2733+
goto fail;
2734+
cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
27272735
cd->cookie_offset = cookie_offset;
27282736
skip_entry:
27292737
cd->common.err = nfs_ok;
@@ -3333,6 +3341,10 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
33333341
}
33343342
maxcount = min_t(int, maxcount-16, bytes_left);
33353343

3344+
/* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */
3345+
if (!readdir->rd_dircount)
3346+
readdir->rd_dircount = INT_MAX;
3347+
33363348
readdir->xdr = xdr;
33373349
readdir->rd_maxcount = maxcount;
33383350
readdir->common.err = 0;

0 commit comments

Comments
 (0)