From: bfields@fieldses.org (J. Bruce Fields)
To: Trond Myklebust <trondmy@gmail.com>
Cc: Steve Dickson <SteveD@redhat.com>,
"J. Bruce Fields" <bfields@redhat.com>,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
Date: Tue, 4 Jun 2019 11:46:11 -0400 [thread overview]
Message-ID: <20190604154611.GC19422@fieldses.org> (raw)
In-Reply-To: <20190603171227.29148-3-trond.myklebust@hammerspace.com>
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?
--b.
> }
>
> char *
> --
> 2.21.0
next prev parent reply other threads:[~2019-06-04 15:46 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 ` J. Bruce Fields [this message]
2019-06-04 17:58 ` [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path Trond Myklebust
2019-06-04 18:01 ` bfields
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=20190604154611.GC19422@fieldses.org \
--to=bfields@fieldses.org \
--cc=SteveD@redhat.com \
--cc=bfields@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@gmail.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).