Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nfsd4: tweak rd_dircount accounting

RFC 3530 14.2.24 says

This value represents the length of the names of the directory
entries and the cookie value for these entries. This length
represents the XDR encoding of the data (names and cookies)...

The "xdr encoding" of the name should probably include the 4 bytes for
the length.

But this is all just a hint so not worth e.g. backporting to stable.

Also reshuffle some lines to more clearly group together the
dircount-related code.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>

+4 -3
+4 -3
fs/nfsd/nfs4xdr.c
··· 2768 2768 if (entry_bytes > cd->rd_maxcount) 2769 2769 goto fail; 2770 2770 cd->rd_maxcount -= entry_bytes; 2771 - if (!cd->rd_dircount) 2772 - goto fail; 2773 2771 /* 2774 2772 * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so 2775 2773 * let's always let through the first entry, at least: 2776 2774 */ 2777 - name_and_cookie = 4 * XDR_QUADLEN(namlen) + 8; 2775 + if (!cd->rd_dircount) 2776 + goto fail; 2777 + name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; 2778 2778 if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) 2779 2779 goto fail; 2780 2780 cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); 2781 + 2781 2782 cd->cookie_offset = cookie_offset; 2782 2783 skip_entry: 2783 2784 cd->common.err = nfs_ok;