Skip to content

Commit 5f0ab1f

Browse files
Trond Myklebustksacilotto
authored andcommitted
nfsd4: Handle the NFSv4 READDIR 'dircount' hint being zero
BugLink: https://bugs.launchpad.net/bugs/1951643 commit f2e717d upstream. 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: <stable@vger.kernel.org> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 6e5c9b4 commit 5f0ab1f

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
@@ -3542,15 +3542,18 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
35423542
goto fail;
35433543
cd->rd_maxcount -= entry_bytes;
35443544
/*
3545-
* RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
3546-
* let's always let through the first entry, at least:
3545+
* RFC 3530 14.2.24 describes rd_dircount as only a "hint", and
3546+
* notes that it could be zero. If it is zero, then the server
3547+
* should enforce only the rd_maxcount value.
35473548
*/
3548-
if (!cd->rd_dircount)
3549-
goto fail;
3550-
name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8;
3551-
if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
3552-
goto fail;
3553-
cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
3549+
if (cd->rd_dircount) {
3550+
name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8;
3551+
if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
3552+
goto fail;
3553+
cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
3554+
if (!cd->rd_dircount)
3555+
cd->rd_maxcount = 0;
3556+
}
35543557

35553558
cd->cookie_offset = cookie_offset;
35563559
skip_entry:

0 commit comments

Comments
 (0)