Skip to content

Commit f2e717d

Browse files
Trond Myklebustchucklever
authored andcommitted
nfsd4: Handle the NFSv4 READDIR 'dircount' hint being zero
RFC3530 notes that the 'dircount' field may be zero, in which case the recommendation is to ignore it, and only enforce the 'maxcount' field. In RFC5661, this recommendation to ignore a zero valued field becomes a requirement. Fixes: aee3776 ("nfsd4: fix rd_dircount enforcement") Cc: <[email protected]> Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 1d62505 commit f2e717d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,15 +3544,18 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
35443544
goto fail;
35453545
cd->rd_maxcount -= entry_bytes;
35463546
/*
3547-
* RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
3548-
* let's always let through the first entry, at least:
3547+
* RFC 3530 14.2.24 describes rd_dircount as only a "hint", and
3548+
* notes that it could be zero. If it is zero, then the server
3549+
* should enforce only the rd_maxcount value.
35493550
*/
3550-
if (!cd->rd_dircount)
3551-
goto fail;
3552-
name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8;
3553-
if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
3554-
goto fail;
3555-
cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
3551+
if (cd->rd_dircount) {
3552+
name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8;
3553+
if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
3554+
goto fail;
3555+
cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
3556+
if (!cd->rd_dircount)
3557+
cd->rd_maxcount = 0;
3558+
}
35563559

35573560
cd->cookie_offset = cookie_offset;
35583561
skip_entry:

0 commit comments

Comments
 (0)