[2/3] fs: namei: Allow follow_down() to uncover auto mounts

Message ID 20221207084309.8499-3-richard@nod.at
State New
Headers
Series NFS: NFSD: Allow crossing mounts when re-exporting |

Commit Message

Richard Weinberger Dec. 7, 2022, 8:43 a.m. UTC
  This function is only used by NFSD to cross mount points.
If a mount point is of type auto mount, follow_down() will
not uncover it. Add LOOKUP_AUTOMOUNT to the lookup flags
to have ->d_automount() called when NFSD walks down the
mount tree.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/namei.c            | 6 +++---
 fs/nfsd/vfs.c         | 6 +++++-
 include/linux/namei.h | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)
  

Comments

Chuck Lever Dec. 14, 2022, 3:15 p.m. UTC | #1
> On Dec 7, 2022, at 3:43 AM, Richard Weinberger <richard@nod.at> wrote:
> 
> This function is only used by NFSD to cross mount points.
> If a mount point is of type auto mount, follow_down() will
> not uncover it. Add LOOKUP_AUTOMOUNT to the lookup flags
> to have ->d_automount() called when NFSD walks down the
> mount tree.
> 
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
> fs/namei.c            | 6 +++---
> fs/nfsd/vfs.c         | 6 +++++-
> include/linux/namei.h | 2 +-
> 3 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 578c2110df02..a6bb6863bf0c 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -1458,11 +1458,11 @@ EXPORT_SYMBOL(follow_down_one);
>  * point, the filesystem owning that dentry may be queried as to whether the
>  * caller is permitted to proceed or not.
>  */
> -int follow_down(struct path *path)
> +int follow_down(struct path *path, unsigned int flags)
> {
> 	struct vfsmount *mnt = path->mnt;
> 	bool jumped;
> -	int ret = traverse_mounts(path, &jumped, NULL, 0);
> +	int ret = traverse_mounts(path, &jumped, NULL, flags);
> 
> 	if (path->mnt != mnt)
> 		mntput(mnt);
> @@ -2864,7 +2864,7 @@ int path_pts(struct path *path)
> 
> 	path->dentry = child;
> 	dput(parent);
> -	follow_down(path);
> +	follow_down(path, 0);
> 	return 0;
> }
> #endif
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 157f0df0e93a..ced04fc2b947 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -63,9 +63,13 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
> 	struct dentry *dentry = *dpp;
> 	struct path path = {.mnt = mntget(exp->ex_path.mnt),
> 			    .dentry = dget(dentry)};
> +	unsigned int follow_flags = 0;
> 	int err = 0;
> 
> -	err = follow_down(&path);
> +	if (exp->ex_flags & NFSEXP_CROSSMOUNT)
> +		follow_flags = LOOKUP_AUTOMOUNT;
> +
> +	err = follow_down(&path, follow_flags);
> 	if (err < 0)
> 		goto out;
> 	if (path.mnt == exp->ex_path.mnt && path.dentry == dentry &&
> diff --git a/include/linux/namei.h b/include/linux/namei.h
> index 00fee52df842..6f96db73a70a 100644
> --- a/include/linux/namei.h
> +++ b/include/linux/namei.h
> @@ -77,7 +77,7 @@ struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
> 					    struct dentry *base, int len);
> 
> extern int follow_down_one(struct path *);
> -extern int follow_down(struct path *);
> +extern int follow_down(struct path *, unsigned int flags);
> extern int follow_up(struct path *);
> 
> extern struct dentry *lock_rename(struct dentry *, struct dentry *);
> -- 
> 2.26.2
> 

I plan to take this through the nfsd tree, thus this one needs
an Ack from the VFS maintainer(s).


--
Chuck Lever
  
Chuck Lever Jan. 3, 2023, 4:15 p.m. UTC | #2
> On Dec 7, 2022, at 3:43 AM, Richard Weinberger <richard@nod.at> wrote:
> 
> This function is only used by NFSD to cross mount points.
> If a mount point is of type auto mount, follow_down() will
> not uncover it. Add LOOKUP_AUTOMOUNT to the lookup flags
> to have ->d_automount() called when NFSD walks down the
> mount tree.
> 
> Signed-off-by: Richard Weinberger <richard@nod.at>

Hello Al, you are top of the maintainers listed for fs/namei.c.
I'd like to take this series for v6.3 via the nfsd tree. Can
I get your Acked-by: for this one?


> ---
> fs/namei.c            | 6 +++---
> fs/nfsd/vfs.c         | 6 +++++-
> include/linux/namei.h | 2 +-
> 3 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 578c2110df02..a6bb6863bf0c 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -1458,11 +1458,11 @@ EXPORT_SYMBOL(follow_down_one);
>  * point, the filesystem owning that dentry may be queried as to whether the
>  * caller is permitted to proceed or not.
>  */
> -int follow_down(struct path *path)
> +int follow_down(struct path *path, unsigned int flags)
> {
> 	struct vfsmount *mnt = path->mnt;
> 	bool jumped;
> -	int ret = traverse_mounts(path, &jumped, NULL, 0);
> +	int ret = traverse_mounts(path, &jumped, NULL, flags);
> 
> 	if (path->mnt != mnt)
> 		mntput(mnt);
> @@ -2864,7 +2864,7 @@ int path_pts(struct path *path)
> 
> 	path->dentry = child;
> 	dput(parent);
> -	follow_down(path);
> +	follow_down(path, 0);
> 	return 0;
> }
> #endif
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 157f0df0e93a..ced04fc2b947 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -63,9 +63,13 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
> 	struct dentry *dentry = *dpp;
> 	struct path path = {.mnt = mntget(exp->ex_path.mnt),
> 			    .dentry = dget(dentry)};
> +	unsigned int follow_flags = 0;
> 	int err = 0;
> 
> -	err = follow_down(&path);
> +	if (exp->ex_flags & NFSEXP_CROSSMOUNT)
> +		follow_flags = LOOKUP_AUTOMOUNT;
> +
> +	err = follow_down(&path, follow_flags);
> 	if (err < 0)
> 		goto out;
> 	if (path.mnt == exp->ex_path.mnt && path.dentry == dentry &&
> diff --git a/include/linux/namei.h b/include/linux/namei.h
> index 00fee52df842..6f96db73a70a 100644
> --- a/include/linux/namei.h
> +++ b/include/linux/namei.h
> @@ -77,7 +77,7 @@ struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
> 					    struct dentry *base, int len);
> 
> extern int follow_down_one(struct path *);
> -extern int follow_down(struct path *);
> +extern int follow_down(struct path *, unsigned int flags);
> extern int follow_up(struct path *);
> 
> extern struct dentry *lock_rename(struct dentry *, struct dentry *);
> -- 
> 2.26.2
> 

--
Chuck Lever
  
Richard Weinberger Jan. 29, 2023, 3:42 p.m. UTC | #3
----- Ursprüngliche Mail -----
> Von: "chuck lever" <chuck.lever@oracle.com>
>> On Dec 7, 2022, at 3:43 AM, Richard Weinberger <richard@nod.at> wrote:
>> 
>> This function is only used by NFSD to cross mount points.
>> If a mount point is of type auto mount, follow_down() will
>> not uncover it. Add LOOKUP_AUTOMOUNT to the lookup flags
>> to have ->d_automount() called when NFSD walks down the
>> mount tree.
>> 
>> Signed-off-by: Richard Weinberger <richard@nod.at>
> 
> Hello Al, you are top of the maintainers listed for fs/namei.c.
> I'd like to take this series for v6.3 via the nfsd tree. Can
> I get your Acked-by: for this one?

ping?

Thanks,
//richard
  
Al Viro Jan. 30, 2023, 2:15 a.m. UTC | #4
On Sun, Jan 29, 2023 at 04:42:39PM +0100, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
> > Von: "chuck lever" <chuck.lever@oracle.com>
> >> On Dec 7, 2022, at 3:43 AM, Richard Weinberger <richard@nod.at> wrote:
> >> 
> >> This function is only used by NFSD to cross mount points.
> >> If a mount point is of type auto mount, follow_down() will
> >> not uncover it. Add LOOKUP_AUTOMOUNT to the lookup flags
> >> to have ->d_automount() called when NFSD walks down the
> >> mount tree.
> >> 
> >> Signed-off-by: Richard Weinberger <richard@nod.at>
> > 
> > Hello Al, you are top of the maintainers listed for fs/namei.c.
> > I'd like to take this series for v6.3 via the nfsd tree. Can
> > I get your Acked-by: for this one?
> 
> ping?

modulo clumsy wording ("mount point is of type auto mount")

Acked-by: Al Viro <viro@zeniv.linux.org.uk>

Commit message sounds as if it refered to autofs, rather than NFS referrals
et.al. and AFAICS those are the cases it's really about...
  

Patch

diff --git a/fs/namei.c b/fs/namei.c
index 578c2110df02..a6bb6863bf0c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1458,11 +1458,11 @@  EXPORT_SYMBOL(follow_down_one);
  * point, the filesystem owning that dentry may be queried as to whether the
  * caller is permitted to proceed or not.
  */
-int follow_down(struct path *path)
+int follow_down(struct path *path, unsigned int flags)
 {
 	struct vfsmount *mnt = path->mnt;
 	bool jumped;
-	int ret = traverse_mounts(path, &jumped, NULL, 0);
+	int ret = traverse_mounts(path, &jumped, NULL, flags);
 
 	if (path->mnt != mnt)
 		mntput(mnt);
@@ -2864,7 +2864,7 @@  int path_pts(struct path *path)
 
 	path->dentry = child;
 	dput(parent);
-	follow_down(path);
+	follow_down(path, 0);
 	return 0;
 }
 #endif
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 157f0df0e93a..ced04fc2b947 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -63,9 +63,13 @@  nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
 	struct dentry *dentry = *dpp;
 	struct path path = {.mnt = mntget(exp->ex_path.mnt),
 			    .dentry = dget(dentry)};
+	unsigned int follow_flags = 0;
 	int err = 0;
 
-	err = follow_down(&path);
+	if (exp->ex_flags & NFSEXP_CROSSMOUNT)
+		follow_flags = LOOKUP_AUTOMOUNT;
+
+	err = follow_down(&path, follow_flags);
 	if (err < 0)
 		goto out;
 	if (path.mnt == exp->ex_path.mnt && path.dentry == dentry &&
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 00fee52df842..6f96db73a70a 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -77,7 +77,7 @@  struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
 					    struct dentry *base, int len);
 
 extern int follow_down_one(struct path *);
-extern int follow_down(struct path *);
+extern int follow_down(struct path *, unsigned int flags);
 extern int follow_up(struct path *);
 
 extern struct dentry *lock_rename(struct dentry *, struct dentry *);