linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Valerie Aurora <vaurora@redhat.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/4] VFS: create user_path_and_parent()
Date: Tue, 30 Mar 2010 14:16:55 -0700	[thread overview]
Message-ID: <1269983817-3252-3-git-send-email-vaurora@redhat.com> (raw)
In-Reply-To: <1269983817-3252-2-git-send-email-vaurora@redhat.com>

Proof-of-concept implementation of user_path_and_parent().  Lookup
both the parent and the target of a user-supplied filename, to supply
later to path_permission().  This is for union mounts, in which the
write permission of a file depends on the path used to access it.
---
 fs/namei.c            |   33 +++++++++++++++++++++++++++++++++
 include/linux/namei.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index b4ba87d..b4b8594 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1577,6 +1577,39 @@ static int user_path_parent(int dfd, const char __user *path,
 	return error;
 }
 
+int user_path_and_parent(int dfd, const char __user *filename,
+			 unsigned flags, struct path *parent,
+			 struct path *child)
+{
+	struct nameidata parent_nd;
+	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;
+	*parent = parent_nd.path;
+
+	/* Lookup child - XXX optimize, racy */
+	error = do_path_lookup(dfd, s, flags, &child_nd);
+	if (error)
+		goto out_path_put;
+	*child = child_nd.path;
+	putname(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 05b441d..1c81b17 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -58,6 +58,8 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 #define LOOKUP_RENAME_TARGET	0x0800
 
 extern int user_path_at(int, const char __user *, unsigned, struct path *);
+extern int user_path_and_parent(int , const char __user *, unsigned,
+				struct path *, 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)
-- 
1.6.3.3


  reply	other threads:[~2010-03-30 21:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-30 21:16 [RFC PATCH 0/4] union mounts: In-kernel copyup v1 Valerie Aurora
2010-03-30 21:16 ` [PATCH 1/4] VFS: Split inode_permission() and create path_permission() Valerie Aurora
2010-03-30 21:16   ` Valerie Aurora [this message]
2010-03-30 21:16     ` [PATCH 3/4] union-mount: In-kernel copyup routines Valerie Aurora
2010-03-30 21:16       ` [PATCH 4/4] union-mount: Implement chown() Valerie Aurora

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=1269983817-3252-3-git-send-email-vaurora@redhat.com \
    --to=vaurora@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).