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 11:51:46 +1100	[thread overview]
Message-ID: <20110318115146.393119fc@notabene.brown> (raw)
In-Reply-To: <1300404473.4621.4.camel@lade.trondhjem.org>

On Thu, 17 Mar 2011 19:27:53 -0400 Trond Myklebust
<Trond.Myklebust@netapp.com> wrote:

> On Thu, 2011-03-17 at 19:22 -0400, Trond Myklebust wrote:
> > On Fri, 2011-03-18 at 10:16 +1100, NeilBrown wrote:
> > > 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.
> > 
> > Fair enough. I'll fix that one too.
> > 
> 
> Here is the result.
> 
> BTW, those are the only cases we care about in -stable. There are no
> other callers of xdr_set_scratch_buffer().

Yes, I agree.  That is a good fix - thanks.

Reviewed-by: NeilBrown <neilb@suse.de>


Thanks,
NeilBrown

> 
> 8<---------------------------------------------------------------------------------
> >From f71825a9002d4008a5b2ac947bc03b9d7c788557 Mon Sep 17 00:00:00 2001
> From: Trond Myklebust <Trond.Myklebust@netapp.com>
> Date: Thu, 17 Mar 2011 13:42:31 -0400
> Subject: [PATCH] NFS: Fix a decoding problem in nfs3_decode_dirent
> 
> When we decode a filename followed by an 8-byte cookie, we need to
> consider the fact that the filename and cookie are 32-bit word aligned.
> Presently, we may end up copying insufficient amounts of data when
> xdr_inline_decode() needs to invoke xdr_copy_to_scratch to deal
> with a page boundary.
> 
> The following patch fixes the issue by first decoding the filename, and
> then decoding the cookie.
> 
> Reported-by: Neil Brown <neilb@suse.de>
> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
> ---
>  fs/nfs/nfs2xdr.c |    6 ++++--
>  fs/nfs/nfs3xdr.c |    6 ++++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
> index b382a1b..33a038d 100644
> --- a/fs/nfs/nfs2xdr.c
> +++ b/fs/nfs/nfs2xdr.c
> @@ -477,11 +477,13 @@ nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_se
>  	entry->ino	  = ntohl(*p++);
>  	entry->len	  = ntohl(*p++);
>  
> -	p = xdr_inline_decode(xdr, entry->len + 4);
> +	p = xdr_inline_decode(xdr, entry->len);
>  	if (unlikely(!p))
>  		goto out_overflow;
>  	entry->name	  = (const char *) p;
> -	p		 += XDR_QUADLEN(entry->len);
> +	p = xdr_inline_decode(xdr, 4);
> +	if (unlikely(!p))
> +		goto out_overflow;
>  	entry->prev_cookie	  = entry->cookie;
>  	entry->cookie	  = ntohl(*p++);
>  
> diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
> index ba91236..dcd934f 100644
> --- a/fs/nfs/nfs3xdr.c
> +++ b/fs/nfs/nfs3xdr.c
> @@ -614,11 +614,13 @@ nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_s
>  	p = xdr_decode_hyper(p, &entry->ino);
>  	entry->len  = ntohl(*p++);
>  
> -	p = xdr_inline_decode(xdr, entry->len + 8);
> +	p = xdr_inline_decode(xdr, entry->len);
>  	if (unlikely(!p))
>  		goto out_overflow;
>  	entry->name = (const char *) p;
> -	p += XDR_QUADLEN(entry->len);
> +	p = xdr_inline_decode(xdr, 8);
> +	if (unlikely(!p))
> +		goto out_overflow;
>  	entry->prev_cookie = entry->cookie;
>  	p = xdr_decode_hyper(p, &entry->cookie);
>  


      reply	other threads:[~2011-03-18  0:51 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
2011-03-17 23:22         ` Trond Myklebust
2011-03-17 23:27           ` Trond Myklebust
2011-03-18  0:51             ` NeilBrown [this message]

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=20110318115146.393119fc@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).