linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org, Dave Hansen <haveblue@us.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 09/10] VFS: Remove read-only checks from dentry_permission
Date: Mon, 06 Sep 2010 10:50:29 +1000	[thread overview]
Message-ID: <20100906005029.20775.70918.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100906004829.20775.68828.stgit@localhost.localdomain>

It is not sufficient to depend on the the "filesystem is readonly"
tests in dentry_permission as it does not check if the vfsmnt is
readonly.
All call sites already call mnt_want_write or __mnt_is_readonly which
includes the test on MS_RDONLY.

So remove this test from dentry_permission as it simply duplicates
tests done elsewhere.

This allows ovl_permission to be significantly simplified.


Cc: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: NeilBrown <neilb@suse.de>
---
 fs/namei.c               |   15 +--------------
 fs/overlayfs/overlayfs.c |   26 ++------------------------
 2 files changed, 3 insertions(+), 38 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 6042564..291a839 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -254,22 +254,9 @@ int dentry_permission(struct dentry *dentry, int mask)
 	struct inode *inode = dentry->d_inode;
 	int retval;
 
-	if (mask & MAY_WRITE) {
-		umode_t mode = inode->i_mode;
-
-		/*
-		 * Nobody gets write access to a read-only fs.
-		 */
-		if (IS_RDONLY(inode) &&
-		    (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
-			return -EROFS;
-
-		/*
-		 * Nobody gets write access to an immutable file.
-		 */
+	if (mask & MAY_WRITE)
 		if (IS_IMMUTABLE(inode))
 			return -EACCES;
-	}
 
 	if (inode->i_op->permission)
 		retval = inode->i_op->permission(dentry, mask);
diff --git a/fs/overlayfs/overlayfs.c b/fs/overlayfs/overlayfs.c
index cdeafa7..749109a 100644
--- a/fs/overlayfs/overlayfs.c
+++ b/fs/overlayfs/overlayfs.c
@@ -1127,31 +1127,9 @@ static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry,
 static int ovl_permission(struct dentry *dentry, int mask)
 {
 	struct ovl_entry *ue = dentry->d_fsdata;
-	struct inode *inode;
-	int err;
-
-	if (ue->upperpath.dentry)
-		return dentry_permission(ue->upperpath.dentry, mask);
-
-	inode = ue->lowerpath.dentry->d_inode;
-	if (!(mask & MAY_WRITE) || special_file(inode->i_mode))
-		return dentry_permission(ue->lowerpath.dentry, mask);
-
-	/* Don't check for read-only fs */
-	if (mask & MAY_WRITE) {
-		if (IS_IMMUTABLE(inode))
-			return -EACCES;
-	}
-
-	if (inode->i_op->permission)
-		err = inode->i_op->permission(ue->lowerpath.dentry, mask);
-	else
-		err = generic_permission(inode, mask, inode->i_op->check_acl);
-
-	if (err)
-		return err;
+	struct path *realpath = ovl_path(ue);
 
-	return security_inode_permission(inode, mask);
+	return dentry_permission(realpath->dentry, mask);
 }
 
 static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev,

  parent reply	other threads:[~2010-09-06  0:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06  0:50 [PATCH 00/10] Assorted fixes/enhancements for overlayfs NeilBrown
2010-09-06  0:50 ` [PATCH 02/10] ovl: minimal remount support NeilBrown
2010-09-06  0:50 ` [PATCH 03/10] ovl: use correct seek function for directories NeilBrown
2010-09-06  0:50 ` [PATCH 01/10] ovl: small optimisation for ovl_lookup NeilBrown
2010-09-06 16:57   ` Miklos Szeredi
2010-09-06  0:50 ` [PATCH 08/10] VFS: tiny optimisation in open_other handling NeilBrown
2010-09-06  0:50 ` [PATCH 04/10] ovl: initialise is_real before use NeilBrown
2010-09-06  0:50 ` [PATCH 05/10] ovl: make sure fsync is never called on the lower filesystem NeilBrown
2010-09-06 17:16   ` Miklos Szeredi
2010-09-06  0:50 ` [PATCH 10/10] ovl: Assorted updates to Documentation/filesystems/overlayfs.txt NeilBrown
2010-09-06  0:50 ` [PATCH 07/10] ovl: add initial revalidate support NeilBrown
2010-09-16 14:47   ` Miklos Szeredi
2010-09-21  2:40     ` Neil Brown
2010-09-06  0:50 ` NeilBrown [this message]
2010-09-06 19:10   ` [PATCH 09/10] VFS: Remove read-only checks from dentry_permission Miklos Szeredi
2010-09-08  7:47     ` Neil Brown
2010-09-08  8:58       ` Miklos Szeredi
2010-09-07 15:58   ` Dave Hansen
2010-09-06  0:50 ` [PATCH 06/10] ovl: rename ovl_fill_cache to ovl_dir_read NeilBrown
2010-09-06 19:23 ` [PATCH 00/10] Assorted fixes/enhancements for overlayfs Miklos Szeredi

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=20100906005029.20775.70918.stgit@localhost.localdomain \
    --to=neilb@suse.de \
    --cc=haveblue@us.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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).