Skip to contentSkip to conversation

vfs - rename user_path_umountat() to user_path_mntpointat()

PATCH In review Ian Kent 2 participants 7 messages Sep 8, 2013 – Sep 9, 2013

Subsystems (2)
lore
Share & tools
lore

Ian Kent

author maintainer
#0 lore raw

PATCH 1/2 vfs - rename user_path_umountat() to user_path_mntpointat()

The function user_path_umountat() not only avoids revalidation but avoids the managed dentry code as well.

This function has other uses, such as the case where autofs is reconnecting to a tree of mounts and needs to avoid the managed dentry call since that would incorrectly cause a callback to the daemon.

So give the function a more descriptive name.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/namei.c            |   34 +++++++++++++++++++---------------
 fs/namespace.c        |    2 +-
 include/linux/namei.h |    2 +-
 3 files changed, 21 insertions(+), 17 deletions(-)
fs/namei.c +19 -15
index f415c66..24f7562 100644
@@ -2250,7 +2250,7 @@ user_path_parent(int dfd, const char __user *path, struct nameidata *nd,
  *         to the link, and nd->path will *not* be put.
  */
 static int
-umount_lookup_last(struct nameidata *nd, struct path *path)
+mntpoint_lookup_last(struct nameidata *nd, struct path *path)
 {
 	int error = 0;
 	struct dentry *dentry;
@@ -2309,17 +2309,19 @@ error_check:
 }
 
 /**
- * path_umountat - look up a path to be umounted
+ * path_mntpointat - look up a path to a mount point
  * @dfd:	directory file descriptor to start walk from
  * @name:	full pathname to walk
  * @flags:	lookup flags
  * @nd:		pathwalk nameidata
  *
- * Look up the given name, but don't attempt to revalidate the last component.
+ * Look up the given name, but don't attempt to revalidate the last component
+ * or call the managed dentry code.
  * Returns 0 and "path" will be valid on success; Retuns error otherwise.
  */
 static int
-path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
+path_mntpointat(int dfd, const char *name,
+		struct path *path, unsigned int flags)
 {
 	struct file *base = NULL;
 	struct nameidata nd;
@@ -2343,7 +2345,7 @@ path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
 		}
 	}
 
-	err = umount_lookup_last(&nd, path);
+	err = mntpoint_lookup_last(&nd, path);
 	while (err > 0) {
 		void *cookie;
 		struct path link = *path;
@@ -2354,7 +2356,7 @@ path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
 		err = follow_link(&link, &nd, &cookie);
 		if (err)
 			break;
-		err = umount_lookup_last(&nd, path);
+		err = mntpoint_lookup_last(&nd, path);
 		put_link(&nd, &link, cookie);
 	}
 out:
@@ -2368,21 +2370,23 @@ out:
 }
 
 /**
- * user_path_umountat - lookup a path from userland in order to umount it
+ * user_path_mntpointat - lookup a mountpoint path from userland without
+ *      revalidating it or calling the managed dentry code
  * @dfd:	directory file descriptor
  * @name:	pathname from userland
  * @flags:	lookup flags
  * @path:	pointer to container to hold result
  *
- * A umount is a special case for path walking. We're not actually interested
- * in the inode in this situation, and ESTALE errors can be a problem. We
- * simply want track down the dentry and vfsmount attached at the mountpoint
- * and avoid revalidating the last component.
+ * A mount point (when being umounted for example) is a special case for path
+ * walking. We're not actually interested in the inode in this situation, and
+ * ESTALE errors can be a problem. We simply want track down the dentry and
+ * vfsmount attached at the mountpoint and avoid revalidating or calling the
+ * managed dentry code for the last component.
  *
  * Returns 0 and populates "path" on success.
  */
 int
-user_path_umountat(int dfd, const char __user *name, unsigned int flags,
+user_path_mntpointat(int dfd, const char __user *name, unsigned int flags,
 			struct path *path)
 {
 	struct filename *s = getname(name);
@@ -2391,11 +2395,11 @@ user_path_umountat(int dfd, const char __user *name, unsigned int flags,
 	if (IS_ERR(s))
 		return PTR_ERR(s);
 
-	error = path_umountat(dfd, s->name, path, flags | LOOKUP_RCU);
+	error = path_mntpointat(dfd, s->name, path, flags | LOOKUP_RCU);
 	if (unlikely(error == -ECHILD))
-		error = path_umountat(dfd, s->name, path, flags);
+		error = path_mntpointat(dfd, s->name, path, flags);
 	if (unlikely(error == -ESTALE))
-		error = path_umountat(dfd, s->name, path, flags | LOOKUP_REVAL);
+		error = path_mntpointat(dfd, s->name, path, flags|LOOKUP_REVAL);
 
 	if (likely(!error))
 		audit_inode(s, path->dentry, 0);
fs/namespace.c +1 -1
index fc2b522..c48ad96 100644
@@ -1321,7 +1321,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
 	if (!(flags & UMOUNT_NOFOLLOW))
 		lookup_flags |= LOOKUP_FOLLOW;
 
-	retval = user_path_umountat(AT_FDCWD, name, lookup_flags, &path);
+	retval = user_path_mntpointat(AT_FDCWD, name, lookup_flags, &path);
 	if (retval)
 		goto out;
 	mnt = real_mount(path.mnt);
include/linux/namei.h +1 -1
index cd09751..7908abf 100644
@@ -58,7 +58,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 
 extern int user_path_at(int, const char __user *, unsigned, struct path *);
 extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
-extern int user_path_umountat(int, const char __user *, unsigned int, struct path *);
+extern int user_path_mntpointat(int, const char __user *, unsigned int, struct path *);
 
 #define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
 #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
author maintainer
#1 lore raw

PATCH 2/2 autofs4 - fix device ioctl mount lookup

When reconnecting to automounts at startup an autofs ioctl is used to find the device and inode of existing mounts so they can be used to open a file descriptor of possibly covered mounts.

At this time the the caller might not yet "own" the mount so it can trigger calling ->d_automount(). This causes automount to hang when trying to reconnect to direct or offset mount types.

Consequently kern_path() can't be used but path_mntpointat() can be.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/autofs4/dev-ioctl.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
fs/autofs4/dev-ioctl.c +12 -11
index 9183821..228866f 100644
@@ -183,13 +183,14 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,
 	return 0;
 }
 
+/* Find the topmost mount satisfying test() */
 static int find_autofs_mount(const char *pathname,
 			     struct path *res,
 			     int test(struct path *path, void *data),
 			     void *data)
 {
 	struct path path;
-	int err = kern_path(pathname, 0, &path);
+	int err = user_path_mntpointat(AT_FDCWD, pathname, 0, &path);
 	if (err)
 		return err;
 	err = -ENOENT;
@@ -197,10 +198,9 @@ static int find_autofs_mount(const char *pathname,
 		if (path.dentry->d_sb->s_magic == AUTOFS_SUPER_MAGIC) {
 			if (test(&path, data)) {
 				path_get(&path);
-				if (!err) /* already found some */
-					path_put(res);
 				*res = path;
 				err = 0;
+				break;
 			}
 		}
 		if (!follow_up(&path))
@@ -498,12 +498,11 @@ static int autofs_dev_ioctl_askumount(struct file *fp,
  * mount if there is one or 0 if it isn't a mountpoint.
  *
  * If we aren't supplied with a file descriptor then we
- * lookup the nameidata of the path and check if it is the
- * root of a mount. If a type is given we are looking for
- * a particular autofs mount and if we don't find a match
- * we return fail. If the located nameidata path is the
- * root of a mount we return 1 along with the super magic
- * of the mount or 0 otherwise.
+ * lookup the path and check if it is the root of a mount.
+ * If a type is given we are looking for a particular autofs
+ * mount and if we don't find a match we return fail. If the
+ * located path is the root of a mount we return 1 along with
+ * the super magic of the mount or 0 otherwise.
  *
  * In both cases the the device number (as returned by
  * new_encode_dev()) is also returned.
@@ -531,9 +530,11 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
 
 	if (!fp || param->ioctlfd == -1) {
 		if (autofs_type_any(type))
-			err = kern_path(name, LOOKUP_FOLLOW, &path);
+			err = user_path_mntpointat(AT_FDCWD,
+						   name, LOOKUP_FOLLOW, &path);
 		else
-			err = find_autofs_mount(name, &path, test_by_type, &type);
+			err = find_autofs_mount(name, &path,
+						test_by_type, &type);
 		if (err)
 			goto out;
 		devid = new_encode_dev(path.dentry->d_sb->s_dev);
#2 lore raw

Re: [PATCH 2/2] autofs4 - fix device ioctl mount lookup

Quoted 24 lines · On Sun, 08 Sep 2013 16:47:23 +0800 Ian Kent <[email protected]> wrote:

When reconnecting to automounts at startup an autofs ioctl is used to find the device and inode of existing mounts so they can be used to open a file descriptor of possibly covered mounts.

At this time the the caller might not yet "own" the mount so it can trigger calling ->d_automount(). This causes automount to hang when trying to reconnect to direct or offset mount types.

Consequently kern_path() can't be used but path_mntpointat() can be.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/autofs4/dev-ioctl.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
fs/autofs4/dev-ioctl.c +0 -0
index 9183821..228866f 100644
@@ -183,13 +183,14 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,
 	return 0;
 }

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_protosubver(struct file *fp, · line 193

Quoted 10 lines
fs/autofs4/dev-ioctl.c +2 -1
 
+/* Find the topmost mount satisfying test() */
 static int find_autofs_mount(const char *pathname,
 			     struct path *res,
 			     int test(struct path *path, void *data),
 			     void *data)
 {
 	struct path path;
-	int err = kern_path(pathname, 0, &path);
+	int err = user_path_mntpointat(AT_FDCWD, pathname, 0, &path);

This looks wrong. "pathname" is a kernel string, not a __user one. I think what you need to do here is to turn user_path_mntpointat into a wrapper around a kern_path_mntpointat equivalent and then call that here.

Quoted 34 lines
fs/autofs4/dev-ioctl.c +6 -8
 	if (err)
 		return err;
 	err = -ENOENT;
@@ -197,10 +198,9 @@ static int find_autofs_mount(const char *pathname,
 		if (path.dentry->d_sb->s_magic == AUTOFS_SUPER_MAGIC) {
 			if (test(&path, data)) {
 				path_get(&path);
-				if (!err) /* already found some */
-					path_put(res);
 				*res = path;
 				err = 0;
+				break;
 			}
 		}
 		if (!follow_up(&path))
@@ -498,12 +498,11 @@ static int autofs_dev_ioctl_askumount(struct file *fp,
  * mount if there is one or 0 if it isn't a mountpoint.
  *
  * If we aren't supplied with a file descriptor then we
- * lookup the nameidata of the path and check if it is the
- * root of a mount. If a type is given we are looking for
- * a particular autofs mount and if we don't find a match
- * we return fail. If the located nameidata path is the
- * root of a mount we return 1 along with the super magic
- * of the mount or 0 otherwise.
+ * lookup the path and check if it is the root of a mount.
+ * If a type is given we are looking for a particular autofs
+ * mount and if we don't find a match we return fail. If the
+ * located path is the root of a mount we return 1 along with
+ * the super magic of the mount or 0 otherwise.
  *
  * In both cases the the device number (as returned by
  * new_encode_dev()) is also returned.

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_ismountpoint(struct file *fp, · line 537

Quoted 10 lines
fs/autofs4/dev-ioctl.c +4 -2
@@ -531,9 +530,11 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
 
 	if (!fp || param->ioctlfd == -1) {
 		if (autofs_type_any(type))
-			err = kern_path(name, LOOKUP_FOLLOW, &path);
+			err = user_path_mntpointat(AT_FDCWD,
+						   name, LOOKUP_FOLLOW, &path);
 		else
-			err = find_autofs_mount(name, &path, test_by_type, &type);
+			err = find_autofs_mount(name, &path,
+						test_by_type, &type);

...ditto in these spots of course...

Quoted 4 lines
fs/autofs4/dev-ioctl.c +0 -0
 		if (err)
 			goto out;
 		devid = new_encode_dev(path.dentry->d_sb->s_dev);
Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#3 lore raw

Re: [PATCH 2/2] autofs4 - fix device ioctl mount lookup

Quoted 28 lines · Jeff Layton
Quoted 25 lines · On Sun, 08 Sep 2013 16:47:23 +0800 Ian Kent <[email protected]> wrote:

When reconnecting to automounts at startup an autofs ioctl is used to find the device and inode of existing mounts so they can be used to open a file descriptor of possibly covered mounts.

At this time the the caller might not yet "own" the mount so it can trigger calling ->d_automount(). This causes automount to hang when trying to reconnect to direct or offset mount types.

Consequently kern_path() can't be used but path_mntpointat() can be.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/autofs4/dev-ioctl.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
fs/autofs4/dev-ioctl.c +0 -0
index 9183821..228866f 100644
@@ -183,13 +183,14 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,
 	return 0;
 }
 
Quoted 14 lines

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_protosubver(struct file *fp, · line 193

Quoted 9 lines
fs/autofs4/dev-ioctl.c +2 -1
+/* Find the topmost mount satisfying test() */
 static int find_autofs_mount(const char *pathname,
 			     struct path *res,
 			     int test(struct path *path, void *data),
 			     void *data)
 {
 	struct path path;
-	int err = kern_path(pathname, 0, &path);
+	int err = user_path_mntpointat(AT_FDCWD, pathname, 0, &path);

This looks wrong. "pathname" is a kernel string, not a __user one. I think what you need to do here is to turn user_path_mntpointat into a wrapper around a kern_path_mntpointat equivalent and then call that here.

In both cases the path comes from a structure passed from user space. So I started thinking it wasn't correct previously.

Quoted 55 lines
Quoted 35 lines
fs/autofs4/dev-ioctl.c +6 -8
 	if (err)
 		return err;
 	err = -ENOENT;
@@ -197,10 +198,9 @@ static int find_autofs_mount(const char *pathname,
 		if (path.dentry->d_sb->s_magic == AUTOFS_SUPER_MAGIC) {
 			if (test(&path, data)) {
 				path_get(&path);
-				if (!err) /* already found some */
-					path_put(res);
 				*res = path;
 				err = 0;
+				break;
 			}
 		}
 		if (!follow_up(&path))
@@ -498,12 +498,11 @@ static int autofs_dev_ioctl_askumount(struct file *fp,
  * mount if there is one or 0 if it isn't a mountpoint.
  *
  * If we aren't supplied with a file descriptor then we
- * lookup the nameidata of the path and check if it is the
- * root of a mount. If a type is given we are looking for
- * a particular autofs mount and if we don't find a match
- * we return fail. If the located nameidata path is the
- * root of a mount we return 1 along with the super magic
- * of the mount or 0 otherwise.
+ * lookup the path and check if it is the root of a mount.
+ * If a type is given we are looking for a particular autofs
+ * mount and if we don't find a match we return fail. If the
+ * located path is the root of a mount we return 1 along with
+ * the super magic of the mount or 0 otherwise.
  *
  * In both cases the the device number (as returned by
  * new_encode_dev()) is also returned.

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_ismountpoint(struct file *fp, · line 537

Quoted 10 lines
fs/autofs4/dev-ioctl.c +4 -2
@@ -531,9 +530,11 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
 
 	if (!fp || param->ioctlfd == -1) {
 		if (autofs_type_any(type))
-			err = kern_path(name, LOOKUP_FOLLOW, &path);
+			err = user_path_mntpointat(AT_FDCWD,
+						   name, LOOKUP_FOLLOW, &path);
 		else
-			err = find_autofs_mount(name, &path, test_by_type, &type);
+			err = find_autofs_mount(name, &path,
+						test_by_type, &type);

...ditto in these spots of course...

Quoted 4 lines
fs/autofs4/dev-ioctl.c +0 -0
 		if (err)
 			goto out;
 		devid = new_encode_dev(path.dentry->d_sb->s_dev);
#4 lore raw

Re: [PATCH 2/2] autofs4 - fix device ioctl mount lookup

Quoted 44 lines · On Mon, 09 Sep 2013 15:18:00 +0800 Ian Kent <[email protected]> wrote:
Quoted 28 lines · Jeff Layton
Quoted 25 lines · On Sun, 08 Sep 2013 16:47:23 +0800 Ian Kent <[email protected]> wrote:

When reconnecting to automounts at startup an autofs ioctl is used to find the device and inode of existing mounts so they can be used to open a file descriptor of possibly covered mounts.

At this time the the caller might not yet "own" the mount so it can trigger calling ->d_automount(). This causes automount to hang when trying to reconnect to direct or offset mount types.

Consequently kern_path() can't be used but path_mntpointat() can be.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/autofs4/dev-ioctl.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
fs/autofs4/dev-ioctl.c +0 -0
index 9183821..228866f 100644
@@ -183,13 +183,14 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,
 	return 0;
 }
 
Quoted 14 lines

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_protosubver(struct file *fp, · line 193

Quoted 9 lines
fs/autofs4/dev-ioctl.c +2 -1
+/* Find the topmost mount satisfying test() */
 static int find_autofs_mount(const char *pathname,
 			     struct path *res,
 			     int test(struct path *path, void *data),
 			     void *data)
 {
 	struct path path;
-	int err = kern_path(pathname, 0, &path);
+	int err = user_path_mntpointat(AT_FDCWD, pathname, 0, &path);

This looks wrong. "pathname" is a kernel string, not a __user one. I think what you need to do here is to turn user_path_mntpointat into a wrapper around a kern_path_mntpointat equivalent and then call that here.

Quoted 3 lines

In both cases the path comes from a structure passed from user space. So I started thinking it wasn't correct previously.

AFAICT, this is a kernel string by the time it gets here.

_autofs_dev_ioctl calls copy_dev_ioctl, which copies that struct from userland to a kernel buffer.

Quoted 57 lines
Quoted 55 lines
Quoted 35 lines
fs/autofs4/dev-ioctl.c +6 -8
 	if (err)
 		return err;
 	err = -ENOENT;
@@ -197,10 +198,9 @@ static int find_autofs_mount(const char *pathname,
 		if (path.dentry->d_sb->s_magic == AUTOFS_SUPER_MAGIC) {
 			if (test(&path, data)) {
 				path_get(&path);
-				if (!err) /* already found some */
-					path_put(res);
 				*res = path;
 				err = 0;
+				break;
 			}
 		}
 		if (!follow_up(&path))
@@ -498,12 +498,11 @@ static int autofs_dev_ioctl_askumount(struct file *fp,
  * mount if there is one or 0 if it isn't a mountpoint.
  *
  * If we aren't supplied with a file descriptor then we
- * lookup the nameidata of the path and check if it is the
- * root of a mount. If a type is given we are looking for
- * a particular autofs mount and if we don't find a match
- * we return fail. If the located nameidata path is the
- * root of a mount we return 1 along with the super magic
- * of the mount or 0 otherwise.
+ * lookup the path and check if it is the root of a mount.
+ * If a type is given we are looking for a particular autofs
+ * mount and if we don't find a match we return fail. If the
+ * located path is the root of a mount we return 1 along with
+ * the super magic of the mount or 0 otherwise.
  *
  * In both cases the the device number (as returned by
  * new_encode_dev()) is also returned.

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_ismountpoint(struct file *fp, · line 537

Quoted 10 lines
fs/autofs4/dev-ioctl.c +4 -2
@@ -531,9 +530,11 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
 
 	if (!fp || param->ioctlfd == -1) {
 		if (autofs_type_any(type))
-			err = kern_path(name, LOOKUP_FOLLOW, &path);
+			err = user_path_mntpointat(AT_FDCWD,
+						   name, LOOKUP_FOLLOW, &path);
 		else
-			err = find_autofs_mount(name, &path, test_by_type, &type);
+			err = find_autofs_mount(name, &path,
+						test_by_type, &type);

...ditto in these spots of course...

Quoted 4 lines
fs/autofs4/dev-ioctl.c +0 -0
 		if (err)
 			goto out;
 		devid = new_encode_dev(path.dentry->d_sb->s_dev);
Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#5 lore raw

Re: [PATCH 2/2] autofs4 - fix device ioctl mount lookup

Quoted 47 lines · Jeff Layton
Quoted 44 lines · On Mon, 09 Sep 2013 15:18:00 +0800 Ian Kent <[email protected]> wrote:
Quoted 42 lines · Jeff Layton
Quoted 24 lines · On Sun, 08 Sep 2013 16:47:23 +0800 Ian Kent <[email protected]> wrote:

When reconnecting to automounts at startup an autofs ioctl is used to find the device and inode of existing mounts so they can be used to open a file descriptor of possibly covered mounts.

At this time the the caller might not yet "own" the mount so it can trigger calling ->d_automount(). This causes automount to hang when trying to reconnect to direct or offset mount types.

Consequently kern_path() can't be used but path_mntpointat() can be.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/autofs4/dev-ioctl.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
fs/autofs4/dev-ioctl.c +0 -0
index 9183821..228866f 100644
@@ -183,13 +183,14 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,
 	return 0;
 }

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_protosubver(struct file *fp, · line 193

Quoted 10 lines
fs/autofs4/dev-ioctl.c +2 -1
 
+/* Find the topmost mount satisfying test() */
 static int find_autofs_mount(const char *pathname,
 			     struct path *res,
 			     int test(struct path *path, void *data),
 			     void *data)
 {
 	struct path path;
-	int err = kern_path(pathname, 0, &path);
+	int err = user_path_mntpointat(AT_FDCWD, pathname, 0, &path);

This looks wrong. "pathname" is a kernel string, not a __user one. I think what you need to do here is to turn user_path_mntpointat into a wrapper around a kern_path_mntpointat equivalent and then call that here.

Quoted 8 lines
Quoted 3 lines

In both cases the path comes from a structure passed from user space. So I started thinking it wasn't correct previously.

AFAICT, this is a kernel string by the time it gets here.

_autofs_dev_ioctl calls copy_dev_ioctl, which copies that struct from userland to a kernel buffer.

Yeah, right you are, doesn't matter now anyway.
I expect we'll go with what Al has in his for-next branch.

Quoted 60 lines
Quoted 58 lines
Quoted 56 lines
Quoted 36 lines
fs/autofs4/dev-ioctl.c +6 -8
 	if (err)
 		return err;
 	err = -ENOENT;
@@ -197,10 +198,9 @@ static int find_autofs_mount(const char *pathname,
 		if (path.dentry->d_sb->s_magic == AUTOFS_SUPER_MAGIC) {
 			if (test(&path, data)) {
 				path_get(&path);
-				if (!err) /* already found some */
-					path_put(res);
 				*res = path;
 				err = 0;
+				break;
 			}
 		}
 		if (!follow_up(&path))
@@ -498,12 +498,11 @@ static int autofs_dev_ioctl_askumount(struct file *fp,
  * mount if there is one or 0 if it isn't a mountpoint.
  *
  * If we aren't supplied with a file descriptor then we
- * lookup the nameidata of the path and check if it is the
- * root of a mount. If a type is given we are looking for
- * a particular autofs mount and if we don't find a match
- * we return fail. If the located nameidata path is the
- * root of a mount we return 1 along with the super magic
- * of the mount or 0 otherwise.
+ * lookup the path and check if it is the root of a mount.
+ * If a type is given we are looking for a particular autofs
+ * mount and if we don't find a match we return fail. If the
+ * located path is the root of a mount we return 1 along with
+ * the super magic of the mount or 0 otherwise.
  *
  * In both cases the the device number (as returned by
  * new_encode_dev()) is also returned.

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_ismountpoint(struct file *fp, · line 537

Quoted 10 lines
fs/autofs4/dev-ioctl.c +4 -2
@@ -531,9 +530,11 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
 
 	if (!fp || param->ioctlfd == -1) {
 		if (autofs_type_any(type))
-			err = kern_path(name, LOOKUP_FOLLOW, &path);
+			err = user_path_mntpointat(AT_FDCWD,
+						   name, LOOKUP_FOLLOW, &path);
 		else
-			err = find_autofs_mount(name, &path, test_by_type, &type);
+			err = find_autofs_mount(name, &path,
+						test_by_type, &type);

...ditto in these spots of course...

Quoted 4 lines
fs/autofs4/dev-ioctl.c +0 -0
 		if (err)
 			goto out;
 		devid = new_encode_dev(path.dentry->d_sb->s_dev);
Acked-by on v1 1/2
#6 lore raw
In reply to Ian Kent
Quoted 137 lines · On Sun, 08 Sep 2013 16:47:15 +0800 Ian Kent <[email protected]> wrote:

The function user_path_umountat() not only avoids revalidation but avoids the managed dentry code as well.

This function has other uses, such as the case where autofs is reconnecting to a tree of mounts and needs to avoid the managed dentry call since that would incorrectly cause a callback to the daemon.

So give the function a more descriptive name.

Cc Jeff Layton <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/namei.c            |   34 +++++++++++++++++++---------------
 fs/namespace.c        |    2 +-
 include/linux/namei.h |    2 +-
 3 files changed, 21 insertions(+), 17 deletions(-)
fs/namei.c +19 -15
index f415c66..24f7562 100644
@@ -2250,7 +2250,7 @@ user_path_parent(int dfd, const char __user *path, struct nameidata *nd,
  *         to the link, and nd->path will *not* be put.
  */
 static int
-umount_lookup_last(struct nameidata *nd, struct path *path)
+mntpoint_lookup_last(struct nameidata *nd, struct path *path)
 {
 	int error = 0;
 	struct dentry *dentry;
@@ -2309,17 +2309,19 @@ error_check:
 }
 
 /**
- * path_umountat - look up a path to be umounted
+ * path_mntpointat - look up a path to a mount point
  * @dfd:	directory file descriptor to start walk from
  * @name:	full pathname to walk
  * @flags:	lookup flags
  * @nd:		pathwalk nameidata
  *
- * Look up the given name, but don't attempt to revalidate the last component.
+ * Look up the given name, but don't attempt to revalidate the last component
+ * or call the managed dentry code.
  * Returns 0 and "path" will be valid on success; Retuns error otherwise.
  */
 static int
-path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
+path_mntpointat(int dfd, const char *name,
+		struct path *path, unsigned int flags)
 {
 	struct file *base = NULL;
 	struct nameidata nd;
@@ -2343,7 +2345,7 @@ path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
 		}
 	}
 
-	err = umount_lookup_last(&nd, path);
+	err = mntpoint_lookup_last(&nd, path);
 	while (err > 0) {
 		void *cookie;
 		struct path link = *path;
@@ -2354,7 +2356,7 @@ path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
 		err = follow_link(&link, &nd, &cookie);
 		if (err)
 			break;
-		err = umount_lookup_last(&nd, path);
+		err = mntpoint_lookup_last(&nd, path);
 		put_link(&nd, &link, cookie);
 	}
 out:
@@ -2368,21 +2370,23 @@ out:
 }
 
 /**
- * user_path_umountat - lookup a path from userland in order to umount it
+ * user_path_mntpointat - lookup a mountpoint path from userland without
+ *      revalidating it or calling the managed dentry code
  * @dfd:	directory file descriptor
  * @name:	pathname from userland
  * @flags:	lookup flags
  * @path:	pointer to container to hold result
  *
- * A umount is a special case for path walking. We're not actually interested
- * in the inode in this situation, and ESTALE errors can be a problem. We
- * simply want track down the dentry and vfsmount attached at the mountpoint
- * and avoid revalidating the last component.
+ * A mount point (when being umounted for example) is a special case for path
+ * walking. We're not actually interested in the inode in this situation, and
+ * ESTALE errors can be a problem. We simply want track down the dentry and
+ * vfsmount attached at the mountpoint and avoid revalidating or calling the
+ * managed dentry code for the last component.
  *
  * Returns 0 and populates "path" on success.
  */
 int
-user_path_umountat(int dfd, const char __user *name, unsigned int flags,
+user_path_mntpointat(int dfd, const char __user *name, unsigned int flags,
 			struct path *path)
 {
 	struct filename *s = getname(name);
@@ -2391,11 +2395,11 @@ user_path_umountat(int dfd, const char __user *name, unsigned int flags,
 	if (IS_ERR(s))
 		return PTR_ERR(s);
 
-	error = path_umountat(dfd, s->name, path, flags | LOOKUP_RCU);
+	error = path_mntpointat(dfd, s->name, path, flags | LOOKUP_RCU);
 	if (unlikely(error == -ECHILD))
-		error = path_umountat(dfd, s->name, path, flags);
+		error = path_mntpointat(dfd, s->name, path, flags);
 	if (unlikely(error == -ESTALE))
-		error = path_umountat(dfd, s->name, path, flags | LOOKUP_REVAL);
+		error = path_mntpointat(dfd, s->name, path, flags|LOOKUP_REVAL);
 
 	if (likely(!error))
 		audit_inode(s, path->dentry, 0);
fs/namespace.c +1 -1
index fc2b522..c48ad96 100644
@@ -1321,7 +1321,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
 	if (!(flags & UMOUNT_NOFOLLOW))
 		lookup_flags |= LOOKUP_FOLLOW;
 
-	retval = user_path_umountat(AT_FDCWD, name, lookup_flags, &path);
+	retval = user_path_mntpointat(AT_FDCWD, name, lookup_flags, &path);
 	if (retval)
 		goto out;
 	mnt = real_mount(path.mnt);
include/linux/namei.h +0 -0
index cd09751..7908abf 100644

include/linux/namei.h enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND}; · line 64

Quoted 8 lines
include/linux/namei.h +1 -1
@@ -58,7 +58,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 
 extern int user_path_at(int, const char __user *, unsigned, struct path *);
 extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
-extern int user_path_umountat(int, const char __user *, unsigned int, struct path *);
+extern int user_path_mntpointat(int, const char __user *, unsigned int, struct path *);
 
 #define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
 #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)

Looks good to me.