linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: hch@infradead.org
Subject: [PATCH 60/76] VFS: Create user_path_nd() to lookup both parent and target
Date: Fri, 17 Jun 2011 17:09:01 +0100	[thread overview]
Message-ID: <20110617160901.30314.49169.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20110617160008.30314.22757.stgit@warthog.procyon.org.uk>

From: Valerie Aurora <vaurora@redhat.com>

Proof-of-concept implementation of user_path_nd().  Lookup both the
parent and the target of a user-supplied filename, to supply later to
union copyup routines.

XXX - Inefficient, racy, gets the parent of the symlink instead of the
parent of the target.  Al Viro would like to see something more like
this:

user_path_mumble() looks up and returns:

parent nameidata
positive topmost dentry of target
negative dentry of target from the topmost layer (if it doesn't exist on top)

Both the positive lower dentry and negative topmost dentry are passed
to the following code, like do_chown().  The tests for permissions and
such-like are performed on the positive lower dentry.  When it comes
time to actually modify the target, we call union_copyup() with both
positive and negative dentries (and the parent nameidata).
---

 fs/namei.c            |   31 +++++++++++++++++++++++++++++++
 include/linux/namei.h |    2 ++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index ce681ca..fafd352 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2190,6 +2190,37 @@ static int user_path_parent(int dfd, const char __user *path,
 	return error;
 }
 
+int user_path_nd(int dfd, const char __user *filename,
+			 unsigned flags, struct nameidata *parent_nd,
+			 struct path *child, char **tmp)
+{
+	struct nameidata child_nd;
+	char *s = getname(filename);
+	int error;
+
+	if (IS_ERR(s))
+		return PTR_ERR(s);
+
+	/* Lookup parent */
+	error = do_path_lookup(dfd, s, LOOKUP_PARENT, parent_nd);
+	if (error)
+		goto out_putname;
+
+	/* Lookup child - XXX optimize, racy */
+	error = do_path_lookup(dfd, s, flags, &child_nd);
+	if (error)
+		goto out_path_put;
+	*child = child_nd.path;
+	*tmp = s;
+	return 0;
+
+out_path_put:
+	path_put(&parent_nd->path);
+out_putname:
+	putname(s);
+	return error;
+}
+
 /*
  * It's inline, so penalty for filesystems that don't use sticky bit is
  * minimal.
diff --git a/include/linux/namei.h b/include/linux/namei.h
index eba45ea..c32c987 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -67,6 +67,8 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 #define LOOKUP_EMPTY		0x4000
 
 extern int user_path_at(int, const char __user *, unsigned, struct path *);
+extern int user_path_nd(int, const char __user *, unsigned,
+			struct nameidata *, struct path *, char **);
 
 #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)


  parent reply	other threads:[~2011-06-17 16:09 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-17 16:00 [RFC][PATCH 00/76] Union Mount David Howells
2011-06-17 16:00 ` [PATCH 01/76] VFS: Make clone_mnt()/copy_tree()/collect_mounts() return errors David Howells
2011-06-17 16:00 ` [PATCH 02/76] VFS: Add hard read-only users count to superblock David Howells
2011-06-17 16:00 ` [PATCH 03/76] VFS: Add CL_NO_SHARED flag to clone_mnt()/copy_tree() David Howells
2011-06-17 16:00 ` [PATCH 04/76] VFS: Add CL_NO_SLAVE " David Howells
2011-06-17 16:00 ` [PATCH 05/76] VFS: Add CL_MAKE_HARD_READONLY " David Howells
2011-06-17 16:01 ` [PATCH 06/76] VFS: Comment follow_mount() and friends David Howells
2011-06-17 16:53   ` Christoph Hellwig
2011-06-17 16:01 ` [PATCH 07/76] VFS: Make lookup_hash() return a struct path David Howells
2011-06-17 16:01 ` [PATCH 08/76] whiteout/NFSD: Don't return information about whiteouts to userspace David Howells
2011-06-17 16:01 ` [PATCH 09/76] whiteout: Define flags and operations for opaque inodes David Howells
2011-06-17 16:01 ` [PATCH 10/76] whiteout: Add vfs_whiteout() and whiteout inode operation David Howells
2011-06-17 16:01 ` [PATCH 11/76] whiteout: Allow removal of a directory with whiteouts David Howells
2011-06-17 16:01 ` [PATCH 12/76] tmpfs: Add whiteout support David Howells
2011-06-17 16:02 ` [PATCH 13/76] ext2: Add ext2_dirent_in_use() David Howells
2011-06-17 16:02 ` [PATCH 14/76] ext2: Split ext2_add_entry() from ext2_add_link() David Howells
2011-06-17 16:02 ` [PATCH 15/76] ext2: Add whiteout support David Howells
2011-06-17 16:02 ` [PATCH 16/76] jffs2: " David Howells
2011-06-17 16:02 ` [PATCH 17/76] VFS: Basic fallthru definitions David Howells
2011-06-17 16:02 ` [PATCH 18/76] ext2: Add fallthru support David Howells
2011-06-17 16:03 ` [PATCH 19/76] tmpfs: " David Howells
2011-06-17 16:03 ` [PATCH 20/76] jffs2: " David Howells
2011-06-17 16:03 ` [PATCH 21/76] union-mount: Union mounts documentation David Howells
2011-06-17 16:03 ` [PATCH 22/76] union-mount: Introduce MNT_UNION and MS_UNION flags David Howells
2011-06-17 16:03 ` [PATCH 23/76] union-mount: Add CONFIG_UNION_MOUNT option David Howells
2011-06-17 16:03 ` [PATCH 24/76] union-mount: Create union_stack structure David Howells
2011-06-17 16:03 ` [PATCH 25/76] union-mount: Add two superblock fields for union mounts David Howells
2011-06-17 16:04 ` [PATCH 26/76] union-mount: Add union_alloc() David Howells
2011-06-17 16:04 ` [PATCH 27/76] union-mount: Add union_find_dir() David Howells
2011-06-17 16:04 ` [PATCH 28/76] union-mount: Create d_free_unions() David Howells
2011-06-17 16:04 ` [PATCH 29/76] union-mount: Free union stack on removal of topmost dentry from dcache David Howells
2011-06-17 16:04 ` [PATCH 30/76] union-mount: Create union_add_dir() David Howells
2011-06-17 16:04 ` [PATCH 31/76] union-mount: Add union_create_topmost_dir() David Howells
2011-06-17 16:04 ` [PATCH 32/76] union-mount: Create IS_MNT_UNION() David Howells
2011-06-17 16:05 ` [PATCH 33/76] union-mount: Create needs_lookup_union() David Howells
2011-06-17 16:05 ` [PATCH 34/76] union-mount: Create check_topmost_union_mnt() David Howells
2011-06-17 16:05 ` [PATCH 35/76] union-mount: Add clone_union_tree() and put_union_sb() David Howells
2011-06-17 16:05 ` [PATCH 36/76] union-mount: Create build_root_union() David Howells
2011-06-17 16:05 ` [PATCH 37/76] union-mount: Create prepare_mnt_union() and cleanup_mnt_union() David Howells
2011-06-17 16:05 ` [PATCH 38/76] union-mount: Prevent improper union-related remounts David Howells
2011-06-17 16:05 ` [PATCH 39/76] union-mount: Prevent topmost file system from being mounted elsewhere David Howells
2011-06-17 16:06 ` [PATCH 40/76] union-mount: Prevent bind mounts of union mounts David Howells
2011-06-17 16:06 ` [PATCH 41/76] union-mount: Implement union mount David Howells
2011-06-17 16:06 ` [PATCH 42/76] union-mount: Temporarily disable some syscalls David Howells
2011-06-17 16:06 ` [PATCH 43/76] union-mount: Basic infrastructure of __lookup_union() David Howells
2011-06-17 16:06 ` [PATCH 44/76] union-mount: Process negative dentries in __lookup_union() David Howells
2011-06-17 16:06 ` [PATCH 45/76] union-mount: Return files found in lower layers " David Howells
2011-06-17 16:06 ` [PATCH 46/76] union-mount: Build union stack " David Howells
2011-06-17 16:07 ` [PATCH 47/76] union-mount: Follow mount " David Howells
2011-06-17 16:07 ` [PATCH 48/76] union-mount: Add lookup_union() David Howells
2011-06-17 16:07 ` [PATCH 49/76] union-mount: Add do_lookup_union() wrapper for __lookup_union() David Howells
2011-06-17 16:07 ` [PATCH 50/76] union-mount: Call union lookup functions in lookup path David Howells
2011-06-17 16:07 ` [PATCH 51/76] union-mount: Create whiteout on unlink() David Howells
2011-06-17 16:07 ` [PATCH 52/76] union-mount: Create whiteout on rmdir() David Howells
2011-06-17 16:07 ` [PATCH 53/76] union-mount: Set opaque flag on new directories in unioned file systems David Howells
2011-06-17 16:08 ` [PATCH 54/76] union-mount: Copy up directory entries on first readdir() David Howells
2011-06-17 16:08 ` [PATCH 55/76] union-mount: Add generic_readdir_fallthru() helper David Howells
2011-06-17 16:08 ` [PATCH 56/76] fallthru: ext2 support for lookup of d_type/d_ino in fallthrus David Howells
2011-06-17 16:08 ` [PATCH 57/76] fallthru: tmpfs " David Howells
2011-06-17 16:08 ` [PATCH 58/76] fallthru: jffs2 " David Howells
2011-06-17 16:08 ` [PATCH 59/76] VFS: Split inode_permission() and create path_permission() David Howells
2011-06-17 16:09 ` David Howells [this message]
2011-06-17 16:09 ` [PATCH 61/76] union-mount: In-kernel file copyup routines David Howells
2011-06-17 16:09 ` [PATCH 62/76] union-mount: Implement union-aware access()/faccessat() David Howells
2011-06-17 16:09 ` [PATCH 63/76] union-mount: Implement union-aware link() David Howells
2011-06-17 16:09 ` [PATCH 64/76] union-mount: Implement union-aware rename() David Howells
2011-06-17 16:09 ` [PATCH 65/76] union-mount: Implement union-aware writable open() David Howells
2011-06-17 16:09 ` [PATCH 66/76] union-mount: Implement union-aware chown() David Howells
2011-06-17 16:10 ` [PATCH 67/76] union-mount: Implement union-aware truncate() David Howells
2011-06-17 16:10 ` [PATCH 68/76] union-mount: Implement union-aware chmod()/fchmodat() David Howells
2011-06-17 16:10 ` [PATCH 69/76] union-mount: Implement union-aware lchown() David Howells
2011-06-17 16:10 ` [PATCH 70/76] union-mount: Implement union-aware utimensat() David Howells
2011-06-17 16:10 ` [PATCH 71/76] union-mount: Implement union-aware setxattr() David Howells
2011-06-17 16:10 ` [PATCH 72/76] union-mount: Implement union-aware lsetxattr() David Howells
2011-06-17 16:10 ` [PATCH 73/76] union-mount: Pass mount flags to sget() David Howells
2011-06-17 16:11 ` [PATCH 74/76] union-mount: Duplicate the i_{, dir_}mutex lock classes and use for upper layer David Howells
2011-06-17 16:11 ` [PATCH 76/76] Temporary commit David Howells
2011-06-17 16:23 ` [PATCH 75/76] Ext2: Unionmount devel David Howells
2011-06-17 16:44 ` [RFC][PATCH 00/76] Union Mount Sedat Dilek

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=20110617160901.30314.49169.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /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).