linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-nfs@vger.kernel.org
Subject: [RFC 05/21] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD permission flags
Date: Thu, 26 Feb 2015 00:41:26 +0100	[thread overview]
Message-ID: <a858d4a82fe74516f5036cb0b8ff8f177830025f.1424907511.git.agruenba@redhat.com> (raw)
In-Reply-To: <cover.1424907511.git.agruenba@redhat.com>
In-Reply-To: <cover.1424907511.git.agruenba@redhat.com>

Normally, deleting a file requires write and execute access to the parent
directory.  With Richacls, a process with MAY_DELETE_SELF access to a file may
delete the file even without write access to the parent directory.

To support that, pass the MAY_DELETE_CHILD mask flag to inode_permission() when
checking for delete access inside a directory, and MAY_DELETE_SELF when
checking for delete access to a file itelf.

The MAY_DELETE_SELF permission does not override the sticky directory check.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/namei.c         | 15 +++++++++++----
 include/linux/fs.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index a8bc030..a8d1674 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -455,7 +455,7 @@ static int sb_permission(struct super_block *sb, struct inode *inode, int mask)
  * changing the "normal" UIDs which are used for other things.
  *
  * When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR,
- * MAY_WRITE must also be set in @mask.
+ * MAY_DELETE_CHILD, MAY_DELETE_SELF, MAY_WRITE must also be set in @mask.
  */
 int inode_permission(struct inode *inode, int mask)
 {
@@ -2452,7 +2452,7 @@ static int may_delete(struct inode *dir, struct dentry *victim,
 		      bool isdir, bool replace)
 {
 	struct inode *inode = victim->d_inode;
-	int error, mask = MAY_WRITE | MAY_EXEC;
+	int error, mask = MAY_EXEC;
 
 	if (d_is_negative(victim))
 		return -ENOENT;
@@ -2462,8 +2462,15 @@ static int may_delete(struct inode *dir, struct dentry *victim,
 	audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE);
 
 	if (replace)
-		mask |= isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE;
-	error = inode_permission(dir, mask);
+		mask |= MAY_WRITE | (isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE);
+	error = inode_permission(dir, mask | MAY_WRITE | MAY_DELETE_CHILD);
+	if (error && IS_RICHACL(inode)) {
+		/* Deleting is also permitted with MAY_EXEC on the directory
+		 * and MAY_DELETE_SELF on the inode.  */
+		if (!inode_permission(inode, MAY_DELETE_SELF) &&
+		    !inode_permission(dir, mask))
+			error = 0;
+	}
 	if (error)
 		return error;
 	if (IS_APPEND(dir))
diff --git a/include/linux/fs.h b/include/linux/fs.h
index bbe1d26..101abcf 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -82,6 +82,8 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 #define MAY_NOT_BLOCK		0x00000080
 #define MAY_CREATE_FILE		0x00000100
 #define MAY_CREATE_DIR		0x00000200
+#define MAY_DELETE_CHILD	0x00000400
+#define MAY_DELETE_SELF		0x00000800
 
 /*
  * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond
-- 
2.1.0

  parent reply	other threads:[~2015-02-25 23:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-25 23:41 [RFC 00/21] Richacls Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 01/21] vfs: Minor documentation fix Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 02/21] vfs: Shrink struct posix_acl Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 03/21] vfs: Add IS_ACL() and IS_RICHACL() tests Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 04/21] vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags Andreas Gruenbacher
2015-02-25 23:41 ` Andreas Gruenbacher [this message]
2015-02-25 23:41 ` [RFC 06/21] vfs: Make the inode passed to inode_change_ok non-const Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 07/21] vfs: Add permission flags for setting file attributes Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 08/21] richacl: In-memory representation and helper functions Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 09/21] richacl: Permission mapping functions Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 10/21] richacl: Compute maximum file masks from an acl Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 11/21] richacl: Update the file masks in chmod() Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 12/21] richacl: Permission check algorithm Andreas Gruenbacher
     [not found] ` <cover.1424907511.git.agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-02-25 23:41   ` [RFC 13/21] richacl: Create-time inheritance Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 14/21] richacl: Check if an acl is equivalent to a file mode Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 15/21] richacl: Automatic Inheritance Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 16/21] richacl: xattr mapping functions Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 17/21] vfs: Cache base_acl objects in inodes Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 18/21] vfs: Cache richacl in struct inode Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 19/21] vfs: Add richacl permission checking Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 20/21] ext4: Implement rich acl for ext4 Andreas Gruenbacher
2015-02-25 23:41 ` [RFC 21/21] ext4: Add richacl feature flag Andreas Gruenbacher
2015-02-27 22:48 ` [RFC 00/21] Richacls J. Bruce Fields
2015-02-28  0:11   ` Andreas Grünbacher

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=a858d4a82fe74516f5036cb0b8ff8f177830025f.1424907511.git.agruenba@redhat.com \
    --to=andreas.gruenbacher@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /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).