All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: "Holger Hoffstätte" <holger.hoffstaette@googlemail.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] nfsd4: tweak rd_dircount accounting
Date: Wed, 7 Jan 2015 15:06:24 -0500	[thread overview]
Message-ID: <20150107200624.GA8119@fieldses.org> (raw)
In-Reply-To: <20150107182141.GA7066@fieldses.org>

From: "J. Bruce Fields" <bfields@redhat.com>

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>
---
 fs/nfsd/nfs4xdr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

On Wed, Jan 07, 2015 at 01:21:41PM -0500, bfields wrote:
> But anyway that reproducer worked and confirmed the following which I'll
> probably pass along upstream today or tomorrow....

I also noticed this nit while I was there.  I'm planning to queue this
up for 3.20.--b.

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 15f7b73e0c0f..91f7a3644ffb 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2768,16 +2768,17 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
 	if (entry_bytes > cd->rd_maxcount)
 		goto fail;
 	cd->rd_maxcount -= entry_bytes;
-	if (!cd->rd_dircount)
-		goto fail;
 	/*
 	 * 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 (!cd->rd_dircount)
+		goto fail;
+	name_and_cookie = 4 + 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;
 skip_entry:
 	cd->common.err = nfs_ok;
-- 
1.9.3


  reply	other threads:[~2015-01-07 20:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-16 22:19 3.18.1: broken directory with one file too many Holger Hoffstätte
2014-12-16 22:19 ` Holger Hoffstätte
2014-12-17 21:22 ` J. Bruce Fields
2014-12-18 12:22   ` Holger Hoffstätte
2014-12-18 12:51     ` Holger Hoffstätte
2014-12-18 12:59       ` Holger Hoffstätte
2014-12-18 14:48     ` J. Bruce Fields
2014-12-18 14:58       ` Benjamin Coddington
2014-12-18 15:19         ` J. Bruce Fields
2014-12-18 15:42           ` Holger Hoffstätte
2014-12-18 16:32             ` J. Bruce Fields
2014-12-18 16:42               ` Holger Hoffstätte
2014-12-18 17:06                 ` J. Bruce Fields
2014-12-18 19:44                   ` Holger Hoffstätte
2014-12-20 18:02                     ` J. Bruce Fields
2014-12-20 18:50                       ` Holger Hoffstätte
2015-01-07  0:25                       ` Holger Hoffstätte
2015-01-07 18:21                         ` J. Bruce Fields
2015-01-07 20:06                           ` J. Bruce Fields [this message]
2014-12-18 17:18           ` J. Bruce Fields
2014-12-18 15:35       ` Holger Hoffstätte
2014-12-18 16:30         ` J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150107200624.GA8119@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=holger.hoffstaette@googlemail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.