linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: Bug in xdr_copy_to_scratch???
Date: Fri, 18 Mar 2011 10:16:08 +1100	[thread overview]
Message-ID: <20110318101608.34bb1117@notabene.brown> (raw)
In-Reply-To: <1300384865.28305.27.camel@lade.trondhjem.org>

On Thu, 17 Mar 2011 14:01:05 -0400 Trond Myklebust
<Trond.Myklebust@netapp.com> wrote:

> On Thu, 2011-03-17 at 09:38 +1100, NeilBrown wrote:
> > We should probably submit a fix to 2.6.37-stable though.  For that it
> > is possibly simplest to tell xdr_decode_inline to round nbytes up to
> > a multiple of 4 - would you agree?
> 
> How about the following fix for 2.6.37 stable?

That is good for NFSv3, but NFSv2 has the same problem.  Code fragment is
	p = xdr_inline_decode(xdr, entry->len + 4);
	if (unlikely(!p))
		goto out_overflow;
	entry->name	  = (const char *) p;
	p		 += XDR_QUADLEN(entry->len);
	entry->prev_cookie	  = entry->cookie;
	entry->cookie	  = ntohl(*p++);

so again we have the cookie after the name and they are decoded together.

This is what I have committed to openSUSE 11.3 for the next update.
It may not match the long-term preferred direction, but it is simple and
obviously covers all cases.

NeilBrown

From: NeilBrown <neilb@suse.de>
Subject: Fix cookie decoding problem in NFS
Patch-mainline: no
References: bnc#678123

nfs3proc decode_dirent asks xdr_inline_decode to return a name
buffer and the cookie in a single request.
There could be padding between these, but if xdr_inline_decode
calls xdr_copy_to_scratch, it will assume the padding is at the end.

So in xdr_copy_to_scratch, round up 'nbytes' to we make don't
fail to return useful data.

Acked-by: NeilBrown <neilb@suse.de>
Signed-off-by: Neil Brown <neilb@suse.de>

---
 net/sunrpc/xdr.c |    5 +++++
 1 file changed, 5 insertions(+)

--- linux-2.6.37-openSUSE-11.4.orig/net/sunrpc/xdr.c
+++ linux-2.6.37-openSUSE-11.4/net/sunrpc/xdr.c
@@ -673,6 +673,11 @@ static __be32 *xdr_copy_to_scratch(struc
 	void *cpdest = xdr->scratch.iov_base;
 	size_t cplen = (char *)xdr->end - (char *)xdr->p;
 
+	/* some callers assume we return the full rounded-up
+	 * number of bytes.
+	 */
+	nbytes = XDR_QUADLEN(nbytes)*4;
+
 	if (nbytes > xdr->scratch.iov_len)
 		return NULL;
 	memcpy(cpdest, xdr->p, cplen);

  reply	other threads:[~2011-03-17 23:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-16 10:36 Bug in xdr_copy_to_scratch??? NeilBrown
2011-03-16 13:42 ` Trond Myklebust
2011-03-16 22:38   ` NeilBrown
2011-03-16 22:57     ` Trond Myklebust
2011-03-17 18:01     ` Trond Myklebust
2011-03-17 23:16       ` NeilBrown [this message]
2011-03-17 23:22         ` Trond Myklebust
2011-03-17 23:27           ` Trond Myklebust
2011-03-18  0:51             ` NeilBrown

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=20110318101608.34bb1117@notabene.brown \
    --to=neilb@suse.de \
    --cc=Trond.Myklebust@netapp.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).