RFC Richacls
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest0 of 21 patches 1 replyIn review
Patches in v1 No applies recorded yet
None of the 21 patches the cover letter announces are in this archive.
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC 00/21] Richacls
Hello,
here is an updated richacl patch queue, also available in git [1]. For those who might not know, richacls are an implementation of NFSv4 ACLs that cleanly integrates into the POSIX file permission model. The goal is to improve interoperability between Linux and other systems, mainly across the NFSv4 and CIFS/SMB protocols. A file system can either contain posix acls or richacls, but not both.
This patch queue includes the vfs and ext4 changes needed for local richacl support. A previous version of this patch queue was last posted about a year ago [2]; I have updated the patches to v4.0-rc1 and tried to incorporate the feedback from the previous discussion. The changes include:
* Introduction of a base_acl object type so that an inode can either cache a posix acl or a richacl largely without caring which of the two kinds it is dealing with.
* RCU support as for posix acls.
* Various cleanups and more documentation.
Things I'm not entirely happy with:
* A new get_richacl inode operation is introduced. This is needed because we need to perform permission checks in contexts where the dentry of the inode to check is not available and we cannot use the getxattr inode operation. It would be nice if we could either convert the getxattr inode operation to take an inode instead, or pass the dentries down to where the get_richacl inode operation is currently used.
* The base_acl code is rather ugly; maybe the previous version which was criticized wasn't so bad after all.
* It would be nice if the MAY_DELETE_SELF flag could override the sticky directory check as it did in the previous version of this patch queue. I couldn't come up with a clean way of achieving that, though.
Because the code has changed quite a bit since the last posting, I have removed the previous sign-offs.
At this point, I would like to ask for your feedback as to what should be changed before these patches can be merged, even if merging these patches alone doesn't make a while lot of sense. I will follow up with additional pieces to the puzzle like the nfsv4 support as I get them into shape again.
--
Which kind of acls an ext4 file system supports is determined by the "richacl" ext4 feature (mkfs.ext4 -O richacl or tune2fs -O richacl). The file system also needs to be mounted with the "acl" mount option, which is the default nowadays.
A version of e2fsprogs with support for the "richacl" feature can be found on github [3], but the feature can also be enabled "hard" in debugfs. Note that unpatched versions of e2fsck will not check file systems with the feature enabled though.
The acls themselves can be manipulated with the richacl command-line utility [4]. Some details on the permission model and examples of its use can be found at the richacl page, http://acl.bestbits.at/richacl/.
[1] git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git richacl
[2] http://lwn.net/Articles/596517/
[3] https://github.com/andreas-gruenbacher/e2fsprogs
[4] https://github.com/andreas-gruenbacher/richacl
Thanks,
Andreas
--
Andreas Gruenbacher (19):
vfs: Minor documentation fix
vfs: Shrink struct posix_acl
vfs: Add IS_ACL() and IS_RICHACL() tests
vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags
vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD permission flags
vfs: Make the inode passed to inode_change_ok non-const
vfs: Add permission flags for setting file attributes
richacl: In-memory representation and helper functions
richacl: Permission mapping functions
richacl: Compute maximum file masks from an acl
richacl: Update the file masks in chmod()
richacl: Permission check algorithm
richacl: Create-time inheritance
richacl: Check if an acl is equivalent to a file mode
richacl: Automatic Inheritance
richacl: xattr mapping functions
vfs: Cache base_acl objects in inodes
vfs: Cache richacl in struct inode
vfs: Add richacl permission checking
Aneesh Kumar K.V (2):
ext4: Implement rich acl for ext4
ext4: Add richacl feature flag
Documentation/filesystems/porting | 8 +- Documentation/filesystems/vfs.txt | 3 + drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- fs/Kconfig | 3 + fs/Makefile | 2 + fs/attr.c | 81 ++- fs/ext4/Kconfig | 15 + fs/ext4/Makefile | 1 + fs/ext4/acl.c | 7 +- fs/ext4/acl.h | 12 +- fs/ext4/ext4.h | 6 +- fs/ext4/file.c | 6 +- fs/ext4/ialloc.c | 7 +- fs/ext4/inode.c | 10 +- fs/ext4/namei.c | 11 +- fs/ext4/richacl.c | 229 ++++++++ fs/ext4/richacl.h | 47 ++ fs/ext4/super.c | 41 +- fs/ext4/xattr.c | 6 + fs/ext4/xattr.h | 1 + fs/f2fs/acl.c | 4 +- fs/inode.c | 15 +- fs/namei.c | 108 +++- fs/posix_acl.c | 31 +- fs/richacl_base.c | 660 ++++++++++++++++++++++++ fs/richacl_inode.c | 67 +++ fs/richacl_xattr.c | 131 +++++ include/linux/fs.h | 47 +- include/linux/posix_acl.h | 12 +- include/linux/richacl.h | 329 ++++++++++++ include/linux/richacl_xattr.h | 47 ++ include/uapi/linux/fs.h | 3 +- 32 files changed, 1844 insertions(+), 108 deletions(-) create mode 100644 fs/ext4/richacl.c create mode 100644 fs/ext4/richacl.h create mode 100644 fs/richacl_base.c create mode 100644 fs/richacl_inode.c create mode 100644 fs/richacl_xattr.c create mode 100644 include/linux/richacl.h create mode 100644 include/linux/richacl_xattr.h
Signature · 1 line
2.1.0
Quoted 1 line
From
a7ae9dc44b9772622cb5d17b142a43cea2d18d10Mon Sep 17 00:00:00 2001
Message-Id: <a7ae9dc44b9772622cb5d17b142a43cea2d18d10.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Wed, 4 Feb 2015 15:47:36 +0100
Subject: [RFC 01/21] vfs: Minor documentation fix
To: [email protected],
[email protected],
[email protected]
The check_acl inode operation and the IPERM_FLAG_RCU are long gone. Document what get_acl does instead.
--- Documentation/filesystems/porting | 8 ++++---- Documentation/filesystems/vfs.txt | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-)
Documentation/filesystems/porting +4 -4
@@ -379,10 +379,10 @@ may now be called in rcu-walk mode (nd->flags & LOOKUP_RCU). -ECHILD should be returned if the filesystem cannot handle rcu-walk. See Documentation/filesystems/vfs.txt for more details. - permission and check_acl are inode permission checks that are called -on many or all directory inodes on the way down a path walk (to check for -exec permission). These must now be rcu-walk aware (flags & IPERM_FLAG_RCU). -See Documentation/filesystems/vfs.txt for more details. + permission is an inode permission check that is called on many or all +directory inodes on the way down a path walk (to check for exec permission). It +must now be rcu-walk aware (mask & MAY_NOT_BLOCK). See +Documentation/filesystems/vfs.txt for more details. -- [mandatory]
Documentation/filesystems/vfs.txt +3 -0
@@ -457,6 +457,9 @@ otherwise noted. If a situation is encountered that rcu-walk cannot handle, return -ECHILD and it will be called again in ref-walk mode. + get_acl: called by the VFS to get the posix acl of an inode. Called during + permission checks. The returned acl is cached in the inode. + setattr: called by the VFS to set attributes for a file. This method is called by chmod(2) and related system calls.
Signature · 1 line
2.1.0
Quoted 1 line
From
d89155579f576fbe07756462212365f678afdb75Mon Sep 17 00:00:00 2001
Message-Id: <d89155579f576fbe07756462212365f678afdb75.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Wed, 4 Feb 2015 14:46:15 +0100
Subject: [RFC 02/21] vfs: Shrink struct posix_acl
To: [email protected],
[email protected],
[email protected]
There is a hole in struct posix_acl because its struct rcu_head member is too large; at least on on 64-bit architectures, the hole cannot be closed by changing the definition of struct posix_acl. So instead, remove the struct rcu_head member from struct posix_acl, make sure that acls are always big enough to fit a struct rcu_head, and cast to struct rcu_head * when disposing of an acl.
--- fs/posix_acl.c | 5 +++-- include/linux/posix_acl.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)
fs/posix_acl.c +3 -2
@@ -140,8 +140,9 @@ EXPORT_SYMBOL(posix_acl_init);struct posix_acl *posix_acl_alloc (int count,gfp_t flags) { -const size_t size =sizeof (struct posix_acl ) + - count *sizeof (struct posix_acl_entry ); +const size_t size =max (sizeof (struct rcu_head ), +sizeof (struct posix_acl ) + + count *sizeof (struct posix_acl_entry ));struct posix_acl *acl =kmalloc (size, flags);if (acl)posix_acl_init (acl, count);
include/linux/posix_acl.h +2 -5
@@ -43,10 +43,7 @@ struct posix_acl_entry { };struct posix_acl { -union { -atomic_t a_refcount; -struct rcu_head a_rcu; - }; +atomic_t a_refcount;unsigned int a_count;struct posix_acl_entry a_entries[0 ]; };
@@ -73,7 +70,7 @@ static inline void posix_acl_release(struct posix_acl *acl) {if (acl &&atomic_dec_and_test (&acl->a_refcount)) -kfree_rcu (acl, a_rcu); +__kfree_rcu ((struct rcu_head *)acl,0 ); }
Signature · 1 line
2.1.0
Quoted 1 line
From
611a0b6fe640f6d4ff7bb98931edf8c2fe81471cMon Sep 17 00:00:00 2001
Message-Id: <611a0b6fe640f6d4ff7bb98931edf8c2fe81471c.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 00:19:53 +0530
Subject: [RFC 03/21] vfs: Add IS_ACL() and IS_RICHACL() tests
To: [email protected],
[email protected],
[email protected]
The vfs does not apply the umask for file systems that support acls. The test used for this used to be called IS_POSIXACL(). Switch to a new IS_ACL() test to check for either posix acls or richacls instead. Add a new MS_RICHACL flag and IS_RICHACL() test for richacls alone. The IS_POSIXACL() test is still needed by file systems that specifically support POSIX ACLs, like nfsd.
--- fs/Kconfig | 3 +++ fs/namei.c | 8 ++++---- include/linux/fs.h | 12 ++++++++++++ include/uapi/linux/fs.h | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-)
fs/Kconfig +3 -0
@@ -58,6 +58,9 @@ endif # BLOCK config FS_POSIX_ACL def_bool n +config FS_RICHACL + def_bool n + config EXPORTFS tristate
fs/namei.c +4 -4
@@ -2696,7 +2696,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, } mode = op->mode; -if ((open_flag &O_CREAT ) && !IS_POSIXACL (dir)) +if ((open_flag &O_CREAT ) && !IS_ACL (dir)) mode &= ~current_umask (); excl = (open_flag & (O_EXCL |O_CREAT )) == (O_EXCL |O_CREAT );
@@ -2880,7 +2880,7 @@ static int lookup_open(struct nameidata *nd, struct path *path,/* Negative dentry, just create the file */ if (!dentry->d_inode && (op->open_flag &O_CREAT )) {umode_t mode = op->mode; -if (!IS_POSIXACL (dir->d_inode)) +if (!IS_ACL (dir->d_inode)) mode &= ~current_umask ();/* * This write is needed to ensure that a
@@ -3481,7 +3481,7 @@ retry:if (IS_ERR (dentry))return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) +if (!IS_ACL (path.dentry->d_inode)) mode &= ~current_umask (); error =security_path_mknod (&path, dentry, mode, dev);if (error)
@@ -3550,7 +3550,7 @@ retry:if (IS_ERR (dentry))return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) +if (!IS_ACL (path.dentry->d_inode)) mode &= ~current_umask (); error =security_path_mkdir (&path, dentry, mode);if (!error)
include/linux/fs.h +12 -0
@@ -1708,6 +1708,12 @@ struct super_operations {#define IS_IMMUTABLE (inode) ((inode)->i_flags & S_IMMUTABLE)#define IS_POSIXACL (inode) __IS_FLG(inode, MS_POSIXACL) +#ifdef CONFIG_FS_RICHACL +#define IS_RICHACL (inode) __IS_FLG(inode, MS_RICHACL) +#else +#define IS_RICHACL (inode) 0 +#endif +#define IS_DEADDIR (inode) ((inode)->i_flags & S_DEAD)#define IS_NOCMTIME (inode) ((inode)->i_flags & S_NOCMTIME)#define IS_SWAPFILE (inode) ((inode)->i_flags & S_SWAPFILE)
@@ -1721,6 +1727,12 @@ struct super_operations { (inode)->i_rdev == WHITEOUT_DEV)/* +* IS_ACL() tells the VFS to not apply the umask +* and use check_acl for acl permission checks when defined. +*/ +#define IS_ACL (inode) __IS_FLG(inode, MS_POSIXACL | MS_RICHACL) + +/* * Inode state bits. Protected by inode->i_lock * * Three bits determine the dirty state of the inode, I_DIRTY_SYNC,
include/uapi/linux/fs.h +2 -1
@@ -81,7 +81,7 @@ struct inodes_stat_t {#define MS_VERBOSE 32768/* War is peace. Verbosity is silence. MS_VERBOSE is deprecated. */ #define MS_SILENT 32768 -#define MS_POSIXACL (1<<16)/* VFS does not apply the umask */ +#define MS_POSIXACL (1<<16)/* Supports POSIX ACLs */ #define MS_UNBINDABLE (1<<17)/* change to unbindable */ #define MS_PRIVATE (1<<18)/* change to private */ #define MS_SLAVE (1<<19)/* change to slave */
@@ -91,6 +91,7 @@ struct inodes_stat_t {#define MS_I_VERSION (1<<23)/* Update inode I_version field */ #define MS_STRICTATIME (1<<24)/* Always perform atime updates */ #define MS_LAZYTIME (1<<25)/* Update the on-disk [acm]times lazily */ +#define MS_RICHACL (1<<26)/* Supports richacls */ /* These sb flags are internal to the kernel */ #define MS_NOSEC (1<<28)
Signature · 1 line
2.1.0
Quoted 1 line
From
f8b04df08a0dd950d47e17c901773258f0653eedMon Sep 17 00:00:00 2001
Message-Id: <f8b04df08a0dd950d47e17c901773258f0653eed.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Wed, 28 Jan 2015 20:23:15 +0100
Subject: [RFC 04/21] vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR
permission flags
To: [email protected],
[email protected],
[email protected]
Richacls distinguish between creating non-directories and directories. To support that, add an isdir parameter to may_create(). When checking inode_permission() for create permission, pass in an additional MAY_CREATE_FILE or MAY_CREATE_DIR mask flag.
To allow checking for delete *and* create access when replacing an existing file via vfs_rename(), add a replace parameter to may_delete().
--- fs/namei.c | 42 ++++++++++++++++++++++++------------------ include/linux/fs.h | 2 ++ 2 files changed, 26 insertions(+), 18 deletions(-)
fs/namei.c +24 -18
137 lines not on this page · raw message
include/linux/fs.h +2 -0
@@ -80,6 +80,8 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,#define MAY_CHDIR 0x00000040/* called from RCU mode, don't block */ #define MAY_NOT_BLOCK 0x00000080 +#define MAY_CREATE_FILE 0x00000100 +#define MAY_CREATE_DIR 0x00000200/* * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond
Signature · 1 line
2.1.0
Quoted 1 line
From
a858d4a82fe74516f5036cb0b8ff8f177830025fMon Sep 17 00:00:00 2001
Message-Id: <a858d4a82fe74516f5036cb0b8ff8f177830025f.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 05:06:26 +0530
Subject: [RFC 05/21] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD
permission flags
To: [email protected],
[email protected],
[email protected]
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.
--- fs/namei.c | 15 +++++++++++---- include/linux/fs.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-)
fs/namei.c +11 -4
@@ -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))
include/linux/fs.h +2 -0
@@ -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
Signature · 1 line
2.1.0
Quoted 1 line
From
19510de7d710a34c47eadb9b8f71881b5621574aMon Sep 17 00:00:00 2001
Message-Id: <19510de7d710a34c47eadb9b8f71881b5621574a.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 05:13:56 +0530
Subject: [RFC 06/21] vfs: Make the inode passed to inode_change_ok
non-const
To: [email protected],
[email protected],
[email protected]
We will need to call iop->permission and iop->get_acl from inode_change_ok() for additional permission checks, and both take a non-const inode.
--- fs/attr.c | 2 +- include/linux/fs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/attr.c +1 -1
@@ -28,7 +28,7 @@* Should be called as the first thing in ->setattr implementations, * possibly after taking additional locks. */ -int inode_change_ok (const struct inode *inode,struct iattr *attr) +int inode_change_ok (struct inode *inode,struct iattr *attr) {unsigned int ia_valid = attr->ia_valid;
include/linux/fs.h +1 -1
@@ -2760,7 +2760,7 @@ extern int buffer_migrate_page(struct address_space *,#define buffer_migrate_page NULL#endif -extern int inode_change_ok (const struct inode *,struct iattr *); +extern int inode_change_ok (struct inode *,struct iattr *);extern int inode_newsize_ok (const struct inode *,loff_t offset);extern void setattr_copy (struct inode *inode,const struct iattr *attr);
Signature · 1 line
2.1.0
Quoted 1 line
From
e710237138b0ee9012bc616012d1f8511cf6af4aMon Sep 17 00:00:00 2001
Message-Id: <e710237138b0ee9012bc616012d1f8511cf6af4a.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 05:29:34 +0530
Subject: [RFC 07/21] vfs: Add permission flags for setting file
attributes
To: [email protected],
[email protected],
[email protected]
Richacls support permissions that allow to take ownership of a file, change the file permissions, and set the file timestamps. Support that by introducing new permission mask flags and by checking for those mask flags in inode_change_ok().
--- fs/attr.c | 79 +++++++++++++++++++++++++++++++++++++++++++++--------- include/linux/fs.h | 3 +++ 2 files changed, 70 insertions(+), 12 deletions(-)
fs/attr.c +67 -12
102 lines not on this page · raw message
include/linux/fs.h +3 -0
@@ -84,6 +84,9 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,#define MAY_CREATE_DIR 0x00000200#define MAY_DELETE_CHILD 0x00000400#define MAY_DELETE_SELF 0x00000800 +#define MAY_TAKE_OWNERSHIP 0x00001000 +#define MAY_CHMOD 0x00002000 +#define MAY_SET_TIMES 0x00004000/* * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond
Signature · 1 line
2.1.0
Quoted 1 line
From
a47d85681cea868d4e34794982297950533c2930Mon Sep 17 00:00:00 2001
Message-Id: <a47d85681cea868d4e34794982297950533c2930.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:10:17 +0530
Subject: [RFC 08/21] richacl: In-memory representation and helper
functions
To: [email protected],
[email protected],
[email protected]
A richacl consists of an NFSv4 acl and an owner, group, and other mask. These three masks correspond to the owner, group, and other file permission bits, but they contain NFSv4 permissions instead of POSIX permissions.
Each entry in the NFSv4 acl applies to the file owner (OWNER@), the owning group (GROUP@), everyone (EVERYONE@), or to a specific uid or gid.
As in the standard POSIX file permission model, each process is the owner, group, or other file class. A richacl grants a requested access only if the NFSv4 acl in the richacl grants the access (according to the NFSv4 permission check algorithm), and the file mask that applies to the process includes the requested permissions.
--- fs/Makefile | 2 + fs/richacl_base.c | 57 +++++++++++ include/linux/richacl.h | 248 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 fs/richacl_base.c create mode 100644 include/linux/richacl.h
fs/Makefile +2 -0
@@ -47,6 +47,8 @@ obj-$(CONFIG_COREDUMP) += coredump.o obj-$(CONFIG_SYSCTL) += drop_caches.o obj-$(CONFIG_FHANDLE) += fhandle.o +obj-$(CONFIG_FS_RICHACL) += richacl.o +richacl-y := richacl_base.o obj-y += quota/
fs/richacl_base.c new file +57 -0
57 lines not on this page · raw message
include/linux/richacl.h new file +248 -0
248 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 1 line
From
fe15273975043bc6064de8395e41ba3066f8d5d4Mon Sep 17 00:00:00 2001
Message-Id: <fe15273975043bc6064de8395e41ba3066f8d5d4.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:11:56 +0530
Subject: [RFC 09/21] richacl: Permission mapping functions
To: [email protected],
[email protected],
[email protected]
We need to map from POSIX permissions to NFSv4 permissions when a chmod() is done, from NFSv4 permissions to POSIX permissions when an acl is set (which implicitly sets the file permission bits), and from the MAY_READ/MAY_WRITE/MAY_EXEC/MAY_APPEND flags to NFSv4 permissions when doing an access check in a richacl.
--- fs/richacl_base.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 46 +++++++++++++++++++ 2 files changed, 163 insertions(+)
fs/richacl_base.c +117 -0
120 lines not on this page · raw message
include/linux/richacl.h +46 -0
57 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 1 line
From
ae4e31aeac1c56249ae7092c84fe554ccb34df41Mon Sep 17 00:00:00 2001
Message-Id: <ae4e31aeac1c56249ae7092c84fe554ccb34df41.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:13:16 +0530
Subject: [RFC 10/21] richacl: Compute maximum file masks from an acl
To: [email protected],
[email protected],
[email protected]
Compute upper bound owner, group, and other file masks with as few permissions as possible without denying any permissions that the NFSv4 acl in a richacl grants.
This algorithm is used when a file inherits an acl at create time and when an acl is set via a mechanism that does not specify file modes (such as via nfsd). When user-space sets an acl, the file masks are passed in as part of the xattr.
When setting a richacl, the file masks determine what the file permission bits will be set to; see richacl_masks_to_mode().
--- fs/richacl_base.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 129 insertions(+)
fs/richacl_base.c +128 -0
131 lines not on this page · raw message
include/linux/richacl.h +1 -0
@@ -290,5 +290,6 @@ extern struct richacl *richacl_alloc(int);extern int richacl_masks_to_mode (const struct richacl *);extern unsigned int richacl_mode_to_mask (mode_t );extern unsigned int richacl_want_to_mask (unsigned int ); +extern void richacl_compute_max_masks (struct richacl *);#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
Quoted 1 line
From
ae450198a6c8cb199f43005757598a41cc50937dMon Sep 17 00:00:00 2001
Message-Id: <ae450198a6c8cb199f43005757598a41cc50937d.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:14:18 +0530
Subject: [RFC 11/21] richacl: Update the file masks in chmod()
To: [email protected],
[email protected],
[email protected]
Doing a chmod() sets the file mode, which includes the file permission bits. When a file has a richacl, the permissions that the richacl grants need to be limited to what the new file permission bits allow.
This is done by setting the file masks in the richacl to what the file permission bits map to. The richacl access check algorithm takes the file masks into account, which ensures that the richacl cannot grant too many permissions.
It is possible to explicitly add permissions to the file masks which go beyond what the file permission bits can grant (like the ACE4_WRITE_ACL permission). The POSIX.1 standard calls this an alternate file access control mechanism. A subsequent chmod() would ensure that those permissions are disabled again.
--- fs/richacl_base.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 41 insertions(+)
fs/richacl_base.c +40 -0
@@ -300,3 +300,43 @@ restart: acl->a_flags &= ~ACL4_MASKED ; }EXPORT_SYMBOL_GPL (richacl_compute_max_masks); + +/** +* richacl_chmod - update the file masks to reflect the new mode +* @mode: new file permission bits +* +* Return a copy of @acl where the file masks have been replaced by the file +* masks corresponding to the file permission bits in @mode, or returns @acl +* itself if the file masks are already up to date. Takes over a reference +* to @acl. +*/ +struct richacl * +richacl_chmod (struct richacl *acl,mode_t mode) +{ +unsigned int owner_mask, group_mask, other_mask; +struct richacl *clone; + + owner_mask =richacl_mode_to_mask (mode >>6 ) | +ACE4_POSIX_OWNER_ALLOWED ; + group_mask =richacl_mode_to_mask (mode >>3 ); + other_mask =richacl_mode_to_mask (mode); + +if (acl->a_owner_mask == owner_mask && + acl->a_group_mask == group_mask && + acl->a_other_mask == other_mask && + (acl->a_flags &ACL4_MASKED )) +return acl; + + clone =richacl_clone (acl); +richacl_put (acl); +if (!clone) +return ERR_PTR (-ENOMEM ); + + clone->a_flags |=ACL4_MASKED ; + clone->a_owner_mask = owner_mask; + clone->a_group_mask = group_mask; + clone->a_other_mask = other_mask; + +return clone; +} +EXPORT_SYMBOL_GPL (richacl_chmod);
include/linux/richacl.h +1 -0
@@ -291,5 +291,6 @@ extern int richacl_masks_to_mode(const struct richacl *);extern unsigned int richacl_mode_to_mask (mode_t );extern unsigned int richacl_want_to_mask (unsigned int );extern void richacl_compute_max_masks (struct richacl *); +extern struct richacl *richacl_chmod (struct richacl *,mode_t );#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
Quoted 1 line
From
516c44e08972125aee20a90e0399aaefe8e6d553Mon Sep 17 00:00:00 2001
Message-Id: <516c44e08972125aee20a90e0399aaefe8e6d553.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:15:22 +0530
Subject: [RFC 12/21] richacl: Permission check algorithm
To: [email protected],
[email protected],
[email protected]
A richacl grants a requested access if the NFSv4 acl in the richacl grants the requested permissions (according to the NFSv4 permission check algorithm) and the file mask that applies to the process includes the requested permissions.
--- fs/richacl_base.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 113 insertions(+)
fs/richacl_base.c +112 -0
115 lines not on this page · raw message
include/linux/richacl.h +1 -0
@@ -292,5 +292,6 @@ extern unsigned int richacl_mode_to_mask(mode_t);extern unsigned int richacl_want_to_mask (unsigned int );extern void richacl_compute_max_masks (struct richacl *);extern struct richacl *richacl_chmod (struct richacl *,mode_t ); +extern int richacl_permission (struct inode *,const struct richacl *,int );#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
Quoted 1 line
From
213ba5b03fffbcf6a7ff78a3585568eff7b43527Mon Sep 17 00:00:00 2001
Message-Id: <213ba5b03fffbcf6a7ff78a3585568eff7b43527.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:17:22 +0530
Subject: [RFC 13/21] richacl: Create-time inheritance
To: [email protected],
[email protected],
[email protected]
When a new file is created, it can inherit an acl from its parent directory; this is similar to how default acls work in POSIX (draft) ACLs.
As with POSIX ACLs, if a file inherits an acl from its parent directory, the intersection between the create mode and the permissions granted by the inherited acl determines the file masks and file permission bits, and the umask is ignored.
--- fs/Makefile | 2 +- fs/richacl_base.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/richacl_inode.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 4 +++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 fs/richacl_inode.c
fs/Makefile +1 -1
@@ -48,7 +48,7 @@ obj-$(CONFIG_SYSCTL) += drop_caches.o obj-$(CONFIG_FHANDLE) += fhandle.o obj-$(CONFIG_FS_RICHACL) += richacl.o -richacl-y := richacl_base.o +richacl-y := richacl_base.o richacl_inode.o obj-y += quota/
fs/richacl_base.c +69 -0
72 lines not on this page · raw message
fs/richacl_inode.c new file +62 -0
62 lines not on this page · raw message
include/linux/richacl.h +4 -0
@@ -293,5 +293,9 @@ extern unsigned int richacl_want_to_mask(unsigned int);extern void richacl_compute_max_masks (struct richacl *);extern struct richacl *richacl_chmod (struct richacl *,mode_t );extern int richacl_permission (struct inode *,const struct richacl *,int ); +extern struct richacl *richacl_inherit (const struct richacl *,int ); +/* richacl_inode.c */ +extern struct richacl *richacl_inherit_inode (const struct richacl *, +struct inode *);#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
Quoted 1 line
From
410d49744f16fb757be06a4c2a9e97b9eb760d70Mon Sep 17 00:00:00 2001
Message-Id: <410d49744f16fb757be06a4c2a9e97b9eb760d70.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:18:38 +0530
Subject: [RFC 14/21] richacl: Check if an acl is equivalent to a file
mode
To: [email protected],
[email protected],
[email protected]
This function is used to avoid storing richacls if the acl can be computed from the file permission bits.
--- fs/richacl_base.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 55 insertions(+)
fs/richacl_base.c +54 -0
57 lines not on this page · raw message
include/linux/richacl.h +1 -0
@@ -294,6 +294,7 @@ extern void richacl_compute_max_masks(struct richacl *);extern struct richacl *richacl_chmod (struct richacl *,mode_t );extern int richacl_permission (struct inode *,const struct richacl *,int );extern struct richacl *richacl_inherit (const struct richacl *,int ); +extern int richacl_equiv_mode (const struct richacl *,mode_t *);/* richacl_inode.c */ extern struct richacl *richacl_inherit_inode(const struct richacl *,
Signature · 1 line
2.1.0
Quoted 1 line
From
39c338514faf1b135b8515db11c58720f6897e9dMon Sep 17 00:00:00 2001
Message-Id: <39c338514faf1b135b8515db11c58720f6897e9d.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:19:48 +0530
Subject: [RFC 15/21] richacl: Automatic Inheritance
To: [email protected],
[email protected],
[email protected]
Automatic Inheritance (AI) allows changes to the acl of a directory to recursively propagate down to files and directories in the directory.
To implement this, the kernel keeps track of which permissions have been inherited, and makes sure that permission propagation is turned off when the file permission bits of a file are changed (upon create or chmod).
The actual permission propagation is implemented in user space.
Automatic Inheritance works as follows:
- When the ACL4_AUTO_INHERIT flag in the acl of a file is not set, the file is not affected by AI.
- When the ACL4_AUTO_INHERIT flag in the acl of a directory is set and a file or subdirectory is created in that directory, files created in the directory will have the ACL4_AUTO_INHERIT flag set, and all inherited aces will have the ACE4_INHERITED_ACE flag set. This allows user space to distinguish between aces which have been inherited and aces which have been explicitly added.
- When the ACL4_PROTECTED acl flag in the acl of a file is set, AI will not modify the acl of the file. This does not affect propagation of permissions from the file to its children (if the file is a directory).
Linux does not have a way of creating files without setting the file permission bits, so all files created inside a directory with ACL4_AUTO_INHERIT set will also have the ACL4_PROTECTED flag set. This effectively disables Automatic Inheritance.
Protocols which support creating files without specifying permissions can explicitly clear the ACL4_PROTECTED flag after creating a file and reset the file masks to "undo" applying the create mode; see richacl_compute_max_masks(). This is a workaround; a mechanism that would allow a process to indicate to the kernel to ignore the create mode when there are inherited permissions would fix this problem.
--- fs/richacl_base.c | 10 +++++++++- fs/richacl_inode.c | 7 ++++++- include/linux/richacl.h | 24 +++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-)
fs/richacl_base.c +9 -1
@@ -324,7 +324,8 @@ richacl_chmod(struct richacl *acl, mode_t mode)if (acl->a_owner_mask == owner_mask && acl->a_group_mask == group_mask && acl->a_other_mask == other_mask && - (acl->a_flags &ACL4_MASKED )) + (acl->a_flags &ACL4_MASKED ) && + (!richacl_is_auto_inherit (acl) ||richacl_is_protected (acl)))return acl; clone =richacl_clone (acl);
@@ -336,6 +337,8 @@ richacl_chmod(struct richacl *acl, mode_t mode) clone->a_owner_mask = owner_mask; clone->a_group_mask = group_mask; clone->a_other_mask = other_mask; +if (richacl_is_auto_inherit (clone)) + clone->a_flags |=ACL4_PROTECTED ;return clone; }
@@ -518,6 +521,11 @@ richacl_inherit(const struct richacl *dir_acl, int isdir) ace++; } } +if (richacl_is_auto_inherit (dir_acl)) { + acl->a_flags =ACL4_AUTO_INHERIT ; +richacl_for_each_entry (ace, acl) + ace->e_flags |=ACE4_INHERITED_ACE ; + }return acl; }
fs/richacl_inode.c +6 -1
@@ -40,9 +40,14 @@ richacl_inherit_inode(const struct richacl *dir_acl, struct inode *inode) acl =richacl_inherit (dir_acl,S_ISDIR (inode->i_mode));if (acl) { +/* +* We need to set ACL4_PROTECTED because we are +* doing an implicit chmod +*/ +if (richacl_is_auto_inherit (acl)) + acl->a_flags |=ACL4_PROTECTED ;richacl_compute_max_masks (acl); -/* * Ensure that the acl will not grant any permissions beyond * the create mode.
include/linux/richacl.h +23 -1
@@ -49,10 +49,17 @@ struct richacl { _ace != (_acl)->a_entries -1 ; \ _ace--) +/* a_flags values */ +#define ACL4_AUTO_INHERIT 0x01 +#define ACL4_PROTECTED 0x02 +#define ACL4_DEFAULTED 0x04/* Flag values defined by richacls */ #define ACL4_MASKED 0x80#define ACL4_VALID_FLAGS ( \ + ACL4_AUTO_INHERIT | \ + ACL4_PROTECTED | \ + ACL4_DEFAULTED | \ ACL4_MASKED)/* e_type values */
@@ -69,6 +76,7 @@ struct richacl {/*#define ACE4_SUCCESSFUL_ACCESS_ACE_FLAG 0x0010*/ /*#define ACE4_FAILED_ACCESS_ACE_FLAG 0x0020*/ #define ACE4_IDENTIFIER_GROUP 0x0040 +#define ACE4_INHERITED_ACE 0x0080/* richacl specific flag values */ #define ACE4_SPECIAL_WHO 0x4000
@@ -78,6 +86,7 @@ struct richacl {ACE4_NO_PROPAGATE_INHERIT_ACE | \ACE4_INHERIT_ONLY_ACE | \ACE4_IDENTIFIER_GROUP | \ +ACE4_INHERITED_ACE | \ ACE4_SPECIAL_WHO)/* e_mask bitflags */
@@ -184,6 +193,18 @@ richacl_put(struct richacl *acl)kfree (acl); } +static inline int +richacl_is_auto_inherit (const struct richacl *acl) +{ +return acl->a_flags &ACL4_AUTO_INHERIT ; +} + +static inline int +richacl_is_protected (const struct richacl *acl) +{ +return acl->a_flags &ACL4_PROTECTED ; +} +/** * richace_is_owner - check if @ace is an OWNER@ entry */
@@ -254,7 +275,8 @@ richace_clear_inheritance_flags(struct richace *ace) ace->e_flags &= ~(ACE4_FILE_INHERIT_ACE |ACE4_DIRECTORY_INHERIT_ACE |ACE4_NO_PROPAGATE_INHERIT_ACE | -ACE4_INHERIT_ONLY_ACE ); +ACE4_INHERIT_ONLY_ACE | +ACE4_INHERITED_ACE ); }/**
Signature · 1 line
2.1.0
Quoted 1 line
From
38f525822b15ec67c337cc90659fecb3737a0767Mon Sep 17 00:00:00 2001
Message-Id: <38f525822b15ec67c337cc90659fecb3737a0767.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:20:43 +0530
Subject: [RFC 16/21] richacl: xattr mapping functions
To: [email protected],
[email protected],
[email protected]
Map between "system.richacl" xattrs and the in-kernel representation.
--- fs/Makefile | 2 +- fs/richacl_xattr.c | 131 ++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl_xattr.h | 47 +++++++++++++++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 fs/richacl_xattr.c create mode 100644 include/linux/richacl_xattr.h
fs/Makefile +1 -1
@@ -48,7 +48,7 @@ obj-$(CONFIG_SYSCTL) += drop_caches.o obj-$(CONFIG_FHANDLE) += fhandle.o obj-$(CONFIG_FS_RICHACL) += richacl.o -richacl-y := richacl_base.o richacl_inode.o +richacl-y := richacl_base.o richacl_inode.o richacl_xattr.o obj-y += quota/
fs/richacl_xattr.c new file +131 -0
131 lines not on this page · raw message
include/linux/richacl_xattr.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 1 line
From
ae174bdfb12f44f592301bec7c0e69688bb4d3b7Mon Sep 17 00:00:00 2001
Message-Id: <ae174bdfb12f44f592301bec7c0e69688bb4d3b7.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Sat, 14 Feb 2015 19:31:38 +0100
Subject: [RFC 17/21] vfs: Cache base_acl objects in inodes
To: [email protected],
[email protected],
[email protected]
POSIX ACLs and richacls are both objects allocated by kmalloc() with a reference count which are freed by kfree_rcu(). An inode can either cache an access and a default POSIX ACL, or a richacl. (Richacls do not have default acls). To allow an inode to cache either of the two kinds of acls, introduce a new base_acl type and convert i_acl and i_default_acl to that type. In most cases, the vfs then doesn't have to care which kind of acl an inode caches (if any).
--- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- fs/f2fs/acl.c | 4 ++-- fs/inode.c | 4 ++-- fs/posix_acl.c | 18 +++++++++--------- include/linux/fs.h | 22 +++++++++++++++++++--- include/linux/posix_acl.h | 9 ++++----- include/linux/richacl.h | 2 +- 7 files changed, 38 insertions(+), 23 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
@@ -1145,7 +1145,7 @@ void ll_clear_inode(struct inode *inode) }#ifdef CONFIG_FS_POSIX_ACL else if (lli->lli_posix_acl) { -LASSERT (atomic_read (&lli->lli_posix_acl->a_refcount) ==1 ); +LASSERT (atomic_read (&lli->lli_posix_acl->a_base.ba_refcount) ==1 );LASSERT (lli->lli_remote_perms ==NULL );posix_acl_release (lli->lli_posix_acl); lli->lli_posix_acl =NULL ;
fs/f2fs/acl.c +2 -2
@@ -270,7 +270,7 @@ static struct posix_acl *f2fs_acl_clone(const struct posix_acl *acl,sizeof (struct posix_acl_entry ); clone =kmemdup (acl, size, flags);if (clone) -atomic_set (&clone->a_refcount,1 ); +atomic_set (&clone->a_base.ba_refcount,1 ); }return clone; }
@@ -282,7 +282,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)umode_t mode = *mode_p;int not_equiv =0 ; -/* assert(atomic_read(acl->a_refcount) == 1); */ +/* assert(atomic_read(acl->a_base.ba_refcount) == 1); */ FOREACH_ACL_ENTRY(pa, acl, pe) {switch (pa->e_tag) {
fs/inode.c +2 -2
@@ -233,9 +233,9 @@ void __destroy_inode(struct inode *inode)#ifdef CONFIG_FS_POSIX_ACL if (inode->i_acl && inode->i_acl !=ACL_NOT_CACHED ) -posix_acl_release (inode->i_acl); +put_base_acl (inode->i_acl);if (inode->i_default_acl && inode->i_default_acl !=ACL_NOT_CACHED ) -posix_acl_release (inode->i_default_acl); +put_base_acl (inode->i_default_acl);#endif this_cpu_dec (nr_inodes); }
fs/posix_acl.c +9 -9
@@ -25,9 +25,9 @@ struct posix_acl **acl_by_type(struct inode *inode, int type) {switch (type) {case ACL_TYPE_ACCESS : -return &inode->i_acl; +return (struct posix_acl **)&inode->i_acl;case ACL_TYPE_DEFAULT : -return &inode->i_default_acl; +return (struct posix_acl **)&inode->i_default_acl;default :BUG (); }
@@ -83,16 +83,16 @@ EXPORT_SYMBOL(forget_cached_acl);void forget_all_cached_acls (struct inode *inode) { -struct posix_acl *old_access, *old_default; +struct base_acl *old_access, *old_default;spin_lock (&inode->i_lock); old_access = inode->i_acl; old_default = inode->i_default_acl; inode->i_acl = inode->i_default_acl =ACL_NOT_CACHED ;spin_unlock (&inode->i_lock);if (old_access !=ACL_NOT_CACHED ) -posix_acl_release (old_access); +put_base_acl (old_access);if (old_default !=ACL_NOT_CACHED ) -posix_acl_release (old_default); +put_base_acl (old_default); }EXPORT_SYMBOL (forget_all_cached_acls);
@@ -129,7 +129,7 @@ EXPORT_SYMBOL(get_acl);void posix_acl_init (struct posix_acl *acl,int count) { -atomic_set (&acl->a_refcount,1 ); +atomic_set (&acl->a_base.ba_refcount,1 ); acl->a_count = count; }EXPORT_SYMBOL (posix_acl_init);
@@ -163,7 +163,7 @@ posix_acl_clone(const struct posix_acl *acl, gfp_t flags)sizeof (struct posix_acl_entry ); clone =kmemdup (acl, size, flags);if (clone) -atomic_set (&clone->a_refcount,1 ); +atomic_set (&clone->a_base.ba_refcount,1 ); }return clone; }
@@ -385,7 +385,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)umode_t mode = *mode_p;int not_equiv =0 ; -/* assert(atomic_read(acl->a_refcount) == 1); */ +/* assert(atomic_read(acl->a_base.ba_refcount) == 1); */ FOREACH_ACL_ENTRY(pa, acl, pe) {switch (pa->e_tag) {
@@ -440,7 +440,7 @@ static int __posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode)struct posix_acl_entry *group_obj =NULL , *mask_obj =NULL ;struct posix_acl_entry *pa, *pe; -/* assert(atomic_read(acl->a_refcount) == 1); */ +/* assert(atomic_read(acl->a_base.ba_refcount) == 1); */ FOREACH_ACL_ENTRY(pa, acl, pe) {switch (pa->e_tag) {
include/linux/fs.h +19 -3
@@ -547,6 +547,9 @@ static inline void mapping_allow_writable(struct address_space *mapping)#define i_size_ordered_init (inode) do { } while (0)#endif +struct base_acl { +atomic_t ba_refcount; +};struct posix_acl ;#define ACL_NOT_CACHED ((void *)(-1))
@@ -566,9 +569,9 @@ struct inode {kgid_t i_gid;unsigned int i_flags; -#ifdef CONFIG_FS_POSIX_ACL -struct posix_acl *i_acl; -struct posix_acl *i_default_acl; +#if defined(CONFIG_FS_POSIX_ACL ) +struct base_acl *i_acl; +struct base_acl *i_default_acl;#endif const struct inode_operations *i_op;
@@ -2936,4 +2939,17 @@ static inline bool dir_relax(struct inode *inode) return !IS_DEADDIR(inode); } +static inline struct base_acl *get_base_acl (struct base_acl *acl) +{ +if (acl) +atomic_inc (&acl->ba_refcount); +return acl; +} + +static inline void put_base_acl (struct base_acl *acl) +{ +if (acl &&atomic_dec_and_test (&acl->ba_refcount)) +__kfree_rcu ((struct rcu_head *)acl,0 ); +} +#endif /* _LINUX_FS_H */
include/linux/posix_acl.h +4 -5
@@ -43,7 +43,7 @@ struct posix_acl_entry { };struct posix_acl { -atomic_t a_refcount; +struct base_acl a_base;unsigned int a_count;struct posix_acl_entry a_entries[0 ]; };
@@ -58,8 +58,7 @@ struct posix_acl {static inline struct posix_acl *posix_acl_dup (struct posix_acl *acl) { -if (acl) -atomic_inc (&acl->a_refcount); +get_base_acl (&acl->a_base);return acl; }
@@ -69,8 +68,8 @@ posix_acl_dup(struct posix_acl *acl)static inline void posix_acl_release (struct posix_acl *acl) { -if (acl &&atomic_dec_and_test (&acl->a_refcount)) -__kfree_rcu ((struct rcu_head *)acl,0 ); +BUILD_BUG_ON (offsetof(struct posix_acl , a_base) !=0 ); +put_base_acl (&acl->a_base); }
include/linux/richacl.h +1 -1
@@ -179,7 +179,7 @@ static inline struct richacl * richacl_get(struct richacl *acl) {if (acl) -atomic_inc (&acl->a_refcount); +atomic_inc (&acl->a_base.ba_refcount);return acl; }
Signature · 1 line
2.1.0
Quoted 1 line
From
3f5c803548a9fc24f1b7f0be25524fb6bd41ccddMon Sep 17 00:00:00 2001
Message-Id: <3f5c803548a9fc24f1b7f0be25524fb6bd41ccdd.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 19:28:44 +0530
Subject: [RFC 18/21] vfs: Cache richacl in struct inode
To: [email protected],
[email protected],
[email protected]
Cache richacls in struct inode so that this doesn't have to be done individually in each filesystem. This is similar to POSIX ACLs.
--- fs/inode.c | 11 +++++-- fs/posix_acl.c | 2 +- fs/richacl_base.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/fs.h | 6 +++- include/linux/richacl.h | 15 ++++++--- 5 files changed, 102 insertions(+), 13 deletions(-)
fs/inode.c +8 -3
@@ -175,8 +175,11 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_private =NULL ; inode->i_mapping = mapping;INIT_HLIST_HEAD (&inode->i_dentry);/* buggered by rcu freeing */ -#ifdef CONFIG_FS_POSIX_ACL - inode->i_acl = inode->i_default_acl =ACL_NOT_CACHED ; +#if defined(CONFIG_FS_POSIX_ACL ) || defined(CONFIG_FS_RICHACL ) + inode->i_acl =ACL_NOT_CACHED ; +# if defined(CONFIG_FS_POSIX_ACL ) + inode->i_default_acl =ACL_NOT_CACHED ; +# endif #endif #ifdef CONFIG_FSNOTIFY
@@ -231,11 +234,13 @@ void __destroy_inode(struct inode *inode)atomic_long_dec (&inode->i_sb->s_remove_count); } -#ifdef CONFIG_FS_POSIX_ACL +#if defined(CONFIG_FS_POSIX_ACL ) || defined(CONFIG_FS_RICHACL )if (inode->i_acl && inode->i_acl !=ACL_NOT_CACHED )put_base_acl (inode->i_acl); +# if defined(CONFIG_FS_POSIX_ACL )if (inode->i_default_acl && inode->i_default_acl !=ACL_NOT_CACHED )put_base_acl (inode->i_default_acl); +# endif #endif this_cpu_dec (nr_inodes); }
fs/posix_acl.c +1 -1
@@ -38,7 +38,7 @@ struct posix_acl *get_cached_acl(struct inode *inode, int type) {struct posix_acl **p =acl_by_type (inode, type);struct posix_acl *acl =ACCESS_ONCE (*p); -if (acl) { +if (acl &&IS_POSIXACL (inode)) {spin_lock (&inode->i_lock); acl = *p;if (acl !=ACL_NOT_CACHED )
fs/richacl_base.c +78 -3
102 lines not on this page · raw message
include/linux/fs.h +5 -1
@@ -551,6 +551,7 @@ struct base_acl {atomic_t ba_refcount; };struct posix_acl ; +struct richacl ;#define ACL_NOT_CACHED ((void *)(-1))#define IOP_FASTPERM 0x0001
@@ -569,9 +570,11 @@ struct inode {kgid_t i_gid;unsigned int i_flags; -#if defined(CONFIG_FS_POSIX_ACL ) +#if defined(CONFIG_FS_POSIX_ACL ) || defined(CONFIG_FS_RICHACL )struct base_acl *i_acl; +# if defined(CONFIG_FS_POSIX_ACL )struct base_acl *i_default_acl; +# endif #endif const struct inode_operations *i_op;
@@ -1586,6 +1589,7 @@ struct inode_operations {void * (*follow_link) (struct dentry *,struct nameidata *);int (*permission) (struct inode *,int );struct posix_acl * (*get_acl)(struct inode *,int ); +struct richacl * (*get_richacl)(struct inode *);int (*readlink) (struct dentry *,char __user *,int );void (*put_link) (struct dentry *,struct nameidata *,void *);
include/linux/richacl.h +10 -5
@@ -30,7 +30,7 @@ struct richace { };struct richacl { -atomic_t a_refcount; +struct base_acl a_base;unsigned int a_owner_mask;unsigned int a_group_mask;unsigned int a_other_mask;
@@ -178,8 +178,7 @@ struct richacl {static inline struct richacl *richacl_get (struct richacl *acl) { -if (acl) -atomic_inc (&acl->a_base.ba_refcount); +get_base_acl (&acl->a_base);return acl; }
@@ -189,10 +188,16 @@ richacl_get(struct richacl *acl)static inline void richacl_put (struct richacl *acl) { -if (acl &&atomic_dec_and_test (&acl->a_refcount)) -kfree (acl); +BUILD_BUG_ON (offsetof(struct richacl , a_base) !=0 ); +put_base_acl (&acl->a_base); } +extern struct richacl *get_cached_richacl (struct inode *); +extern struct richacl *get_cached_richacl_rcu (struct inode *); +extern void set_cached_richacl (struct inode *,struct richacl *); +extern void forget_cached_richacl (struct inode *); +extern struct richacl *get_richacl (struct inode *); +static inline int richacl_is_auto_inherit (const struct richacl *acl) {
Signature · 1 line
2.1.0
Quoted 1 line
From
b467e4dcfbff041accd57839765468c4042a20c5Mon Sep 17 00:00:00 2001
Message-Id: <b467e4dcfbff041accd57839765468c4042a20c5.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Andreas Gruenbacher <[email protected]>
Date: Tue, 1 Apr 2014 18:08:42 +0530
Subject: [RFC 19/21] vfs: Add richacl permission checking
To: [email protected],
[email protected],
[email protected]
Hook the richacl permission checking function into the vfs.
--- fs/namei.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- fs/posix_acl.c | 6 +++--- 2 files changed, 52 insertions(+), 5 deletions(-)
fs/namei.c +49 -2
73 lines not on this page · raw message
fs/posix_acl.c +3 -3
@@ -100,13 +100,13 @@ struct posix_acl *get_acl(struct inode *inode, int type) {struct posix_acl *acl; +if (!IS_POSIXACL (inode)) +return NULL ; + acl =get_cached_acl (inode, type);if (acl !=ACL_NOT_CACHED )return acl; -if (!IS_POSIXACL (inode)) -return NULL ; -/* * A filesystem can force a ACL callback by just never filling the * ACL cache. But normally you'd fill the cache either at inode
Signature · 1 line
2.1.0
Quoted 1 line
From
c6043a752cec38940291b0caca452826afb1fa04Mon Sep 17 00:00:00 2001
Message-Id: <c6043a752cec38940291b0caca452826afb1fa04.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: "Aneesh Kumar K.V" <[email protected]>
Date: Wed, 23 Apr 2014 20:54:41 +0530
Subject: [RFC 20/21] ext4: Implement rich acl for ext4
To: [email protected],
[email protected],
[email protected]
Support the richacl permission model in ext4. The richacls are stored in "system.richacl" xattrs. Richacls need to be enabled by tune2fs or at file system create time.
--- fs/ext4/Kconfig | 15 ++++ fs/ext4/Makefile | 1 + fs/ext4/acl.c | 7 +- fs/ext4/acl.h | 12 +-- fs/ext4/file.c | 6 +- fs/ext4/ialloc.c | 7 +- fs/ext4/inode.c | 10 ++- fs/ext4/namei.c | 11 ++- fs/ext4/richacl.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/richacl.h | 47 +++++++++++ fs/ext4/xattr.c | 6 ++ fs/ext4/xattr.h | 1 + 12 files changed, 332 insertions(+), 20 deletions(-) create mode 100644 fs/ext4/richacl.c create mode 100644 fs/ext4/richacl.h
fs/ext4/Kconfig +15 -0
@@ -73,3 +73,18 @@ config EXT4_DEBUG If you select Y here, then you will be able to turn on debugging with a command such as: echo 1 > /sys/module/ext4/parameters/mballoc_debug + +config EXT4_FS_RICHACL + bool "Ext4 Rich Access Control Lists (EXPERIMENTAL)" + depends on EXT4_FS + select FS_RICHACL + help + Rich ACLs are an implementation of NFSv4 ACLs, extended by file masks + to fit into the standard POSIX file permission model. They are + designed to work seamlessly locally as well as across the NFSv4 and + CIFS/SMB2 network file system protocols. + + To learn more about Rich ACL, visit + http://acl.bestbits.at/richacl/ + + If you don't know what Rich ACLs are, say N
fs/ext4/Makefile +1 -0
@@ -12,3 +12,4 @@ ext4-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o page-io.o \ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o +ext4-$(CONFIG_EXT4_FS_RICHACL) += richacl.o
fs/ext4/acl.c +3 -4
@@ -144,8 +144,7 @@ fail:* * inode->i_mutex: don't care */ -struct posix_acl * -ext4_get_acl (struct inode *inode,int type) +struct posix_acl *ext4_get_posix_acl (struct inode *inode,int type) {int name_index;char *value =NULL ;
@@ -239,7 +238,7 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type, }int -ext4_set_acl (struct inode *inode,struct posix_acl *acl,int type) +ext4_set_posix_acl (struct inode *inode,struct posix_acl *acl,int type) {handle_t *handle;int error, retries =0 ;
@@ -264,7 +263,7 @@ retry:* inode->i_mutex: up (access to inode is still exclusive) */ int -ext4_init_acl (handle_t *handle,struct inode *inode,struct inode *dir) +ext4_init_posix_acl (handle_t *handle,struct inode *inode,struct inode *dir) {struct posix_acl *default_acl, *acl;int error;
fs/ext4/acl.h +6 -6
@@ -54,17 +54,17 @@ static inline int ext4_acl_count(size_t size)#ifdef CONFIG_EXT4_FS_POSIX_ACL /* acl.c */ -struct posix_acl *ext4_get_acl (struct inode *inode,int type); -int ext4_set_acl (struct inode *inode,struct posix_acl *acl,int type); -extern int ext4_init_acl (handle_t *,struct inode *,struct inode *); +struct posix_acl *ext4_get_posix_acl (struct inode *inode,int type); +int ext4_set_posix_acl (struct inode *inode,struct posix_acl *acl,int type); +extern int ext4_init_posix_acl (handle_t *,struct inode *,struct inode *);#else /* CONFIG_EXT4_FS_POSIX_ACL */ #include <linux/sched.h> -#define ext4_get_acl NULL -#define ext4_set_acl NULL +#define ext4_get_posix_acl NULL +#define ext4_set_posix_acl NULLstatic inline int -ext4_init_acl (handle_t *handle,struct inode *inode,struct inode *dir) +ext4_init_posix_acl (handle_t *handle,struct inode *inode,struct inode *dir) {return 0 ; }
fs/ext4/file.c +4 -2
@@ -30,6 +30,7 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" +#include "richacl.h" /* * Called when an inode is released. Note that this is different
@@ -651,8 +652,9 @@ const struct inode_operations ext4_file_inode_operations = { .getxattr = generic_getxattr, .listxattr = ext4_listxattr, .removexattr = generic_removexattr, - .get_acl = ext4_get_acl, - .set_acl = ext4_set_acl, + .get_acl = ext4_get_posix_acl, + .set_acl = ext4_set_posix_acl, + .get_richacl = ext4_get_richacl, .fiemap = ext4_fiemap, };
fs/ext4/ialloc.c +6 -1
@@ -28,6 +28,7 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" +#include "richacl.h" #include <trace/events/ext4.h>
@@ -1039,7 +1040,11 @@ got:if (err) goto fail_drop; - err =ext4_init_acl (handle, inode, dir); +if (EXT4_IS_RICHACL (dir)) + err =ext4_init_richacl (handle, inode, dir); +else + err =ext4_init_posix_acl (handle, inode, dir); +if (err) goto fail_free_drop;
fs/ext4/inode.c +7 -3
@@ -44,6 +44,7 @@#include "xattr.h" #include "acl.h" #include "truncate.h" +#include "richacl.h" #include <trace/events/ext4.h>
@@ -4657,9 +4658,12 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)if (orphan && inode->i_nlink)ext4_orphan_del (NULL , inode); -if (!rc && (ia_valid &ATTR_MODE )) - rc =posix_acl_chmod (inode, inode->i_mode); - +if (!rc && (ia_valid &ATTR_MODE )) { +if (EXT4_IS_RICHACL (inode)) + rc =ext4_richacl_chmod (inode); +else + rc =posix_acl_chmod (inode, inode->i_mode); + } err_out:ext4_std_error (inode->i_sb, error);if (!error)
fs/ext4/namei.c +7 -4
@@ -39,6 +39,7 @@#include "xattr.h" #include "acl.h" +#include "richacl.h" #include <trace/events/ext4.h> /*
@@ -3541,8 +3542,9 @@ const struct inode_operations ext4_dir_inode_operations = { .getxattr = generic_getxattr, .listxattr = ext4_listxattr, .removexattr = generic_removexattr, - .get_acl = ext4_get_acl, - .set_acl = ext4_set_acl, + .get_acl = ext4_get_posix_acl, + .set_acl = ext4_set_posix_acl, + .get_richacl = ext4_get_richacl, .fiemap = ext4_fiemap, };
@@ -3552,6 +3554,7 @@ const struct inode_operations ext4_special_inode_operations = { .getxattr = generic_getxattr, .listxattr = ext4_listxattr, .removexattr = generic_removexattr, - .get_acl = ext4_get_acl, - .set_acl = ext4_set_acl, + .get_acl = ext4_get_posix_acl, + .set_acl = ext4_set_posix_acl, + .get_richacl = ext4_get_richacl, };
fs/ext4/richacl.c new file +229 -0
229 lines not on this page · raw message
fs/ext4/richacl.h new file +47 -0
47 lines not on this page · raw message
fs/ext4/xattr.c +6 -0
@@ -100,6 +100,9 @@ static const struct xattr_handler *ext4_xattr_handler_map[] = { #ifdef CONFIG_EXT4_FS_SECURITY [EXT4_XATTR_INDEX_SECURITY] = &ext4_xattr_security_handler, #endif +#ifdef CONFIG_EXT4_FS_RICHACL + [EXT4_XATTR_INDEX_RICHACL] = &ext4_richacl_xattr_handler, +#endif }; const struct xattr_handler *ext4_xattr_handlers[] = {
@@ -112,6 +115,9 @@ const struct xattr_handler *ext4_xattr_handlers[] = {#ifdef CONFIG_EXT4_FS_SECURITY &ext4_xattr_security_handler,#endif +#ifdef CONFIG_EXT4_FS_RICHACL + &ext4_richacl_xattr_handler, +#endifNULL };
fs/ext4/xattr.h +1 -0
@@ -97,6 +97,7 @@ struct ext4_xattr_ibody_find {extern const struct xattr_handler ext4_xattr_user_handler;extern const struct xattr_handler ext4_xattr_trusted_handler;extern const struct xattr_handler ext4_xattr_security_handler; +extern const struct xattr_handler ext4_richacl_xattr_handler;extern ssize_t ext4_listxattr (struct dentry *,char *,size_t );
Signature · 1 line
2.1.0
Quoted 1 line
From
2743598850b5ac481b91b7fea5f6f00a04e8beaeMon Sep 17 00:00:00 2001
Message-Id: <2743598850b5ac481b91b7fea5f6f00a04e8beae.1424900921.git.agruenba@redhat.com>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: "Aneesh Kumar K.V" <[email protected]>
Date: Wed, 23 Apr 2014 20:54:54 +0530
Subject: [RFC 21/21] ext4: Add richacl feature flag
To: [email protected],
[email protected],
[email protected]
This feature flag selects richacl instead of posix acl support on the file system. In addition, the "acl" mount option is needed for enabling either of the two kinds of acls.
--- fs/ext4/ext4.h | 6 ++++-- fs/ext4/super.c | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +4 -2
@@ -978,7 +978,7 @@ struct ext4_inode_info {#define EXT4_MOUNT_UPDATE_JOURNAL 0x01000/* Update the journal format */ #define EXT4_MOUNT_NO_UID32 0x02000/* Disable 32-bit UIDs */ #define EXT4_MOUNT_XATTR_USER 0x04000/* Extended user attributes */ -#define EXT4_MOUNT_POSIX_ACL 0x08000/* POSIX Access Control Lists */ +#define EXT4_MOUNT_ACL 0x08000/* Access Control Lists */ #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000/* No auto delalloc mapping */ #define EXT4_MOUNT_BARRIER 0x20000/* Use block barriers */ #define EXT4_MOUNT_QUOTA 0x80000/* Some quota option set */
@@ -1552,6 +1552,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000/* >2GB or 3-lvl htree */ #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000/* data in inode */ #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 +#define EXT4_FEATURE_INCOMPAT_RICHACL 0x20000#define EXT2_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR#define EXT2_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
@@ -1576,7 +1577,8 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) EXT4_FEATURE_INCOMPAT_64BIT| \ EXT4_FEATURE_INCOMPAT_FLEX_BG| \ EXT4_FEATURE_INCOMPAT_MMP | \ - EXT4_FEATURE_INCOMPAT_INLINE_DATA) + EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ + EXT4_FEATURE_INCOMPAT_RICHACL)#define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
fs/ext4/super.c +32 -9
71 lines not on this page · raw message
Signature · 1 line
2.1.0