[PATCH 28/38] union-mount: Implement union-aware access()/faccessat()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Valerie Aurora
Date: Friday, August 6, 2010 - 3:35 pm

For union mounts, a file located on the lower layer will incorrectly
return EROFS on an access check.  To fix this, use the new
path_permission() call, which ignores a read-only lower layer file
system if the target will be copied up to the topmost file system.

Signed-off-by: Valerie Aurora <vaurora@redhat.com>
---
 fs/open.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 5463266..fc56da0 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -31,6 +31,7 @@
 #include <linux/ima.h>
 
 #include "internal.h"
+#include "union.h"
 
 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 	struct file *filp)
@@ -288,7 +289,10 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
 	const struct cred *old_cred;
 	struct cred *override_cred;
 	struct path path;
+	struct nameidata nd;
+	struct vfsmount *mnt;
 	struct inode *inode;
+	char *tmp;
 	int res;
 
 	if (mode & ~S_IRWXO)	/* where's F_OK, X_OK, W_OK, R_OK? */
@@ -312,10 +316,17 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
 
 	old_cred = override_creds(override_cred);
 
-	res = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
+	res = user_path_nd(dfd, filename, LOOKUP_FOLLOW,
+				   &nd, &path, &tmp);
 	if (res)
 		goto out;
 
+	/* For union mounts, use the topmost mnt's permissions */
+	if (IS_DIR_UNIONED(nd.path.dentry))
+		mnt = nd.path.mnt;
+	else
+		mnt = path.mnt;
+
 	inode = path.dentry->d_inode;
 
 	if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) {
@@ -324,11 +335,11 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
 		 * with the "noexec" flag.
 		 */
 		res = -EACCES;
-		if (path.mnt->mnt_flags & MNT_NOEXEC)
+		if (mnt->mnt_flags & MNT_NOEXEC)
 			goto out_path_release;
 	}
 
-	res = inode_permission(inode, mode | MAY_ACCESS);
+	res = path_permission(&path, &nd.path, mode | MAY_ACCESS);
 	/* SuS v2 requires we report a read only fs too */
 	if (res || !(mode & S_IWOTH) || special_file(inode->i_mode))
 		goto out_path_release;
@@ -342,11 +353,13 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
 	 * inherently racy and know that the fs may change
 	 * state before we even see this result.
 	 */
-	if (__mnt_is_readonly(path.mnt))
+	if (__mnt_is_readonly(mnt))
 		res = -EROFS;
 
 out_path_release:
 	path_put(&path);
+	path_put(&nd.path);
+	putname(tmp);
 out:
 	revert_creds(old_cred);
 	put_cred(override_cred);
-- 
1.6.3.3

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/38] VFS union mounts - Add MS_FALLTHRU, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 09/38] whiteout: tmpfs whiteout support, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 11/38] whiteout: ext2 whiteout support, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 12/38] whiteout: jffs2 whiteout support, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 13/38] fallthru: Basic fallthru definitions, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 14/38] fallthru: ext2 fallthru support, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 15/38] fallthru: jffs2 fallthru support, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 16/38] fallthru: tmpfs fallthru support, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 17/38] union-mount: Union mounts documentation, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 22/38] union-mount: Implement union lookup, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 27/38] union-mount: In-kernel file copyup routines, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 28/38] union-mount: Implement union-aware access()/ ..., Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 29/38] union-mount: Implement union-aware link(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 30/38] union-mount: Implement union-aware rename(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 32/38] union-mount: Implement union-aware chown(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 35/38] union-mount: Implement union-aware lchown(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
Re: [PATCH 14/38] fallthru: ext2 fallthru support, Andreas Dilger, (Fri Aug 6, 5:28 pm)
Re: [PATCH 14/38] fallthru: ext2 fallthru support, Valerie Aurora, (Sun Aug 8, 9:40 am)