* [PATCH 0/3] Incremental against [exports] rootdir patchset
@ 2019-06-03 17:12 Trond Myklebust
2019-06-03 17:12 ` [PATCH 1/3] mountd: Fix up incorrect comparison in next_mnt() Trond Myklebust
2019-06-10 13:53 ` [PATCH 0/3] Incremental against [exports] rootdir patchset Steve Dickson
0 siblings, 2 replies; 8+ messages in thread
From: Trond Myklebust @ 2019-06-03 17:12 UTC (permalink / raw)
To: Steve Dickson; +Cc: J. Bruce Fields, linux-nfs
These patches fix up a couple of bugs and issues against the [exports]
rootdir patchset for nfs-utils.
Trond Myklebust (3):
mountd: Fix up incorrect comparison in next_mnt()
mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
mountd: Canonicalise the rootdir in exportent_mkrealpath()
support/export/export.c | 12 ++++++++++--
support/misc/nfsd_path.c | 17 +++++++++++++----
utils/mountd/cache.c | 2 +-
3 files changed, 24 insertions(+), 7 deletions(-)
--
2.21.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] mountd: Fix up incorrect comparison in next_mnt()
2019-06-03 17:12 [PATCH 0/3] Incremental against [exports] rootdir patchset Trond Myklebust
@ 2019-06-03 17:12 ` Trond Myklebust
2019-06-03 17:12 ` [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path Trond Myklebust
2019-06-10 13:53 ` [PATCH 0/3] Incremental against [exports] rootdir patchset Steve Dickson
1 sibling, 1 reply; 8+ messages in thread
From: Trond Myklebust @ 2019-06-03 17:12 UTC (permalink / raw)
To: Steve Dickson; +Cc: J. Bruce Fields, linux-nfs
We want to ensure that we compare the full name of the last component.
Reported-by: "J. Bruce Fields" <bfields@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
utils/mountd/cache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c
index d818c971bded..d616d526667e 100644
--- a/utils/mountd/cache.c
+++ b/utils/mountd/cache.c
@@ -400,7 +400,7 @@ static char *next_mnt(void **v, char *p)
while ((me = getmntent(f)) != NULL && l > 1) {
mnt_dir = nfsd_path_strip_root(me->mnt_dir);
- if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] != '/')
+ if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] == '/')
return mnt_dir;
}
endmntent(f);
--
2.21.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
2019-06-03 17:12 ` [PATCH 1/3] mountd: Fix up incorrect comparison in next_mnt() Trond Myklebust
@ 2019-06-03 17:12 ` 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
0 siblings, 2 replies; 8+ messages in thread
From: Trond Myklebust @ 2019-06-03 17:12 UTC (permalink / raw)
To: Steve Dickson; +Cc: J. Bruce Fields, linux-nfs
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;
}
char *
--
2.21.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] mountd: Canonicalise the rootdir in exportent_mkrealpath()
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 ` Trond Myklebust
2019-06-04 15:46 ` [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path J. Bruce Fields
1 sibling, 0 replies; 8+ messages in thread
From: Trond Myklebust @ 2019-06-03 17:12 UTC (permalink / raw)
To: Steve Dickson; +Cc: J. Bruce Fields, linux-nfs
Ensure that we canonicalise the export path when generating the
real path.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
support/export/export.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/support/export/export.c b/support/export/export.c
index 82bbb54c5e9e..c753f68e4d63 100644
--- a/support/export/export.c
+++ b/support/export/export.c
@@ -14,6 +14,7 @@
#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in.h>
+#include <limits.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
@@ -21,6 +22,7 @@
#include "nfslib.h"
#include "exportfs.h"
#include "nfsd_path.h"
+#include "xlog.h"
exp_hash_table exportlist[MCL_MAXTYPES] = {{NULL, {{NULL,NULL}, }}, };
static int export_hash(char *);
@@ -38,8 +40,14 @@ exportent_mkrealpath(struct exportent *eep)
const char *chroot = nfsd_path_nfsd_rootdir();
char *ret = NULL;
- if (chroot)
- ret = nfsd_path_prepend_dir(chroot, eep->e_path);
+ if (chroot) {
+ char buffer[PATH_MAX];
+ if (realpath(chroot, buffer))
+ ret = nfsd_path_prepend_dir(buffer, eep->e_path);
+ else
+ xlog(D_GENERAL, "%s: failed to resolve path %s: %m",
+ __func__, chroot);
+ }
if (!ret)
ret = xstrdup(eep->e_path);
eep->e_realpath = ret;
--
2.21.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
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
2019-06-04 17:58 ` Trond Myklebust
1 sibling, 1 reply; 8+ messages in thread
From: J. Bruce Fields @ 2019-06-04 15:46 UTC (permalink / raw)
To: Trond Myklebust; +Cc: Steve Dickson, J. Bruce Fields, linux-nfs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
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
0 siblings, 1 reply; 8+ messages in thread
From: Trond Myklebust @ 2019-06-04 17:58 UTC (permalink / raw)
To: bfields@fieldses.org
Cc: linux-nfs@vger.kernel.org, SteveD@redhat.com, bfields@redhat.com
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.
Thanks Bruce!
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
2019-06-04 17:58 ` Trond Myklebust
@ 2019-06-04 18:01 ` bfields
0 siblings, 0 replies; 8+ messages in thread
From: bfields @ 2019-06-04 18:01 UTC (permalink / raw)
To: Trond Myklebust
Cc: linux-nfs@vger.kernel.org, SteveD@redhat.com, bfields@redhat.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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] Incremental against [exports] rootdir patchset
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-10 13:53 ` Steve Dickson
1 sibling, 0 replies; 8+ messages in thread
From: Steve Dickson @ 2019-06-10 13:53 UTC (permalink / raw)
To: Trond Myklebust; +Cc: J. Bruce Fields, linux-nfs
On 6/3/19 1:12 PM, Trond Myklebust wrote:
> These patches fix up a couple of bugs and issues against the [exports]
> rootdir patchset for nfs-utils.
>
> Trond Myklebust (3):
> mountd: Fix up incorrect comparison in next_mnt()
> mountd: Ensure nfsd_path_strip_root() uses the canonicalised path
> mountd: Canonicalise the rootdir in exportent_mkrealpath()
>
> support/export/export.c | 12 ++++++++++--
> support/misc/nfsd_path.c | 17 +++++++++++++----
> utils/mountd/cache.c | 2 +-
> 3 files changed, 24 insertions(+), 7 deletions(-)
>
Committed!
steved.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-06-10 13:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2019-06-10 13:53 ` [PATCH 0/3] Incremental against [exports] rootdir patchset Steve Dickson
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).