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 4/4] union-mount: Implement chown()
Date: Tue, 30 Mar 2010 14:16:57 -0700	[thread overview]
Message-ID: <1269983817-3252-5-git-send-email-vaurora@redhat.com> (raw)
In-Reply-To: <1269983817-3252-4-git-send-email-vaurora@redhat.com>

Proof-of-concept implementation of chown() for union mounts.  Copies
up the target file even if later permission checks fail.
---
 fs/open.c |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index e17f544..55d6b5b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -30,6 +30,7 @@
 #include <linux/falloc.h>
 #include <linux/fs_struct.h>
 #include <linux/ima.h>
+#include <linux/union.h>
 
 #include "internal.h"
 
@@ -704,19 +705,39 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
 
 SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
 {
-	struct path path;
+	struct path parent;
+	struct path child;
+	struct vfsmount *mnt;
 	int error;
 
-	error = user_path(filename, &path);
+	error = user_path_and_parent(AT_FDCWD, filename, 0, &parent, &child);
 	if (error)
 		goto out;
-	error = mnt_want_write(path.mnt);
+
+	if (IS_MNT_UNION(parent.mnt))
+		mnt = parent.mnt;
+	else
+		mnt = child.mnt;
+
+	error = mnt_want_write(mnt);
 	if (error)
 		goto out_release;
-	error = chown_common(&path, user, group);
-	mnt_drop_write(path.mnt);
+	/*
+	 * XXX Will copy up when operation fails, e.g., EPERM.  We
+	 * have to either (1) separate chown_common() into chown_ok()
+	 * and chown_change(), or (2) push both parent and child path
+	 * down into every check that could return failure.  But this
+	 * is good enough for a proof of concept.
+	 */
+	error = union_copyup_path(&parent, &child);
+	if (error)
+		goto out_drop_write;
+	error = chown_common(&child, user, group);
+out_drop_write:
+	mnt_drop_write(mnt);
 out_release:
-	path_put(&path);
+	path_put(&child);
+	path_put(&parent);
 out:
 	return error;
 }
-- 
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   ` [PATCH 2/4] VFS: create user_path_and_parent() Valerie Aurora
2010-03-30 21:16     ` [PATCH 3/4] union-mount: In-kernel copyup routines Valerie Aurora
2010-03-30 21:16       ` Valerie Aurora [this message]

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-5-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).