linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
To: "J. Bruce Fields" <bfields@fieldses.org>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-nfs@vger.kernel.org
Subject: [RFC 33/39] nfsd: Add richacl support
Date: Fri, 27 Mar 2015 17:50:31 +0100	[thread overview]
Message-ID: <5c9f7d23399017c28314596d53e08f0218be7bee.1427471526.git.agruenba@redhat.com> (raw)
In-Reply-To: <cover.1427471526.git.agruenba@redhat.com>
In-Reply-To: <cover.1427471526.git.agruenba@redhat.com>

On file systems with richacls enabled, get and set richacls directly instead of
converting from / to posix acls.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/nfsd/nfs4acl.c  | 89 ++++++++++++++++++++++++++++++++++++++++++++----------
 fs/nfsd/nfs4proc.c |  2 +-
 fs/nfsd/nfs4xdr.c  | 21 ++++++++++---
 3 files changed, 91 insertions(+), 21 deletions(-)

diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index 9e65a19..8e0cea1 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -38,6 +38,8 @@
 #include <linux/nfs_fs.h>
 #include <linux/richacl_compat.h>
 #include <linux/nfs4acl.h>
+#include <linux/xattr.h>
+#include <linux/richacl_xattr.h>
 #include "nfsfh.h"
 #include "nfsd.h"
 #include "idmap.h"
@@ -127,8 +129,8 @@ static short ace2type(struct richace *);
 static void _posix_to_richacl_one(struct posix_acl *, struct richacl_alloc *,
 				unsigned int);
 
-int
-nfsd4_get_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl **acl)
+static int
+nfsd4_get_posix_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl **acl)
 {
 	struct inode *inode = dentry->d_inode;
 	int error = 0;
@@ -144,7 +146,8 @@ nfsd4_get_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl **ac
 	if (IS_ERR(pacl))
 		return PTR_ERR(pacl);
 
-	/* allocate for worst case: one (deny, allow) pair each: */
+	/* Allocate for worst case: one (deny, allow) pair each.  The resulting
+	   acl will be released shortly and won't be cached. */
 	count = 2 * pacl->a_count;
 
 	if (S_ISDIR(inode->i_mode)) {
@@ -178,6 +181,38 @@ rel_pacl:
 	return error;
 }
 
+static int
+nfsd4_get_richacl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl **acl)
+{
+	struct inode *inode = dentry->d_inode;
+	struct richacl *acl2;
+	int error;
+
+	acl2 = get_richacl(inode);
+	if (!acl2)
+		acl2 = richacl_from_mode(inode->i_mode);
+
+	if (IS_ERR(acl2))
+		return PTR_ERR(acl2);
+	error = richacl_apply_masks(&acl2);
+	if (error)
+		richacl_put(acl2);
+	else
+		*acl = acl2;
+	return error;
+}
+
+int
+nfsd4_get_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl **acl)
+{
+	struct inode *inode = dentry->d_inode;
+
+	if (IS_RICHACL(inode))
+		return nfsd4_get_richacl(rqstp, dentry, acl);
+	else
+		return nfsd4_get_posix_acl(rqstp, dentry, acl);
+}
+
 struct posix_acl_summary {
 	unsigned short owner;
 	unsigned short users;
@@ -788,24 +823,14 @@ out_estate:
 	return ret;
 }
 
-__be32
-nfsd4_set_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, struct richacl *acl)
+static __be32
+nfsd4_set_posix_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl *acl)
 {
-	__be32 error;
 	int host_error;
-	struct dentry *dentry;
-	struct inode *inode;
+	struct inode *inode = dentry->d_inode;
 	struct posix_acl *pacl = NULL, *dpacl = NULL;
 	unsigned int flags = 0;
 
-	/* Get inode */
-	error = fh_verify(rqstp, fhp, 0, NFSD_MAY_SATTR);
-	if (error)
-		return error;
-
-	dentry = fhp->fh_dentry;
-	inode = dentry->d_inode;
-
 	if (!inode->i_op->set_acl || !IS_POSIXACL(inode))
 		return nfserr_attrnotsupp;
 
@@ -837,6 +862,38 @@ out_nfserr:
 		return nfserrno(host_error);
 }
 
+static __be32
+nfsd4_set_richacl(struct svc_rqst *rqstp, struct dentry *dentry, struct richacl *acl)
+{
+	size_t size = richacl_xattr_size(acl);
+	char *buffer;
+	int error;
+
+	buffer = kmalloc(size, GFP_KERNEL);
+	if (!buffer)
+		return -ENOMEM;
+	richacl_to_xattr(&init_user_ns, acl, buffer, size);
+	error = vfs_setxattr(dentry, RICHACL_XATTR, buffer, size, 0);
+	kfree(buffer);
+	return error;
+}
+
+__be32
+nfsd4_set_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, struct richacl *acl)
+{
+	struct dentry *dentry;
+	__be32 error;
+
+	error = fh_verify(rqstp, fhp, 0, NFSD_MAY_SATTR);
+	if (error)
+		return error;
+	dentry = fhp->fh_dentry;
+
+	if (IS_RICHACL(dentry->d_inode))
+		return nfsd4_set_richacl(rqstp, dentry, acl);
+	else
+		return nfsd4_set_posix_acl(rqstp, dentry, acl);
+}
 
 static short
 ace2type(struct richace *ace)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 687726c..a477477c 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -110,7 +110,7 @@ check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	 * in current environment or not.
 	 */
 	if (bmval[0] & FATTR4_WORD0_ACL) {
-		if (!IS_POSIXACL(dentry->d_inode))
+		if (!IS_ACL(dentry->d_inode))
 			return nfserr_attrnotsupp;
 	}
 
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index a882a86..d33335e 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -339,11 +339,24 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
 
 		richacl_for_each_entry(ace, *acl) {
 			READ_BUF(16); len += 16;
-			ace->e_type = be32_to_cpup(p++);
-			ace->e_flags = be32_to_cpup(p++);
-			ace->e_mask = be32_to_cpup(p++);
-			if (ace->e_flags & RICHACE_SPECIAL_WHO)
+
+			dummy32 = be32_to_cpup(p++);
+			if (dummy32 > RICHACE_ACCESS_DENIED_ACE_TYPE)
+				return nfserr_inval;
+			ace->e_type = dummy32;
+
+			dummy32 = be32_to_cpup(p++);
+			if (dummy32 & (~RICHACE_VALID_FLAGS |
+				       RICHACE_INHERITED_ACE |
+				       RICHACE_SPECIAL_WHO))
 				return nfserr_inval;
+			ace->e_flags = dummy32;
+
+			dummy32 = be32_to_cpup(p++);
+			if (dummy32 & ~RICHACE_VALID_MASK)
+				return nfserr_inval;
+			ace->e_mask = dummy32;
+
 			dummy32 = be32_to_cpup(p++);
 			READ_BUF(dummy32);
 			len += XDR_QUADLEN(dummy32) << 2;
-- 
2.1.0


  parent reply	other threads:[~2015-03-27 16:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 16:49 [RFC 00/39] Richacls (2) Andreas Gruenbacher
2015-03-27 16:49 ` [RFC 01/39] vfs: Minor documentation fix Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 02/39] uapi: Remove kernel internal declaration Andreas Gruenbacher
     [not found]   ` <063d443cc0ddc5db271cdaa6649443eb699736d0.1427471526.git.agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-04-20 18:57     ` J. Bruce Fields
2015-04-24 11:25       ` Andreas Grünbacher
2015-03-27 16:50 ` [RFC 03/39] vfs: Shrink struct posix_acl Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 05/39] vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 06/39] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD " Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 07/39] vfs: Make the inode passed to inode_change_ok non-const Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 08/39] vfs: Add permission flags for setting file attributes Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 09/39] richacl: In-memory representation and helper functions Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 10/39] richacl: Permission mapping functions Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 11/39] richacl: Compute maximum file masks from an acl Andreas Gruenbacher
     [not found]   ` <75f97eb880b1bbb47b0aa146d3f528e32de06744.1427471526.git.agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-04-20 21:28     ` J. Bruce Fields
2015-04-24 11:07       ` Andreas Grünbacher
2015-03-27 16:50 ` [RFC 12/39] richacl: Update the file masks in chmod() Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 13/39] richacl: Permission check algorithm Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 14/39] vfs: Cache base_acl objects in inodes Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 16/39] richacl: Create-time inheritance Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 17/39] richacl: Check if an acl is equivalent to a file mode Andreas Gruenbacher
     [not found] ` <cover.1427471526.git.agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-27 16:50   ` [RFC 04/39] vfs: Add IS_ACL() and IS_RICHACL() tests Andreas Gruenbacher
2015-03-27 16:50   ` [RFC 15/39] vfs: Cache richacl in struct inode Andreas Gruenbacher
2015-03-27 16:50   ` [RFC 18/39] richacl: Automatic Inheritance Andreas Gruenbacher
2015-03-27 16:50   ` [RFC 22/39] ext4: Add richacl feature flag Andreas Gruenbacher
2015-03-27 16:50   ` [RFC 26/39] richacl: Isolate the owner and group classes Andreas Gruenbacher
2015-03-30 18:16   ` Fwd: [RFC 00/39] Richacls (2) Steve French
2015-03-27 16:50 ` [RFC 19/39] richacl: xattr mapping functions Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 20/39] vfs: Add richacl permission checking Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 21/39] ext4: Add richacl support Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 23/39] richacl: acl editing helper functions Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 24/39] richacl: Move everyone@ aces down the acl Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 25/39] richacl: Propagate everyone@ permissions to other aces Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 27/39] richacl: Apply the file masks to a richacl Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 28/39] richacl: Create richacl from mode values Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 29/39] richacl: Create acl with masks applied in richacl_from_mode() Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 30/39] nfsd: Remove dead declarations Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 31/39] nfsd: Keep list of acls to dispose of in compoundargs Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 32/39] nfsd: Use richacls as internal acl representation Andreas Gruenbacher
2015-03-27 16:50 ` Andreas Gruenbacher [this message]
2015-03-27 16:50 ` [RFC 34/39] nfs/sunrpc: No more encode and decode function pointer casting Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 35/39] nfs/sunrpc: Return status code from encode functions Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 36/39] nfs3: Return posix acl encode errors Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 37/39] nfs: Remove unused xdr page offsets in getacl/setacl arguments Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 38/39] rpc: Allow to demand-allocate pages to encode into Andreas Gruenbacher
2015-03-27 16:50 ` [RFC 39/39] nfs: Add richacl support Andreas Gruenbacher

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=5c9f7d23399017c28314596d53e08f0218be7bee.1427471526.git.agruenba@redhat.com \
    --to=andreas.gruenbacher@gmail.com \
    --cc=bfields@fieldses.org \
    --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).