linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "bfields@fieldses.org" <bfields@fieldses.org>
To: Trond Myklebust <trondmy@hammerspace.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>,
	"SteveD@redhat.com" <SteveD@redhat.com>,
	"bfields@redhat.com" <bfields@redhat.com>
Subject: Re: [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
Date: Tue, 4 Jun 2019 14:01:26 -0400	[thread overview]
Message-ID: <20190604180126.GA2953@fieldses.org> (raw)
In-Reply-To: <1fb61a70b5eea0cd4735aa5ae3050382b317f886.camel@hammerspace.com>

On Tue, Jun 04, 2019 at 05:58:59PM +0000, Trond Myklebust wrote:
> On Tue, 2019-06-04 at 11:46 -0400, J. Bruce Fields wrote:
> > On Mon, Jun 03, 2019 at 01:12:26PM -0400, Trond Myklebust wrote:
> > > When attempting to strip the root path, we should first
> > > canonicalise
> > > the root pathname.
> > > 
> > > Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> > > ---
> > >  support/misc/nfsd_path.c | 17 +++++++++++++----
> > >  1 file changed, 13 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c
> > > index 2f41a793c534..9b38dd96007f 100644
> > > --- a/support/misc/nfsd_path.c
> > > +++ b/support/misc/nfsd_path.c
> > > @@ -1,6 +1,7 @@
> > >  #include <errno.h>
> > >  #include <sys/types.h>
> > >  #include <sys/stat.h>
> > > +#include <limits.h>
> > >  #include <stdlib.h>
> > >  #include <unistd.h>
> > >  
> > > @@ -62,13 +63,21 @@ nfsd_path_nfsd_rootdir(void)
> > >  char *
> > >  nfsd_path_strip_root(char *pathname)
> > >  {
> > > +	char buffer[PATH_MAX];
> > >  	const char *dir = nfsd_path_nfsd_rootdir();
> > >  	char *ret;
> > >  
> > > -	ret = strstr(pathname, dir);
> > > -	if (!ret || ret != pathname)
> > > -		return pathname;
> > > -	return pathname + strlen(dir);
> > > +	if (!dir)
> > > +		goto out;
> > > +	if (realpath(dir, buffer)) {
> > > +		ret = strstr(pathname, buffer);
> > > +		if (ret == pathname)
> > > +			return pathname + strlen(dir);
> > > +	} else
> > > +		xlog(D_GENERAL, "%s: failed to resolve path %s: %m",
> > > +				__func__, dir);
> > > +out:
> > > +	return pathname;
> > 
> > I still don't get this.
> > 
> > So in the case strstr doesn't find anything, it returns the path
> > unchanged.
> > 
> > That means that if the next_mnt() caller asks whether there are any
> > mounts underneath /rootdir/a/b, and nextdir finds a mountpoint at
> > /a/b/c, it can return that, right?
> > 
> 
> Ack. Sending out a v2 of these patches.

Oh, good, thanks, I thought I was going crazy.

(Always a possibility, especially when I'm looking at code.)

--b.

  reply	other threads:[~2019-06-04 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-03 17:12 [PATCH 0/3] Incremental against [exports] rootdir patchset Trond Myklebust
2019-06-03 17:12 ` [PATCH 1/3] mountd: Fix up incorrect comparison in next_mnt() Trond Myklebust
2019-06-03 17:12   ` [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path Trond Myklebust
2019-06-03 17:12     ` [PATCH 3/3] mountd: Canonicalise the rootdir in exportent_mkrealpath() Trond Myklebust
2019-06-04 15:46     ` [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path J. Bruce Fields
2019-06-04 17:58       ` Trond Myklebust
2019-06-04 18:01         ` bfields [this message]
2019-06-10 13:53 ` [PATCH 0/3] Incremental against [exports] rootdir patchset Steve Dickson

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=20190604180126.GA2953@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=SteveD@redhat.com \
    --cc=bfields@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@hammerspace.com \
    /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).