Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758045Ab0DOXH4 (ORCPT ); Thu, 15 Apr 2010 19:07:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65181 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757950Ab0DOXHU (ORCPT ); Thu, 15 Apr 2010 19:07:20 -0400 From: Valerie Aurora To: Alexander Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Valerie Aurora Subject: [PATCH 27/35] union-mount: Implement union-aware access()/faccessat() Date: Thu, 15 Apr 2010 16:04:34 -0700 Message-Id: <1271372682-21225-28-git-send-email-vaurora@redhat.com> In-Reply-To: <1271372682-21225-27-git-send-email-vaurora@redhat.com> References: <1271372682-21225-1-git-send-email-vaurora@redhat.com> <1271372682-21225-2-git-send-email-vaurora@redhat.com> <1271372682-21225-3-git-send-email-vaurora@redhat.com> <1271372682-21225-4-git-send-email-vaurora@redhat.com> <1271372682-21225-5-git-send-email-vaurora@redhat.com> <1271372682-21225-6-git-send-email-vaurora@redhat.com> <1271372682-21225-7-git-send-email-vaurora@redhat.com> <1271372682-21225-8-git-send-email-vaurora@redhat.com> <1271372682-21225-9-git-send-email-vaurora@redhat.com> <1271372682-21225-10-git-send-email-vaurora@redhat.com> <1271372682-21225-11-git-send-email-vaurora@redhat.com> <1271372682-21225-12-git-send-email-vaurora@redhat.com> <1271372682-21225-13-git-send-email-vaurora@redhat.com> <1271372682-21225-14-git-send-email-vaurora@redhat.com> <1271372682-21225-15-git-send-email-vaurora@redhat.com> <1271372682-21225-16-git-send-email-vaurora@redhat.com> <1271372682-21225-17-git-send-email-vaurora@redhat.com> <1271372682-21225-18-git-send-email-vaurora@redhat.com> <1271372682-21225-19-git-send-email-vaurora@redhat.com> <1271372682-21225-20-git-send-email-vaurora@redhat.com> <1271372682-21225-21-git-send-email-vaurora@redhat.com> <1271372682-21225-22-git-send-email-vaurora@redhat.com> <1271372682-21225-23-git-send-email-vaurora@redhat.com> <1271372682-21225-24-git-send-email-vaurora@redhat.com> <1271372682-21225-25-git-send-email-vaurora@redhat.com> <1271372682-21225-26-git-send-email-vaurora@redhat.com> <1271372682-21225-27-git-send-email-vaurora@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2534 Lines: 79 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. --- fs/open.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/open.c b/fs/open.c index e17f544..686fcd2 100644 --- a/fs/open.c +++ b/fs/open.c @@ -454,7 +454,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? */ @@ -478,10 +481,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_UNIONED_DIR(&nd.path)) + mnt = nd.path.mnt; + else + mnt = path.mnt; + inode = path.dentry->d_inode; if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) { @@ -490,11 +500,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; @@ -508,11 +518,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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/