Richacls (2)
Subsystems (11)
cover Richacls (2)
Hello,
here is an update to the richacl patch queue. The changes since the last posting (https://lwn.net/Articles/634870/) include:
* The ACL4_ and ACE4_ prefixes used for various richacl flags were renamed to RICHACL_ and RICHACE_. The flag values are still identical with NFSv4 for flags that exist in NFSv4.
* The code is now uid/gid namespace aware.
* The nfs server now uses richacls as its internal acl representation; struct nfs4_acl is gone. On the underlying file system, it uses either POSIX ACLs or richacls depending on what that file system supports.
* The nfs client now exports NFSv4 acls as richacls in the "system.richacl" attribute instead of the nfs-specific "system.nfs4_acl" attribute, just like local file systems.
Note that the richacl xattr format has changed from the previous version and is incompatible.
The git version is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git \ richacl-2015-03-27
For comparison, the previous version is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git \ richacl-2015-02-26
Things still to be done, or which I'm not entirely happy with:
* We may need to add back support for the "system.nfs4_acl" attribute on nfs mounts for backwards compatible. Is anyone actually using that attribute?
* While richacls do support Automatic Inheritance, the nfs client and server don't because they don't support the NFSv4.1 "dacl" attribute yet (see RFC 5661).
* The nfs server performs some access checking on its own before calling into the vfs which is rersponsible for the actual access checking (see where it calls inode_permission()). With the additional MAY_ flags introduced in this patch queue, the nfsd access checks may now be too restrictive in some cases; I have yet to figure out how to deal with this.
* It would make sense for CIFS to expose Windows ACLs as richacls as well. Steve maybe?
* The base_acl code is still rather ugly.
* 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.
Andreas Gruenbacher (37):
vfs: Minor documentation fix
uapi: Remove kernel internal declaration
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
vfs: Cache base_acl objects in inodes
vfs: Cache richacl in struct inode
richacl: Create-time inheritance
richacl: Check if an acl is equivalent to a file mode
richacl: Automatic Inheritance
richacl: xattr mapping functions
vfs: Add richacl permission checking
richacl: acl editing helper functions
richacl: Move everyone@ aces down the acl
richacl: Propagate everyone@ permissions to other aces
richacl: Isolate the owner and group classes
richacl: Apply the file masks to a richacl
richacl: Create richacl from mode values
richacl: Create acl with masks applied in richacl_from_mode()
nfsd: Remove dead declarations
nfsd: Keep list of acls to dispose of in compoundargs
nfsd: Use richacls as internal acl representation
nfsd: Add richacl support
nfs/sunrpc: No more encode and decode function pointer casting nfs/sunrpc: Return status code from encode functions
nfs3: Return posix acl encode errors
nfs: Remove unused xdr page offsets in getacl/setacl arguments
rpc: Allow to demand-allocate pages to encode into
nfs: Add richacl support
Aneesh Kumar K.V (2):
ext4: Add richacl support
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 | 9 + fs/Makefile | 3 + 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 | 211 ++++++ 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/lockd/clnt4xdr.c | 58 +- fs/lockd/clntxdr.c | 58 +- fs/lockd/mon.c | 26 +- fs/namei.c | 108 ++- fs/nfs/inode.c | 2 +- fs/nfs/mount_clnt.c | 24 +- fs/nfs/nfs2xdr.c | 115 ++-- fs/nfs/nfs3xdr.c | 225 ++++--- fs/nfs/nfs4proc.c | 335 +++++----- fs/nfs/nfs4xdr.c | 699 ++++++++++++++------ fs/nfs/super.c | 4 +- fs/nfs_common/Makefile | 1 + fs/nfs_common/nfs4acl.c | 41 ++ fs/nfsd/Kconfig | 1 + fs/nfsd/acl.h | 24 +- fs/nfsd/nfs4acl.c | 467 ++++++------- fs/nfsd/nfs4callback.c | 29 +- fs/nfsd/nfs4proc.c | 17 +- fs/nfsd/nfs4xdr.c | 103 +-- fs/nfsd/xdr4.h | 12 +- fs/posix_acl.c | 31 +- fs/richacl_base.c | 549 ++++++++++++++++ fs/richacl_compat.c | 835 ++++++++++++++++++++++++ fs/richacl_inode.c | 195 ++++++ fs/richacl_xattr.c | 210 ++++++ fs/xattr.c | 34 +- include/linux/fs.h | 47 +- include/linux/nfs4.h | 16 - include/linux/nfs4acl.h | 7 + include/linux/nfs_fs.h | 2 +- include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 8 +- include/linux/posix_acl.h | 12 +- include/linux/richacl.h | 330 ++++++++++ include/linux/richacl_compat.h | 40 ++ include/linux/richacl_xattr.h | 52 ++ include/linux/sunrpc/xdr.h | 5 +- include/uapi/linux/fs.h | 3 +- include/uapi/linux/nfs4.h | 7 - include/uapi/linux/xattr.h | 2 + net/sunrpc/auth.c | 7 +- net/sunrpc/auth_gss/gss_rpc_upcall.c | 4 +- net/sunrpc/auth_gss/gss_rpc_xdr.c | 11 +- net/sunrpc/auth_gss/gss_rpc_xdr.h | 8 +- net/sunrpc/clnt.c | 5 +- net/sunrpc/rpcb_clnt.c | 57 +- net/sunrpc/xdr.c | 8 + 69 files changed, 4283 insertions(+), 1059 deletions(-) create mode 100644 fs/ext4/richacl.c create mode 100644 fs/ext4/richacl.h create mode 100644 fs/nfs_common/nfs4acl.c create mode 100644 fs/richacl_base.c create mode 100644 fs/richacl_compat.c create mode 100644 fs/richacl_inode.c create mode 100644 fs/richacl_xattr.c create mode 100644 include/linux/nfs4acl.h create mode 100644 include/linux/richacl.h create mode 100644 include/linux/richacl_compat.h create mode 100644 include/linux/richacl_xattr.h
Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 1/39 vfs: Minor documentation fix
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
RFC 2/39 uapi: Remove kernel internal declaration
In reply to Andreas GruenbacherThe enum nfs4_acl_whotype is only used in nfs4d's internal nfs4 acl representation. No longer expose it to user space.
--- include/linux/nfs4.h | 7 +++++++ include/uapi/linux/nfs4.h | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-)
include/linux/nfs4.h +7 -0
@@ -16,6 +16,13 @@#include <linux/uidgid.h> #include <uapi/linux/nfs4.h> +enum nfs4_acl_whotype { +NFS4_ACL_WHO_NAMED =0 , +NFS4_ACL_WHO_OWNER , +NFS4_ACL_WHO_GROUP , +NFS4_ACL_WHO_EVERYONE , +}; +struct nfs4_ace {uint32_t type;uint32_t flag;
include/uapi/linux/nfs4.h +0 -7
@@ -162,13 +162,6 @@*/ #define NFS4_MAX_BACK_CHANNEL_OPS 2 -enum nfs4_acl_whotype { -NFS4_ACL_WHO_NAMED =0 , -NFS4_ACL_WHO_OWNER , -NFS4_ACL_WHO_GROUP , -NFS4_ACL_WHO_EVERYONE , -}; -#endif /* _UAPI_LINUX_NFS4_H */ /*
Signature · 1 line
2.1.0
RFC 3/39 vfs: Shrink struct posix_acl
In reply to Andreas GruenbacherThere 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
RFC 4/39 vfs: Add IS_ACL() and IS_RICHACL() tests
In reply to Andreas GruenbacherThe 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 · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 5/39 vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags
In reply to Andreas GruenbacherRichacls 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
@@ -454,7 +454,8 @@ static int sb_permission(struct super_block *sb, struct inode *inode, int mask)* this, letting us set arbitrary permissions for filesystem access without * changing the "normal" UIDs which are used for other things. * -* When checking for MAY_APPEND, MAY_WRITE must also be set in @mask. +* When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR, +* MAY_WRITE must also be set in @mask. */ int inode_permission (struct inode *inode,int mask) {
@@ -2447,10 +2448,11 @@ EXPORT_SYMBOL(__check_sticky);* 10. We don't allow removal of NFS sillyrenamed files; it's handled by * nfs_async_unlink(). */ -static int may_delete (struct inode *dir,struct dentry *victim,bool isdir) +static int may_delete (struct inode *dir,struct dentry *victim, +bool isdir,bool replace) {struct inode *inode = victim->d_inode; -int error; +int error, mask =MAY_WRITE |MAY_EXEC ;if (d_is_negative (victim))return -ENOENT ;
@@ -2459,7 +2461,9 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)BUG_ON (victim->d_parent->d_inode != dir);audit_inode_child (dir, victim,AUDIT_TYPE_CHILD_DELETE ); - error =inode_permission (dir,MAY_WRITE |MAY_EXEC ); +if (replace) + mask |= isdir ?MAY_CREATE_DIR :MAY_CREATE_FILE ; + error =inode_permission (dir, mask);if (error)return error;if (IS_APPEND (dir))
@@ -2490,14 +2494,16 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)* 3. We should have write and exec permissions on dir * 4. We can't do it if dir is immutable (done in permission()) */ -static inline int may_create (struct inode *dir,struct dentry *child) +static inline int may_create (struct inode *dir,struct dentry *child,bool isdir) { +int mask = isdir ?MAY_CREATE_DIR :MAY_CREATE_FILE ; +audit_inode_child (dir, child,AUDIT_TYPE_CHILD_CREATE );if (child->d_inode)return -EEXIST ;if (IS_DEADDIR (dir))return -ENOENT ; -return inode_permission (dir,MAY_WRITE |MAY_EXEC ); +return inode_permission (dir,MAY_WRITE |MAY_EXEC | mask); }/*
@@ -2547,7 +2553,7 @@ EXPORT_SYMBOL(unlock_rename);int vfs_create (struct inode *dir,struct dentry *dentry,umode_t mode,bool want_excl) { -int error =may_create (dir, dentry); +int error =may_create (dir, dentry, false);if (error)return error;
@@ -3422,7 +3428,7 @@ EXPORT_SYMBOL(user_path_create);int vfs_mknod (struct inode *dir,struct dentry *dentry,umode_t mode,dev_t dev) { -int error =may_create (dir, dentry); +int error =may_create (dir, dentry, false);if (error)return error;
@@ -3514,7 +3520,7 @@ SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, dint vfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) { -int error =may_create (dir, dentry); +int error =may_create (dir, dentry, true);unsigned max_links = dir->i_sb->s_max_links;if (error)
@@ -3595,7 +3601,7 @@ EXPORT_SYMBOL(dentry_unhash);int vfs_rmdir (struct inode *dir,struct dentry *dentry) { -int error =may_delete (dir, dentry,1 ); +int error =may_delete (dir, dentry, true, false);if (error)return error;
@@ -3715,7 +3721,7 @@ SYSCALL_DEFINE1(rmdir, const char __user *, pathname)int vfs_unlink (struct inode *dir,struct dentry *dentry,struct inode **delegated_inode) {struct inode *target = dentry->d_inode; -int error =may_delete (dir, dentry,0 ); +int error =may_delete (dir, dentry, false, false);if (error)return error;
@@ -3847,7 +3853,7 @@ SYSCALL_DEFINE1(unlink, const char __user *, pathname)int vfs_symlink (struct inode *dir,struct dentry *dentry,const char *oldname) { -int error =may_create (dir, dentry); +int error =may_create (dir, dentry, false);if (error)return error;
@@ -3930,7 +3936,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_deif (!inode)return -ENOENT ; - error =may_create (dir, new_dentry); + error =may_create (dir, new_dentry, false);if (error)return error;
@@ -4118,19 +4124,19 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,if (source == target)return 0 ; - error =may_delete (old_dir, old_dentry, is_dir); + error =may_delete (old_dir, old_dentry, is_dir, false);if (error)return error;if (!target) { - error =may_create (new_dir, new_dentry); + error =may_create (new_dir, new_dentry, is_dir); }else { new_is_dir =d_is_dir (new_dentry);if (!(flags &RENAME_EXCHANGE )) - error =may_delete (new_dir, new_dentry, is_dir); + error =may_delete (new_dir, new_dentry, is_dir, true);else - error =may_delete (new_dir, new_dentry, new_is_dir); + error =may_delete (new_dir, new_dentry, new_is_dir, true); }if (error)return error;
@@ -4394,7 +4400,7 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newnaint vfs_whiteout (struct inode *dir,struct dentry *dentry) { -int error =may_create (dir, dentry); +int error =may_create (dir, dentry, false);if (error)return error;
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
RFC 8/39 vfs: Add permission flags for setting file attributes
In reply to Andreas GruenbacherRichacls 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
@@ -17,6 +17,65 @@#include <linux/ima.h> /** +* inode_extended_permission - permissions beyond read/write/execute +* +* Check for permissions that only richacls can currently grant. +*/ +static int inode_extended_permission (struct inode *inode,int mask) +{ +if (!IS_RICHACL (inode)) +return -EPERM ; +return inode_permission (inode, mask); +} + +static bool inode_uid_change_ok (struct inode *inode,kuid_t ia_uid) +{ +if (uid_eq (current_fsuid (), inode->i_uid) && +uid_eq (ia_uid, inode->i_uid)) +return true; +if (uid_eq (current_fsuid (), ia_uid) && +inode_extended_permission (inode,MAY_TAKE_OWNERSHIP ) ==0 ) +return true; +if (capable_wrt_inode_uidgid (inode,CAP_CHOWN )) +return true; +return false; +} + +static bool inode_gid_change_ok (struct inode *inode,kgid_t ia_gid) +{ +int in_group =in_group_p (ia_gid); +if (uid_eq (current_fsuid (), inode->i_uid) && + (in_group ||gid_eq (ia_gid, inode->i_gid))) +return true; +if (in_group &&inode_extended_permission (inode,MAY_TAKE_OWNERSHIP ) ==0 ) +return true; +if (capable_wrt_inode_uidgid (inode,CAP_CHOWN )) +return true; +return false; +} + +/** +* inode_owner_permitted_or_capable +* +* Check for permissions implicitly granted to the owner, like MAY_CHMOD or +* MAY_SET_TIMES. Equivalent to inode_owner_or_capable for file systems +* without support for those permissions. +*/ +static bool inode_owner_permitted_or_capable (struct inode *inode,int mask) +{ +struct user_namespace *ns; + +if (uid_eq (current_fsuid (), inode->i_uid)) +return true; +if (inode_extended_permission (inode, mask) ==0 ) +return true; + ns =current_user_ns (); +if (ns_capable (ns,CAP_FOWNER ) &&kuid_has_mapping (ns, inode->i_uid)) +return true; +return false; +} + +/** * inode_change_ok - check if attribute changes to an inode are allowed * @inode: inode to check * @attr: attributes to change
@@ -47,22 +106,18 @@ int inode_change_ok(struct inode *inode, struct iattr *attr)return 0 ;/* Make sure a caller can chown. */ -if ((ia_valid &ATTR_UID ) && - (!uid_eq (current_fsuid (), inode->i_uid) || - !uid_eq (attr->ia_uid, inode->i_uid)) && - !capable_wrt_inode_uidgid (inode,CAP_CHOWN )) -return -EPERM ; +if (ia_valid &ATTR_UID ) +if (!inode_uid_change_ok (inode, attr->ia_uid)) +return -EPERM ;/* Make sure caller can chgrp. */ -if ((ia_valid &ATTR_GID ) && - (!uid_eq (current_fsuid (), inode->i_uid) || - (!in_group_p (attr->ia_gid) && !gid_eq (attr->ia_gid, inode->i_gid))) && - !capable_wrt_inode_uidgid (inode,CAP_CHOWN )) -return -EPERM ; +if (ia_valid &ATTR_GID ) +if (!inode_gid_change_ok (inode, attr->ia_gid)) +return -EPERM ;/* Make sure a caller can chmod. */ if (ia_valid & ATTR_MODE) { - if (!inode_owner_or_capable(inode)) + if (!inode_owner_permitted_or_capable(inode, MAY_CHMOD)) return -EPERM; /* Also check the setgid bit! */ if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
@@ -73,7 +128,7 @@ int inode_change_ok(struct inode *inode, struct iattr *attr)/* Check for setting the inode time. */ if (ia_valid & (ATTR_MTIME_SET |ATTR_ATIME_SET |ATTR_TIMES_SET )) { -if (!inode_owner_or_capable (inode)) +if (!inode_owner_permitted_or_capable (inode,MAY_SET_TIMES ))return -EPERM ; }
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
RFC 9/39 richacl: In-memory representation and helper functions
In reply to Andreas GruenbacherA 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 | 58 ++++++++++++ include/linux/richacl.h | 246 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 306 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 +58 -0
58 lines not on this page · raw message
include/linux/richacl.h new file +246 -0
246 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC 10/39 richacl: Permission mapping functions
In reply to Andreas GruenbacherWe 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
@@ -56,3 +56,120 @@ richacl_clone(const struct richacl *acl, gfp_t gfp) }return dup; } + +/** +* richacl_mask_to_mode - compute the file permission bits which correspond to @mask +* @mask: %RICHACE_* permission mask +* +* See richacl_masks_to_mode(). +*/ +static int +richacl_mask_to_mode (unsigned int mask) +{ +int mode =0 ; + +if (mask &RICHACE_POSIX_MODE_READ ) + mode |=S_IROTH ; +if (mask &RICHACE_POSIX_MODE_WRITE ) + mode |=S_IWOTH ; +if (mask &RICHACE_POSIX_MODE_EXEC ) + mode |=S_IXOTH ; + +return mode; +} + +/** +* richacl_masks_to_mode - compute the file permission bits from the file masks +* +* When setting a richacl, we set the file permission bits to indicate maximum +* permissions: for example, we set the Write permission when a mask contains +* RICHACE_APPEND_DATA even if it does not also contain RICHACE_WRITE_DATA. +* +* Permissions which are not in RICHACE_POSIX_MODE_READ, RICHACE_POSIX_MODE_WRITE, or +* RICHACE_POSIX_MODE_EXEC cannot be represented in the file permission bits. +* Such permissions can still be effective, but not for new files or after a +* chmod(), and only if they were set explicitly, for example, by setting a +* richacl. +*/ +int +richacl_masks_to_mode (const struct richacl *acl) +{ +return richacl_mask_to_mode (acl->a_owner_mask) <<6 | +richacl_mask_to_mode (acl->a_group_mask) <<3 | +richacl_mask_to_mode (acl->a_other_mask); +} +EXPORT_SYMBOL_GPL (richacl_masks_to_mode); + +/** +* richacl_mode_to_mask - compute a file mask from the lowest three mode bits +* +* When the file permission bits of a file are set with chmod(), this specifies +* the maximum permissions that processes will get. All permissions beyond +* that will be removed from the file masks, and become ineffective. +* +* We also add in the permissions which are always allowed no matter what the +* acl says. +*/ +unsigned int +richacl_mode_to_mask (mode_t mode) +{ +unsigned int mask =RICHACE_POSIX_ALWAYS_ALLOWED ; + +if (mode &S_IROTH ) + mask |=RICHACE_POSIX_MODE_READ ; +if (mode &S_IWOTH ) + mask |=RICHACE_POSIX_MODE_WRITE ; +if (mode &S_IXOTH ) + mask |=RICHACE_POSIX_MODE_EXEC ; + +return mask; +} + +/** +* richacl_want_to_mask - convert the iop->permission want argument to a mask +* @want: @want argument of the permission inode operation +* +* When checking for append, @want is (MAY_WRITE | MAY_APPEND). +* +* Richacls use the iop->may_create and iop->may_delete hooks which are +* used for checking if creating and deleting files is allowed. These hooks do +* not use richacl_want_to_mask(), so we do not have to deal with mapping +* MAY_WRITE to RICHACE_ADD_FILE, RICHACE_ADD_SUBDIRECTORY, and RICHACE_DELETE_CHILD +* here. +*/ +unsigned int +richacl_want_to_mask (unsigned int want) +{ +unsigned int mask =0 ; + +if (want &MAY_READ ) + mask |=RICHACE_READ_DATA ; +if (want &MAY_DELETE_SELF ) + mask |=RICHACE_DELETE ; +if (want &MAY_TAKE_OWNERSHIP ) + mask |=RICHACE_WRITE_OWNER ; +if (want &MAY_CHMOD ) + mask |=RICHACE_WRITE_ACL ; +if (want &MAY_SET_TIMES ) + mask |=RICHACE_WRITE_ATTRIBUTES ; +if (want &MAY_EXEC ) + mask |=RICHACE_EXECUTE ; +/* +* differentiate MAY_WRITE from these request +*/ +if (want & (MAY_APPEND | +MAY_CREATE_FILE |MAY_CREATE_DIR | +MAY_DELETE_CHILD )) { +if (want &MAY_APPEND ) + mask |=RICHACE_APPEND_DATA ; +if (want &MAY_CREATE_FILE ) + mask |=RICHACE_ADD_FILE ; +if (want &MAY_CREATE_DIR ) + mask |=RICHACE_ADD_SUBDIRECTORY ; +if (want &MAY_DELETE_CHILD ) + mask |=RICHACE_DELETE_CHILD ; + }else if (want &MAY_WRITE ) + mask |=RICHACE_WRITE_DATA ; +return mask; +} +EXPORT_SYMBOL_GPL (richacl_want_to_mask);
include/linux/richacl.h +46 -0
57 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC 11/39 richacl: Compute maximum file masks from an acl
In reply to Andreas GruenbacherCompute 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
@@ -173,3 +173,131 @@ richacl_want_to_mask(unsigned int want)return mask; }EXPORT_SYMBOL_GPL (richacl_want_to_mask); + +/** +* richacl_allowed_to_who - mask flags allowed to a specific who value +* +* Computes the mask values allowed to a specific who value, taking +* EVERYONE@ entries into account. +*/ +static unsigned int richacl_allowed_to_who (struct richacl *acl, +struct richace *who) +{ +struct richace *ace; +unsigned int allowed =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_same_identifier (ace, who) || +richace_is_everyone (ace)) { +if (richace_is_allow (ace)) + allowed |= ace->e_mask; +else if (richace_is_deny (ace)) + allowed &= ~ace->e_mask; + } + } +return allowed; +} + +/** +* richacl_group_class_allowed - maximum permissions the group class is allowed +* +* See richacl_compute_max_masks(). +*/ +static unsigned int richacl_group_class_allowed (struct richacl *acl) +{ +struct richace *ace; +unsigned int everyone_allowed =0 , group_class_allowed =0 ; +int had_group_ace =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace) || +richace_is_owner (ace)) +continue ; + +if (richace_is_everyone (ace)) { +if (richace_is_allow (ace)) + everyone_allowed |= ace->e_mask; +else if (richace_is_deny (ace)) + everyone_allowed &= ~ace->e_mask; + }else { + group_class_allowed |= +richacl_allowed_to_who (acl, ace); + +if (richace_is_group (ace)) + had_group_ace =1 ; + } + } +if (!had_group_ace) + group_class_allowed |= everyone_allowed; +return group_class_allowed; +} + +/** +* richacl_compute_max_masks - compute upper bound masks +* +* Computes upper bound owner, group, and other masks so that none of +* the mask flags allowed by the acl are disabled (for any choice of the +* file owner or group membership). +*/ +void richacl_compute_max_masks (struct richacl *acl) +{ +unsigned int gmask = ~0 ; +struct richace *ace; + +/* +* @gmask contains all permissions which the group class is ever +* allowed. We use it to avoid adding permissions to the group mask +* from everyone@ allow aces which the group class is always denied +* through other aces. For example, the following acl would otherwise +* result in a group mask or rw: +* +* group@:w::deny +* everyone@:rw::allow +* +* Avoid computing @gmask for acls which do not include any group class +* deny aces: in such acls, the group class is never denied any +* permissions from everyone@ allow aces. +*/ + +restart: + acl->a_owner_mask =0 ; + acl->a_group_mask =0 ; + acl->a_other_mask =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; + +if (richace_is_owner (ace)) { +if (richace_is_allow (ace)) + acl->a_owner_mask |= ace->e_mask; +else if (richace_is_deny (ace)) + acl->a_owner_mask &= ~ace->e_mask; + }else if (richace_is_everyone (ace)) { +if (richace_is_allow (ace)) { + acl->a_owner_mask |= ace->e_mask; + acl->a_group_mask |= ace->e_mask & gmask; + acl->a_other_mask |= ace->e_mask; + }else if (richace_is_deny (ace)) { + acl->a_owner_mask &= ~ace->e_mask; + acl->a_group_mask &= ~ace->e_mask; + acl->a_other_mask &= ~ace->e_mask; + } + }else { +if (richace_is_allow (ace)) { + acl->a_owner_mask |= ace->e_mask & gmask; + acl->a_group_mask |= ace->e_mask & gmask; + }else if (richace_is_deny (ace) && gmask == ~0 ) { + gmask =richacl_group_class_allowed (acl); +if (likely (gmask != ~0 )) +/* should always be true */ + goto restart; + } + } + } + + acl->a_flags &= ~RICHACL_MASKED ; +} +EXPORT_SYMBOL_GPL (richacl_compute_max_masks);
include/linux/richacl.h +1 -0
@@ -288,5 +288,6 @@ extern struct richacl *richacl_alloc(int, gfp_t);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
RFC 13/39 richacl: Permission check algorithm
In reply to Andreas GruenbacherA 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/Makefile | 2 +- fs/richacl_inode.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 3 ++ 3 files changed, 134 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_inode.c new file +130 -0
130 lines not on this page · raw message
include/linux/richacl.h +3 -0
@@ -291,4 +291,7 @@ 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 ); +/* richacl_inode.c */ +extern int richacl_permission (struct inode *,const struct richacl *,int ); +#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
RFC 15/39 vfs: Cache richacl in struct inode
In reply to Andreas GruenbacherCache 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
@@ -33,7 +33,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;
@@ -167,8 +167,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; }
@@ -178,10 +177,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 *); +/** * richace_is_owner - check if @ace is an OWNER@ entry */
Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 16/39 richacl: Create-time inheritance
In reply to Andreas GruenbacherWhen 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/richacl_base.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/richacl_inode.c | 60 ++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 2 ++ 3 files changed, 131 insertions(+)
fs/richacl_base.c +69 -0
@@ -416,3 +416,72 @@ richacl_chmod(struct richacl *acl, mode_t mode)return clone; }EXPORT_SYMBOL_GPL (richacl_chmod); + +/** +* richacl_inherit - compute the inherited acl of a new file +* @dir_acl: acl of the containing directory +* @isdir: inherit by a directory or non-directory? +* +* A directory can have acl entries which files and/or directories created +* inside the directory will inherit. This function computes the acl for such +* a new file. If there is no inheritable acl, it will return %NULL. +*/ +struct richacl * +richacl_inherit (const struct richacl *dir_acl,int isdir) +{ +const struct richace *dir_ace; +struct richacl *acl =NULL ; +struct richace *ace; +int count =0 ; + +if (isdir) { +richacl_for_each_entry (dir_ace, dir_acl) { +if (!richace_is_inheritable (dir_ace)) +continue ; + count++; + } +if (!count) +return NULL ; + acl =richacl_alloc (count,GFP_KERNEL ); +if (!acl) +return ERR_PTR (-ENOMEM ); + ace = acl->a_entries; +richacl_for_each_entry (dir_ace, dir_acl) { +if (!richace_is_inheritable (dir_ace)) +continue ; +memcpy (ace, dir_ace,sizeof (struct richace )); +if (dir_ace->e_flags &RICHACE_NO_PROPAGATE_INHERIT_ACE ) +richace_clear_inheritance_flags (ace); +if ((dir_ace->e_flags &RICHACE_FILE_INHERIT_ACE ) && + !(dir_ace->e_flags &RICHACE_DIRECTORY_INHERIT_ACE )) + ace->e_flags |=RICHACE_INHERIT_ONLY_ACE ; + ace++; + } + }else { +richacl_for_each_entry (dir_ace, dir_acl) { +if (!(dir_ace->e_flags &RICHACE_FILE_INHERIT_ACE )) +continue ; + count++; + } +if (!count) +return NULL ; + acl =richacl_alloc (count,GFP_KERNEL ); +if (!acl) +return ERR_PTR (-ENOMEM ); + ace = acl->a_entries; +richacl_for_each_entry (dir_ace, dir_acl) { +if (!(dir_ace->e_flags &RICHACE_FILE_INHERIT_ACE )) +continue ; +memcpy (ace, dir_ace,sizeof (struct richace )); +richace_clear_inheritance_flags (ace); +/* +* RICHACE_DELETE_CHILD is meaningless for +* non-directories, so clear it. +*/ + ace->e_mask &= ~RICHACE_DELETE_CHILD ; + ace++; + } + } + +return acl; +}
fs/richacl_inode.c +60 -0
63 lines not on this page · raw message
include/linux/richacl.h +2 -0
@@ -295,8 +295,10 @@ 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 struct richacl *richacl_inherit (const struct richacl *,int );/* richacl_inode.c */ extern int richacl_permission (struct inode *,const struct richacl *,int ); +extern struct richacl *richacl_create (struct inode *,struct inode *);#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
RFC 17/39 richacl: Check if an acl is equivalent to a file mode
In reply to Andreas GruenbacherThis 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
@@ -485,3 +485,57 @@ richacl_inherit(const struct richacl *dir_acl, int isdir)return acl; } + +/** +* richacl_equiv_mode - check if @acl is equivalent to file permission bits +* @mode_p: the file mode (including the file type) +* +* If @acl can be fully represented by file permission bits, this function +* returns 0, and the file permission bits in @mode_p are set to the equivalent +* of @acl. +* +* This function is used to avoid storing richacls on disk if the acl can be +* computed from the file permission bits. It allows user-space to make sure +* that a file has no explicit richacl set. +*/ +int +richacl_equiv_mode (const struct richacl *acl,mode_t *mode_p) +{ +const struct richace *ace = acl->a_entries; +unsigned int x; +mode_t mode; + +if (acl->a_count !=1 || + acl->a_flags !=RICHACL_MASKED || + !richace_is_everyone (ace) || + !richace_is_allow (ace) || + ace->e_flags & ~RICHACE_SPECIAL_WHO ) +return -1 ; + +/* +* Figure out the permissions we care about: RICHACE_DELETE_CHILD is +* meaningless for non-directories, so we ignore it. +*/ + x = ~RICHACE_POSIX_ALWAYS_ALLOWED ; +if (!S_ISDIR (*mode_p)) + x &= ~RICHACE_DELETE_CHILD ; + + mode =richacl_masks_to_mode (acl); +if ((acl->a_group_mask & x) != (richacl_mode_to_mask (mode >>3 ) & x) || + (acl->a_other_mask & x) != (richacl_mode_to_mask (mode) & x)) +return -1 ; + +/* +* Ignore permissions which the owner is always allowed. +*/ + x &= ~RICHACE_POSIX_OWNER_ALLOWED ; +if ((acl->a_owner_mask & x) != (richacl_mode_to_mask (mode >>6 ) & x)) +return -1 ; + +if ((ace->e_mask & x) != (RICHACE_POSIX_MODE_ALL & x)) +return -1 ; + + *mode_p = (*mode_p & ~S_IRWXUGO ) | mode; +return 0 ; +} +EXPORT_SYMBOL_GPL (richacl_equiv_mode);
include/linux/richacl.h +1 -0
@@ -296,6 +296,7 @@ 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 struct richacl *richacl_inherit (const struct richacl *,int ); +extern int richacl_equiv_mode (const struct richacl *,mode_t *);/* richacl_inode.c */ extern int richacl_permission (struct inode *,const struct richacl *,int );
Signature · 1 line
2.1.0
RFC 18/39 richacl: Automatic Inheritance
In reply to Andreas GruenbacherAutomatic 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 | 25 +++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-)
fs/richacl_base.c +9 -1
@@ -400,7 +400,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 &RICHACL_MASKED )) + (acl->a_flags &RICHACL_MASKED ) && + (!richacl_is_auto_inherit (acl) ||richacl_is_protected (acl)))return acl; clone =richacl_clone (acl,GFP_KERNEL );
@@ -412,6 +413,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 |=RICHACL_PROTECTED ;return clone; }
@@ -482,6 +485,11 @@ richacl_inherit(const struct richacl *dir_acl, int isdir) ace++; } } +if (richacl_is_auto_inherit (dir_acl)) { + acl->a_flags =RICHACL_AUTO_INHERIT ; +richacl_for_each_entry (ace, acl) + ace->e_flags |=RICHACE_INHERITED_ACE ; + }return acl; }
fs/richacl_inode.c +6 -1
@@ -150,9 +150,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 RICHACL_PROTECTED because we are +* doing an implicit chmod +*/ +if (richacl_is_auto_inherit (acl)) + acl->a_flags |=RICHACL_PROTECTED ;richacl_compute_max_masks (acl); -/* * Ensure that the acl will not grant any permissions beyond * the create mode.
include/linux/richacl.h +23 -2
@@ -53,9 +53,15 @@ struct richacl { _ace--)/* a_flag values */ +#define RICHACL_AUTO_INHERIT 0x01 +#define RICHACL_PROTECTED 0x02 +#define RICHACL_DEFAULTED 0x04#define RICHACL_MASKED 0x80 -#define RICHACL_VALID_FLAGS ( \ +#define RICHACL_VALID_FLAGS ( \ + RICHACL_AUTO_INHERIT | \ + RICHACL_PROTECTED | \ + RICHACL_DEFAULTED | \ RICHACL_MASKED)/* e_type values */
@@ -68,6 +74,7 @@ struct richacl {#define RICHACE_NO_PROPAGATE_INHERIT_ACE 0x0004#define RICHACE_INHERIT_ONLY_ACE 0x0008#define RICHACE_IDENTIFIER_GROUP 0x0040 +#define RICHACE_INHERITED_ACE 0x0080#define RICHACE_SPECIAL_WHO 0x4000#define RICHACE_VALID_FLAGS ( \
@@ -76,6 +83,7 @@ struct richacl {RICHACE_NO_PROPAGATE_INHERIT_ACE | \RICHACE_INHERIT_ONLY_ACE | \RICHACE_IDENTIFIER_GROUP | \ +RICHACE_INHERITED_ACE | \ RICHACE_SPECIAL_WHO)/* e_mask bitflags */
@@ -187,6 +195,18 @@ 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) +{ +return acl->a_flags &RICHACL_AUTO_INHERIT ; +} + +static inline int +richacl_is_protected (const struct richacl *acl) +{ +return acl->a_flags &RICHACL_PROTECTED ; +} +/** * richace_is_owner - check if @ace is an OWNER@ entry */
@@ -257,7 +277,8 @@ richace_clear_inheritance_flags(struct richace *ace) ace->e_flags &= ~(RICHACE_FILE_INHERIT_ACE |RICHACE_DIRECTORY_INHERIT_ACE |RICHACE_NO_PROPAGATE_INHERIT_ACE | -RICHACE_INHERIT_ONLY_ACE ); +RICHACE_INHERIT_ONLY_ACE | +RICHACE_INHERITED_ACE ); }/**
Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 19/39 richacl: xattr mapping functions
In reply to Andreas GruenbacherMap between "system.richacl" xattrs and the in-kernel representation.
--- fs/Makefile | 2 +- fs/richacl_xattr.c | 210 ++++++++++++++++++++++++++++++++++++++++++ fs/xattr.c | 34 +++++-- include/linux/richacl_xattr.h | 52 +++++++++++ include/uapi/linux/xattr.h | 2 + 5 files changed, 293 insertions(+), 7 deletions(-) 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 +210 -0
210 lines not on this page · raw message
fs/xattr.c +28 -6
@@ -21,6 +21,7 @@#include <linux/audit.h> #include <linux/vmalloc.h> #include <linux/posix_acl_xattr.h> +#include <linux/richacl_xattr.h> #include <asm/uaccess.h>
@@ -314,6 +315,18 @@ vfs_removexattr(struct dentry *dentry, const char *name) }EXPORT_SYMBOL_GPL (vfs_removexattr); +static void +fix_xattr_from_user (const char *kname,void *kvalue,size_t size) +{ +if (strncmp (kname,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN )) +return ; + kname +=XATTR_SYSTEM_PREFIX_LEN ; +if (!strcmp (kname,XATTR_POSIX_ACL_ACCESS ) || + !strcmp (kname,XATTR_POSIX_ACL_DEFAULT )) +posix_acl_fix_xattr_from_user (kvalue, size); +else if (!strcmp (kname,XATTR_RICHACL )) +richacl_fix_xattr_from_user (kvalue, size); +}/* * Extended attribute SET operations
@@ -350,9 +363,7 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, error = -EFAULT ; goto out; } -if ((strcmp (kname,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) || - (strcmp (kname,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 )) -posix_acl_fix_xattr_from_user (kvalue, size); +fix_xattr_from_user (kname, kvalue, size); } error =vfs_setxattr (d, kname, kvalue, size, flags);
@@ -419,6 +430,19 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,return error; } +static void +fix_xattr_to_user (const char *kname,void *kvalue,size_t size) +{ +if (strncmp (kname,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN )) +return ; + kname +=XATTR_SYSTEM_PREFIX_LEN ; +if (!strcmp (kname,XATTR_POSIX_ACL_ACCESS ) || + !strcmp (kname,XATTR_POSIX_ACL_DEFAULT )) +posix_acl_fix_xattr_to_user (kvalue, size); +else if (!strcmp (kname,XATTR_RICHACL )) +richacl_fix_xattr_to_user (kvalue, size); +} +/* * Extended attribute GET operations */
@@ -451,9 +475,7 @@ getxattr(struct dentry *d, const char __user *name, void __user *value, error =vfs_getxattr (d, kname, kvalue, size);if (error >0 ) { -if ((strcmp (kname,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) || - (strcmp (kname,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 )) -posix_acl_fix_xattr_to_user (kvalue, size); +fix_xattr_to_user (kname, kvalue, size);if (size &©_to_user (value, kvalue, error)) error = -EFAULT ; }else if (error == -ERANGE && size >=XATTR_SIZE_MAX ) {
include/linux/richacl_xattr.h new file +52 -0
52 lines not on this page · raw message
include/uapi/linux/xattr.h +2 -0
@@ -73,5 +73,7 @@#define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"#define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT +#define XATTR_RICHACL "richacl" +#define XATTR_NAME_RICHACL XATTR_SYSTEM_PREFIX XATTR_RICHACL#endif /* _UAPI_LINUX_XATTR_H */
Signature · 1 line
2.1.0
RFC 22/39 ext4: Add richacl feature flag
In reply to Andreas GruenbacherFrom: "Aneesh Kumar K.V" <[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 · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 23/39 richacl: acl editing helper functions
In reply to Andreas GruenbacherThe file masks in richacls make chmod and creating new files more efficient than having to apply file permission bits to the acl directly. They also allow us to regain permissions from an acl even after a restrictive chmod, because the permissions in the acl itself are not being destroyed. In POSIX ACLs, the mask entry has a similar function.
Protocols like nfsv4 do not understand file masks. For those protocols, we need to compute nfs4 acls which represent the effective permissions granted by a richacl: we need to "apply" the file masks to the acl.
This is the first in a series of richacl transformation patches; it implements basic richacl editing functions. The following patches implement algorithms for transforming a richacl so that it can be evaluated as a plain nfs4 acl, with identical permission check results.
--- fs/Makefile | 3 +- fs/richacl_compat.c | 161 +++++++++++++++++++++++++++++++++++++++++ include/linux/richacl_compat.h | 40 ++++++++++ 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 fs/richacl_compat.c create mode 100644 include/linux/richacl_compat.h
fs/Makefile +2 -1
@@ -48,7 +48,8 @@ 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_xattr.o +richacl-y := richacl_base.o richacl_inode.o \ + richacl_xattr.o richacl_compat.o obj-y += quota/
fs/richacl_compat.c new file +161 -0
161 lines not on this page · raw message
include/linux/richacl_compat.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2015 Red Hat, Inc. +* Written by Andreas Gruenbacher <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2, or (at your option) any +* later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __RICHACL_COMPAT_H +#define __RICHACL_COMPAT_H + +#include <linux/richacl.h> + +/** +* struct richacl_alloc - remember how many entries are actually allocated +* @acl: acl with a_count <= @count +* @count: the actual number of entries allocated in @acl +* +* We pass around this structure while modifying an acl so that we do +* not have to reallocate when we remove existing entries followed by +* adding new entries. +*/ +struct richacl_alloc { +struct richacl *acl; +unsigned int count; +}; + +struct richacl *richacl_prepare (struct richacl_alloc *,unsigned int ); +struct richace *richacl_append_entry (struct richacl_alloc *); +int richacl_insert_entry (struct richacl_alloc *,struct richace **); +void richacl_delete_entry (struct richacl_alloc *,struct richace **); + +#endif /* __RICHACL_COMPAT_H */
Signature · 1 line
2.1.0
RFC 24/39 richacl: Move everyone@ aces down the acl
In reply to Andreas GruenbacherThe POSIX standard puts processes which are not the owner or a member in the owning group or which match any ace other then everyone@ on the other file class. We only know if a process is in the other class after processing the entire acl.
Move all everyone@ aces in the acl down in the acl so that at most a single everyone@ allow ace remains at the end. Permissions which are not explicitly allowed are implicitly denied, so everyone@ deny ace is needed.
The everyone@ aces can be moved down the acl without changing the permissions that the acl grants. This transformation simplifies the following algorithms, and eventually allows us to turn the final everyone@ allow ace into an entry for the other class.
--- fs/richacl_compat.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
fs/richacl_compat.c +65 -0
@@ -159,3 +159,68 @@ richace_change_mask(struct richacl_alloc *x, struct richace **ace, }return 0 ; } + +/** +* richacl_move_everyone_aces_down - move everyone@ aces to the end of the acl +* @x: acl and number of allocated entries +* +* Move all everyone aces to the end of the acl so that only a single everyone@ +* allow ace remains at the end, and update the mask fields of all aces on the +* way. The last ace of the resulting acl will be an everyone@ allow ace only +* if @acl grants any permissions to @everyone. No @everyone deny aces will +* remain. +* +* This transformation does not alter the permissions that the acl grants. +* Having at most one everyone@ allow ace at the end of the acl helps us in the +* following algorithms. +*/ +static int +richacl_move_everyone_aces_down (struct richacl_alloc *x) +{ +struct richace *ace; +unsigned int allowed =0 , denied =0 ; + +richacl_for_each_entry (ace, x->acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_everyone (ace)) { +if (richace_is_allow (ace)) + allowed |= (ace->e_mask & ~denied); +else if (richace_is_deny (ace)) + denied |= (ace->e_mask & ~allowed); +else +continue ; +if (richace_change_mask (x, &ace,0 )) +return -1 ; + }else { +if (richace_is_allow (ace)) { +if (richace_change_mask (x, &ace, allowed | + (ace->e_mask & ~denied))) +return -1 ; + }else if (richace_is_deny (ace)) { +if (richace_change_mask (x, &ace, denied | + (ace->e_mask & ~allowed))) +return -1 ; + } + } + } +if (allowed & ~RICHACE_POSIX_ALWAYS_ALLOWED ) { +struct richace *last_ace = ace -1 ; + +if (x->acl->a_entries && +richace_is_everyone (last_ace) && +richace_is_allow (last_ace) && +richace_is_inherit_only (last_ace) && + last_ace->e_mask == allowed) + last_ace->e_flags &= ~RICHACE_INHERIT_ONLY_ACE ; +else { +if (richacl_insert_entry (x, &ace)) +return -1 ; + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = allowed; + ace->e_id.special =RICHACE_EVERYONE_SPECIAL_ID ; + } + } +return 0 ; +}
Signature · 1 line
2.1.0
RFC 25/39 richacl: Propagate everyone@ permissions to other aces
In reply to Andreas GruenbacherThe trailing everyone@ allow ace can grant permissions to all file classes including the owner and group class. Before we can apply the other mask to this entry to turn it into an "other class" entry, we need to ensure that members of the owner or group class will not lose any permissions from that ace.
Conceptually, we do this by inserting additional <who>:<allow>::allow entries before the trailing everyone@ allow ace with the same permissions as the trailing everyone@ allow ace for owner@, group@, and all explicitly mentioned users and groups. (In practice, we will rarely need to insert any additional aces in this step.)
--- fs/richacl_compat.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+)
fs/richacl_compat.c +189 -0
@@ -224,3 +224,192 @@ richacl_move_everyone_aces_down(struct richacl_alloc *x) }return 0 ; } + +/** +* __richacl_propagate_everyone - propagate everyone@ permissions up for @who +* @x: acl and number of allocated entries +* @who: identifier to propagate permissions for +* @allow: permissions to propagate up +* +* Propagate the permissions in @allow up from the end of the acl to the start +* for the specified principal @who. +* +* The simplest possible approach to achieve this would be to insert a +* "<who>:<allow>::allow" ace before the final everyone@ allow ace. Since this +* would often result in aces which are not needed or which could be merged +* with an existing ace, we make the following optimizations: +* +* - We go through the acl and determine which permissions are already +* allowed or denied to @who, and we remove those permissions from +* @allow. +* +* - If the acl contains an allow ace for @who and no aces after this entry +* deny permissions in @allow, we add the permissions in @allow to this +* ace. (Propagating permissions across a deny ace which can match the +* process can elevate permissions.) +* +* This transformation does not alter the permissions that the acl grants. +*/ +static int +__richacl_propagate_everyone (struct richacl_alloc *x,struct richace *who, +unsigned int allow) +{ +struct richace *allow_last =NULL , *ace; + +/* +* Remove the permissions from allow that are already determined for +* this who value, and figure out if there is an allow entry for +* this who value that is "reachable" from the trailing everyone@ +* allow ace. +*/ +richacl_for_each_entry (ace, x->acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_allow (ace)) { +if (richace_is_same_identifier (ace, who)) { + allow &= ~ace->e_mask; + allow_last = ace; + } + }else if (richace_is_deny (ace)) { +if (richace_is_same_identifier (ace, who)) + allow &= ~ace->e_mask; +else if (allow & ace->e_mask) + allow_last =NULL ; + } + } +if (allow) { +if (allow_last) +return richace_change_mask (x, &allow_last, + allow_last->e_mask | allow); +else { +struct richace who_copy; + + ace = x->acl->a_entries + x->acl->a_count -1 ; +memcpy (&who_copy, who,sizeof (struct richace )); +if (richacl_insert_entry (x, &ace)) +return -1 ; +memcpy (ace, &who_copy,sizeof (struct richace )); + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; +richace_clear_inheritance_flags (ace); + ace->e_mask = allow; + } + } +return 0 ; +} + +/** +* richacl_propagate_everyone - propagate everyone@ permissions up the acl +* @x: acl and number of allocated entries +* +* Make sure that owner@, group@, and all other users and groups mentioned in +* the acl will not lose any permissions when finally applying the other mask +* to the everyone@ allow ace at the end of the acl. If one of those +* principals is not granted some of those permissions, insert an additional +* allow ace for that principal into the acl before the final everyone@ allow +* ace. +* +* For example, the following acl implicitly grants everyone rwx access: +* +* joe:r::allow +* everyone@:rwx::allow +* +* When applying mode 0660 to this acl, owner@ and group@ would lose rw access, +* and joe would lose w access even though the mode does not exclude those +* permissions. To fix this problem, we insert additional allow aces into the +* acl. The result after applying mode 0660 is: +* +* joe:rw::allow +* owner@:rw::allow +* group@:rw::allow +* +* Deny aces complicate the matter. For example, the following acl grants +* everyone but joe write access: +* +* joe:w::deny +* everyone@:rwx::allow +* +* When applying mode 0660 to this acl, owner@ and group@ would lose rw access, +* and joe would lose r access. The result after inserting additional allow +* aces and applying mode 0660 is: +* +* joe:w::deny +* owner@:rw::allow +* group@:rw::allow +* joe:r::allow +* +* Inserting the additional aces does not alter the permissions that the acl +* grants. +*/ +static int +richacl_propagate_everyone (struct richacl_alloc *x) +{ +struct richace who = { .e_flags =RICHACE_SPECIAL_WHO }; +struct richacl *acl = x->acl; +struct richace *ace; +unsigned int owner_allow, group_allow; + +/* +* If the owner mask contains permissions which are not in +* the group mask, the group mask contains permissions which +* are not in the other mask, or the owner class contains +* permissions which are not in the other mask, we may need +* to propagate permissions up from the everyone@ allow ace. +* The third condition is implied by the first two. +*/ +if (!((acl->a_owner_mask & ~acl->a_group_mask) || + (acl->a_group_mask & ~acl->a_other_mask))) +return 0 ; +if (!acl->a_count) +return 0 ; + ace = acl->a_entries + acl->a_count -1 ; +if (richace_is_inherit_only (ace) || !richace_is_everyone (ace)) +return 0 ; +if (!(ace->e_mask & ~(acl->a_group_mask & acl->a_other_mask))) +/* +* None of the allowed permissions will get masked. +*/ +return 0 ; + owner_allow = ace->e_mask & acl->a_owner_mask; + group_allow = ace->e_mask & acl->a_group_mask; + +/* Propagate everyone@ permissions through to owner@. */ +if (owner_allow & ~(acl->a_group_mask & acl->a_other_mask)) { + who.e_id.special =RICHACE_OWNER_SPECIAL_ID ; +if (__richacl_propagate_everyone (x, &who, owner_allow)) +return -1 ; + acl = x->acl; + } + +if (group_allow & ~acl->a_other_mask) { +int n; + +/* Propagate everyone@ permissions through to group@. */ + who.e_id.special =RICHACE_GROUP_SPECIAL_ID ; +if (__richacl_propagate_everyone (x, &who, group_allow)) +return -1 ; + acl = x->acl; + +/* +* Start from the entry before the trailing everyone@ allow +* entry. We will not hit everyone@ entries in the loop. +*/ +for (n = acl->a_count -2 ; n !=-1 ; n--) { + ace = acl->a_entries + n; + +if (richace_is_inherit_only (ace) || +richace_is_owner (ace) || +richace_is_group (ace)) +continue ; +if (richace_is_allow (ace) ||richace_is_deny (ace)) { +/* +* Any inserted entry will end up below the +* current entry +*/ +if (__richacl_propagate_everyone (x, ace, + group_allow)) +return -1 ; + } + } + } +return 0 ; +}
Signature · 1 line
2.1.0
RFC 26/39 richacl: Isolate the owner and group classes
In reply to Andreas GruenbacherWhen applying the file masks to an acl, we need to ensure that no process gets more permissions than allowed by its file mask.
This may require inserting an owner@ deny ace to ensure this if the owner mask contains fewer permissions than the group or other mask. For example, when applying mode 0466 to the following acl:
everyone@:rw::allow
A deny ace needs to be inserted so that the owner won't get elevated write access:
owner@:w::deny
everyone@:rw::allow
Likewise, we may need to insert group class deny aces if the group mask contains fewer permissions than the other mask. For example, when applying mode 0646 to the following acl:
owner@:rw::allow
everyone@:rw::allow
A deny ace needs to be inserted so that the owning group won't get elevated write access:
owner@:rw::allow
group@:w::deny
everyone@:rw::allow
--- fs/richacl_compat.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+)
fs/richacl_compat.c +233 -0
@@ -413,3 +413,236 @@ richacl_propagate_everyone(struct richacl_alloc *x) }return 0 ; } + +/** +* richacl_max_allowed - maximum permissions that anybody is allowed +*/ +static unsigned int +richacl_max_allowed (struct richacl *acl) +{ +struct richace *ace; +unsigned int allowed =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_allow (ace)) + allowed |= ace->e_mask; +else if (richace_is_deny (ace)) { +if (richace_is_everyone (ace)) + allowed &= ~ace->e_mask; + } + } +return allowed; +} + +/** +* richacl_isolate_owner_class - limit the owner class to the owner file mask +* @x: acl and number of allocated entries +* +* POSIX requires that after a chmod, the owner class is granted no more +* permissions than the owner file permission bits. Mapped to richacls, this +* means that the owner class must not be granted any permissions that the +* owner mask does not include. +* +* When we apply file masks to an acl which grant more permissions to the group +* or other class than to the owner class, we may end up in a situation where +* the owner is granted additional permission from other aces. For example, +* given this acl: +* +* everyone:rwx::allow +* +* when file masks corresponding to mode 0466 are applied, after +* richacl_propagate_everyone() and __richacl_apply_masks(), we end up with: +* +* owner@:r::allow +* everyone@:rw::allow +* +* This acl still grants the owner rw access through the everyone@ allow ace. +* To fix this, we must deny w access to the owner: +* +* owner@:w::deny +* owner@:r::allow +* everyone@:rw::allow +*/ +static int +richacl_isolate_owner_class (struct richacl_alloc *x) +{ +struct richace *ace; +unsigned int allowed =0 ; + + allowed =richacl_max_allowed (x->acl); +if (allowed & ~x->acl->a_owner_mask) { +/* +* Figure out if we can update an existig OWNER@ DENY entry. +*/ +richacl_for_each_entry (ace, x->acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_deny (ace)) { +if (richace_is_owner (ace)) +break ; + }else if (richace_is_allow (ace)) { + ace = x->acl->a_entries + x->acl->a_count; +break ; + } + } +if (ace != x->acl->a_entries + x->acl->a_count) { +if (richace_change_mask (x, &ace, ace->e_mask | + (allowed & ~x->acl->a_owner_mask))) +return -1 ; + }else { +/* Insert an owner@ deny entry at the front. */ + ace = x->acl->a_entries; +if (richacl_insert_entry (x, &ace)) +return -1 ; + ace->e_type =RICHACE_ACCESS_DENIED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = allowed & ~x->acl->a_owner_mask; + ace->e_id.special =RICHACE_OWNER_SPECIAL_ID ; + } + } +return 0 ; +} + +/** +* __richacl_isolate_who - isolate entry from everyone@ allow entry +* @x: acl and number of allocated entries +* @who: identifier to isolate +* @deny: permissions this identifier should not be allowed +* +* See richacl_isolate_group_class(). +*/ +static int +__richacl_isolate_who (struct richacl_alloc *x,struct richace *who, +unsigned int deny) +{ +struct richace *ace; +unsigned int n; +/* +* Compute the permissions already denied to @who. +*/ +richacl_for_each_entry (ace, x->acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_same_identifier (ace, who) && +richace_is_deny (ace)) + deny &= ~ace->e_mask; + } +if (!deny) +return 0 ; + +/* +* Figure out if we can update an existig deny entry. Start from the +* entry before the trailing everyone@ allow entry. We will not hit +* everyone@ entries in the loop. +*/ +for (n = x->acl->a_count -2 ; n !=-1 ; n--) { + ace = x->acl->a_entries + n; +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_deny (ace)) { +if (richace_is_same_identifier (ace, who)) +break ; + }else if (richace_is_allow (ace) && + (ace->e_mask & deny)) { + n =-1 ; +break ; + } + } +if (n !=-1 ) { +if (richace_change_mask (x, &ace, ace->e_mask | deny)) +return -1 ; + }else { +/* +* Insert a new entry before the trailing everyone@ deny entry. +*/ +struct richace who_copy; + + ace = x->acl->a_entries + x->acl->a_count -1 ; +memcpy (&who_copy, who,sizeof (struct richace )); +if (richacl_insert_entry (x, &ace)) +return -1 ; +memcpy (ace, &who_copy,sizeof (struct richace )); + ace->e_type =RICHACE_ACCESS_DENIED_ACE_TYPE ; +richace_clear_inheritance_flags (ace); + ace->e_mask = deny; + } +return 0 ; +} + +/** +* richacl_isolate_group_class - limit the group class to the group file mask +* @x: acl and number of allocated entries +* +* POSIX requires that after a chmod, the group class is granted no more +* permissions than the group file permission bits. Mapped to richacls, this +* means that the group class must not be granted any permissions that the +* group mask does not include. +* +* When we apply file masks to an acl which grant more permissions to the other +* class than to the group class, we may end up in a situation where processes +* in the group class are granted additional permission from other aces. For +* example, given this acl: +* +* joe:rwx::allow +* everyone:rwx::allow +* +* when file masks corresponding to mode 0646 are applied, after +* richacl_propagate_everyone() and __richacl_apply_masks(), we end up with: +* +* joe:r::allow +* owner@:rw::allow +* group@:r::allow +* everyone@:rw::allow +* +* This acl still grants joe and group@ rw access through the everyone@ allow +* ace. To fix this, we must deny w access to group class aces before the +* everyone@ allow ace at the end of the acl: +* +* joe:r::allow +* owner@:rw::allow +* group@:r::allow +* joe:w::deny +* group@:w::deny +* everyone@:rw::allow +*/ +static int +richacl_isolate_group_class (struct richacl_alloc *x) +{ +struct richace who = { + .e_flags =RICHACE_SPECIAL_WHO , + .e_id.special =RICHACE_GROUP_SPECIAL_ID , + }; +struct richace *ace; +unsigned int deny; + +if (!x->acl->a_count) +return 0 ; + ace = x->acl->a_entries + x->acl->a_count -1 ; +if (richace_is_inherit_only (ace) || !richace_is_everyone (ace)) +return 0 ; + deny = ace->e_mask & ~x->acl->a_group_mask; + +if (deny) { +unsigned int n; + +if (__richacl_isolate_who (x, &who, deny)) +return -1 ; +/* +* Start from the entry before the trailing everyone@ allow +* entry. We will not hit everyone@ entries in the loop. +*/ +for (n = x->acl->a_count -2 ; n !=-1 ; n--) { + ace = x->acl->a_entries + n; + +if (richace_is_inherit_only (ace) || +richace_is_owner (ace) || +richace_is_group (ace)) +continue ; +if (__richacl_isolate_who (x, ace, deny)) +return -1 ; + } + } +return 0 ; +}
Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 27/39 richacl: Apply the file masks to a richacl
In reply to Andreas GruenbacherPut all the pieces of the acl transformation puzzle together for computing a richacl which has the file masks "applied" so that the standard nfsv4 access check algorithm can be used on the richacl.
--- fs/richacl_compat.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 3 ++ 2 files changed, 104 insertions(+)
fs/richacl_compat.c +101 -0
@@ -646,3 +646,104 @@ richacl_isolate_group_class(struct richacl_alloc *x) }return 0 ; } + +/** +* __richacl_apply_masks - apply the file masks to all aces +* @x: acl and number of allocated entries +* +* Apply the owner mask to owner@ aces, the other mask to +* everyone@ aces, and the group mask to all other aces. +* +* The previous transformations have brought the acl into a +* form in which applying the masks will not lead to the +* accidental loss of permissions anymore. +*/ +static int +__richacl_apply_masks (struct richacl_alloc *x) +{ +struct richace *ace; + +richacl_for_each_entry (ace, x->acl) { +unsigned int mask; + +if (richace_is_inherit_only (ace) || !richace_is_allow (ace)) +continue ; +if (richace_is_owner (ace)) + mask = x->acl->a_owner_mask; +else if (richace_is_everyone (ace)) + mask = x->acl->a_other_mask; +else + mask = x->acl->a_group_mask; +if (richace_change_mask (x, &ace, ace->e_mask & mask)) +return -1 ; + } +return 0 ; +} + +/** +* richacl_apply_masks - apply the masks to the acl +* +* Transform @acl so that the standard NFSv4 permission check algorithm (which +* is not aware of file masks) will compute the same access decisions as the +* richacl permission check algorithm (which looks at the acl and the file +* masks). +* +* This algorithm is split into several steps: +* +* - Move everyone@ aces to the end of the acl. This simplifies the other +* transformations, and allows the everyone@ allow ace at the end of the +* acl to eventually allow permissions to the other class only. +* +* - Propagate everyone@ permissions up the acl. This transformation makes +* sure that the owner and group class aces won't lose any permissions when +* we apply the other mask to the everyone@ allow ace at the end of the acl. +* +* - Apply the file masks to all aces. +* +* - Make sure that the owner is not granted any permissions beyond the owner +* mask from group class aces or from everyone@. +* +* - Make sure that the group class is not granted any permissions from +* everyone@. +* +* The algorithm is exact except for richacls which cannot be represented as an +* acl alone: for example, given this acl: +* +* group@:rw::allow +* +* when file masks corresponding to mode 0600 are applied, the owner would only +* get rw access if he is a member of the owning group. This algorithm would +* produce an empty acl in this case. We fix this case by modifying +* richacl_permission() so that the group mask is always applied to group class +* aces. With this fix, the owner would not have any access (beyond the +* implicit permissions always granted to owners). +* +* NOTE: Depending on the acl and file masks, this algorithm can increase the +* number of aces by almost a factor of three in the worst case. This may make +* the acl too large for some purposes. +*/ +int +richacl_apply_masks (struct richacl **acl) +{ +int retval =0 ; + +if ((*acl)->a_flags &RICHACL_MASKED ) { +struct richacl_alloc x = { + .acl = *acl, + .count = (*acl)->a_count, + }; + +if (richacl_move_everyone_aces_down (&x) || +richacl_propagate_everyone (&x) || +__richacl_apply_masks (&x) || +richacl_isolate_owner_class (&x) || +richacl_isolate_group_class (&x)) + retval = -ENOMEM ; + + x.acl->a_flags &= ~RICHACL_MASKED ; + *acl = x.acl; + } + +return retval; +} +EXPORT_SYMBOL_GPL (richacl_apply_masks);
include/linux/richacl.h +3 -0
@@ -323,4 +323,7 @@ extern int richacl_equiv_mode(const struct richacl *, mode_t *);extern int richacl_permission (struct inode *,const struct richacl *,int );extern struct richacl *richacl_create (struct inode *,struct inode *); +/* richacl_compat.c */ +extern int richacl_apply_masks (struct richacl **); +#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
RFC 28/39 richacl: Create richacl from mode values
In reply to Andreas GruenbacherCreate a richacl that corresponds to given file mode permission bits.
--- fs/richacl_compat.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 36 insertions(+)
fs/richacl_compat.c +35 -0
@@ -747,3 +747,38 @@ richacl_apply_masks(struct richacl **acl)return retval; }EXPORT_SYMBOL_GPL (richacl_apply_masks); + +/** +* richacl_from_mode - create an acl which corresponds to @mode +* @mode: file mode including the file type +*/ +struct richacl * +richacl_from_mode (mode_t mode) +{ +struct richacl *acl; +struct richace *ace; + + acl =richacl_alloc (1 ,GFP_KERNEL ); +if (!acl) +return NULL ; + acl->a_flags =RICHACL_MASKED ; + acl->a_owner_mask =richacl_mode_to_mask (mode >>6 ) | +RICHACE_POSIX_OWNER_ALLOWED ; + acl->a_group_mask =richacl_mode_to_mask (mode >>3 ); + acl->a_other_mask =richacl_mode_to_mask (mode); + + ace = acl->a_entries; + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask =RICHACE_POSIX_ALWAYS_ALLOWED | +RICHACE_POSIX_MODE_ALL | +RICHACE_POSIX_OWNER_ALLOWED ; +/* RICHACE_DELETE_CHILD is meaningless for non-directories. */ +if (!S_ISDIR (mode)) + ace->e_mask &= ~RICHACE_DELETE_CHILD ; + ace->e_id.special =RICHACE_EVERYONE_SPECIAL_ID ; + +return acl; + +} +EXPORT_SYMBOL_GPL (richacl_from_mode);
include/linux/richacl.h +1 -0
@@ -325,5 +325,6 @@ extern struct richacl *richacl_create(struct inode *, struct inode *);/* richacl_compat.c */ extern int richacl_apply_masks (struct richacl **); +extern struct richacl *richacl_from_mode (mode_t );#endif /* __RICHACL_H */
Signature · 1 line
2.1.0
RFC 29/39 richacl: Create acl with masks applied in richacl_from_mode()
In reply to Andreas GruenbacherWhen creating a richacl that represents a particular file mode, one approach is to create one everyone@ allow entry and set the richacl masks according to the file mode; when those masks are applied with richacl_apply_masks(), that everyone@ allow entry gets transformed as needed. The other approach is to compute the result after richacl_apply_masks() directly; this commit does that.
--- fs/richacl_compat.c | 85 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 17 deletions(-)
fs/richacl_compat.c +68 -17
@@ -755,30 +755,81 @@ EXPORT_SYMBOL_GPL(richacl_apply_masks);struct richacl *richacl_from_mode (mode_t mode) { +unsigned int owner_mask =richacl_mode_to_mask (mode >>6 ) | +RICHACE_POSIX_OWNER_ALLOWED ; +unsigned int group_mask =richacl_mode_to_mask (mode >>3 ); +unsigned int other_mask =richacl_mode_to_mask (mode); +unsigned int denied; +unsigned int entries =0 ;struct richacl *acl;struct richace *ace; - acl =richacl_alloc (1 ,GFP_KERNEL ); +/* RICHACE_DELETE_CHILD is meaningless for non-directories. */ +if (!S_ISDIR (mode)) { + owner_mask &= ~RICHACE_DELETE_CHILD ; + group_mask &= ~RICHACE_DELETE_CHILD ; + other_mask &= ~RICHACE_DELETE_CHILD ; + } + +if (owner_mask & ~(group_mask & other_mask)) + entries++;/* OWNER@ ALLOW entry needed */ + denied = ~owner_mask & (group_mask | other_mask); +if (denied) + entries++;/* OWNER@ DENY entry needed */ +if (group_mask & ~other_mask) + entries++;/* GROUP@ ALLOW entry needed */ + denied = ~group_mask & other_mask; +if (denied) + entries++;/* GROUP@ DENY entry needed */ +if (other_mask) + entries++;/* EVERYONE@ ALLOW entry needed */ + + acl =richacl_alloc (entries,GFP_KERNEL );if (!acl)return NULL ; - acl->a_flags =RICHACL_MASKED ; - acl->a_owner_mask =richacl_mode_to_mask (mode >>6 ) | -RICHACE_POSIX_OWNER_ALLOWED ; - acl->a_group_mask =richacl_mode_to_mask (mode >>3 ); - acl->a_other_mask =richacl_mode_to_mask (mode); - + acl->a_owner_mask = owner_mask; + acl->a_group_mask = group_mask; + acl->a_other_mask = other_mask; ace = acl->a_entries; - ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; - ace->e_flags =RICHACE_SPECIAL_WHO ; - ace->e_mask =RICHACE_POSIX_ALWAYS_ALLOWED | -RICHACE_POSIX_MODE_ALL | -RICHACE_POSIX_OWNER_ALLOWED ; -/* RICHACE_DELETE_CHILD is meaningless for non-directories. */ -if (!S_ISDIR (mode)) - ace->e_mask &= ~RICHACE_DELETE_CHILD ; - ace->e_id.special =RICHACE_EVERYONE_SPECIAL_ID ; -return acl; +if (owner_mask & ~(group_mask & other_mask)) { + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = owner_mask; + ace->e_id.special =RICHACE_OWNER_SPECIAL_ID ; + ace++; + } + denied = ~owner_mask & (group_mask | other_mask); +if (denied) { + ace->e_type =RICHACE_ACCESS_DENIED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = denied; + ace->e_id.special =RICHACE_OWNER_SPECIAL_ID ; + ace++; + } +if (group_mask & ~other_mask) { + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = group_mask; + ace->e_id.special =RICHACE_GROUP_SPECIAL_ID ; + ace++; + } + denied = ~group_mask & other_mask; +if (denied) { + ace->e_type =RICHACE_ACCESS_DENIED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = denied; + ace->e_id.special =RICHACE_GROUP_SPECIAL_ID ; + ace++; + } +if (other_mask) { + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = other_mask; + ace->e_id.special =RICHACE_EVERYONE_SPECIAL_ID ; + ace++; + } +return acl; }EXPORT_SYMBOL_GPL (richacl_from_mode);
Signature · 1 line
2.1.0
RFC 30/39 nfsd: Remove dead declarations
In reply to Andreas Gruenbacher--- fs/nfsd/nfs4acl.c | 12 ------------ 1 file changed, 12 deletions(-)
fs/nfsd/nfs4acl.c +0 -12
@@ -52,10 +52,6 @@#define NFS4_ANYONE_MODE (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL | NFS4_ACE_SYNCHRONIZE)#define NFS4_OWNER_MODE (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL) -/* We don't support these bits; insist they be neither allowed nor denied */ -#define NFS4_MASK_UNSUPP (NFS4_ACE_DELETE | NFS4_ACE_WRITE_OWNER \ - | NFS4_ACE_READ_NAMED_ATTRS | NFS4_ACE_WRITE_NAMED_ATTRS) -/* flags used to simulate posix default ACLs */ #define NFS4_INHERITANCE_FLAGS (NFS4_ACE_FILE_INHERIT_ACE \ | NFS4_ACE_DIRECTORY_INHERIT_ACE)
@@ -64,9 +60,6 @@ | NFS4_ACE_INHERIT_ONLY_ACE \ | NFS4_ACE_IDENTIFIER_GROUP) -#define MASK_EQUAL (mask1, mask2) \ - ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) ) -static u32 mask_from_posix (unsigned short perm,unsigned int flags) {
@@ -126,11 +119,6 @@ low_mode_from_nfs4(u32 perm, unsigned short *mode, unsigned int flags) *mode |=ACL_EXECUTE ; } -struct ace_container { -struct nfs4_ace *ace; -struct list_head ace_l; -}; -static short ace2type (struct nfs4_ace *);static void _posix_to_nfsv4_one (struct posix_acl *,struct nfs4_acl *,unsigned int );
Signature · 1 line
2.1.0
RFC 31/39 nfsd: Keep list of acls to dispose of in compoundargs
In reply to Andreas GruenbacherWe will decode acls in requests into richacls; those need to be richacl_put() at the end of the request instead of kfree()d; this allows the vfs to cache them whenever possible.
NOTE: If we allow only a single acl per request, we can get rid of the list here.
--- fs/nfsd/nfs4xdr.c | 26 ++++++++++++++++++++++++++ fs/nfsd/xdr4.h | 6 ++++++ 2 files changed, 32 insertions(+)
fs/nfsd/nfs4xdr.c +26 -0
@@ -39,6 +39,7 @@#include <linux/utsname.h> #include <linux/pagemap.h> #include <linux/sunrpc/svcauth_gss.h> +#include <linux/richacl.h> #include "idmap.h" #include "acl.h"
@@ -195,6 +196,24 @@ svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len)return tb->buf; } +static struct richacl * +svcxdr_alloc_richacl (struct nfsd4_compoundargs *argp,u32 nace) +{ +struct svcxdr_richacl *acls; + + acls =kmalloc (sizeof (*acls),GFP_KERNEL ); +if (!acls) +return NULL ; + acls->acl =richacl_alloc (nace,GFP_KERNEL ); +if (!acls->acl) { +kfree (acls); +return NULL ; + } + acls->next = argp->acls; + argp->acls = acls; +return acls->acl; +} +/* * For xdr strings that need to be passed to other kernel api's * as null-terminated strings.
@@ -4383,6 +4402,12 @@ int nfsd4_release_compoundargs(void *rq, __be32 *p, void *resp) args->to_free = tb->next;kfree (tb); } +while (args->acls) { +struct svcxdr_richacl *acls = args->acls; + args->acls = acls->next; +richacl_put (acls->acl); +kfree (acls); + }return 1 ; }
@@ -4401,6 +4426,7 @@ nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_comp args->pagelen = rqstp->rq_arg.page_len; args->tmpp =NULL ; args->to_free =NULL ; + args->acls =NULL ; args->ops = args->iops; args->rqstp = rqstp;
fs/nfsd/xdr4.h +6 -0
@@ -569,6 +569,11 @@ struct svcxdr_tmpbuf {char buf[]; }; +struct svcxdr_richacl { +struct svcxdr_richacl *next; +struct richacl *acl; +}; +struct nfsd4_compoundargs {/* scratch variables for XDR decode */ __be32 * p;
@@ -578,6 +583,7 @@ struct nfsd4_compoundargs {__be32 tmp[8 ];__be32 * tmpp;struct svcxdr_tmpbuf *to_free; +struct svcxdr_richacl *acls;struct svc_rqst *rqstp;
Signature · 1 line
2.1.0
RFC 34/39 nfs/sunrpc: No more encode and decode function pointer casting
In reply to Andreas GruenbacherInstead of casting the encode and decode functions to the required type when assigning them to the p_encode and p_decode members of struct rpc_procinfo, define the functions with their proper type and cast the additional obj argument to the appropriate type inside those functions. This allows slightly better type checking by the compiler at the cost of slightly more verbose code.
--- fs/lockd/clnt4xdr.c | 28 ++-- fs/lockd/clntxdr.c | 28 ++-- fs/lockd/mon.c | 20 ++- fs/nfs/mount_clnt.c | 21 +-- fs/nfs/nfs2xdr.c | 55 ++++--- fs/nfs/nfs3xdr.c | 123 +++++++++------ fs/nfs/nfs4xdr.c | 292 +++++++++++++++++++++++------------ fs/nfsd/nfs4callback.c | 16 +- include/linux/sunrpc/xdr.h | 5 +- net/sunrpc/auth_gss/gss_rpc_upcall.c | 4 +- net/sunrpc/auth_gss/gss_rpc_xdr.c | 6 +- net/sunrpc/auth_gss/gss_rpc_xdr.h | 4 +- net/sunrpc/clnt.c | 4 +- net/sunrpc/rpcb_clnt.c | 51 +++--- 14 files changed, 421 insertions(+), 236 deletions(-)
fs/lockd/clnt4xdr.c +18 -10
@@ -381,8 +381,9 @@ static void encode_nlm4_lock(struct xdr_stream *xdr,*/ static void nlm4_xdr_enc_testargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -402,8 +403,9 @@ static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,*/ static void nlm4_xdr_enc_lockargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -424,8 +426,9 @@ static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,*/ static void nlm4_xdr_enc_cancargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -442,8 +445,9 @@ static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,*/ static void nlm4_xdr_enc_unlockargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -458,8 +462,9 @@ static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,*/ static void nlm4_xdr_enc_res (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_res *result) +void *obj) { +const struct nlm_res *result = obj;encode_cookie (xdr, &result->cookie);encode_nlm4_stat (xdr, result->status); }
@@ -479,8 +484,9 @@ static void nlm4_xdr_enc_res(struct rpc_rqst *req,*/ static void nlm4_xdr_enc_testres (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_res *result) +void *obj) { +const struct nlm_res *result = obj;encode_cookie (xdr, &result->cookie);encode_nlm4_stat (xdr, result->status);if (result->status == nlm_lck_denied)
@@ -525,8 +531,9 @@ out:static int nlm4_xdr_dec_testres (struct rpc_rqst *req,struct xdr_stream *xdr, -struct nlm_res *result) +void *obj) { +struct nlm_res *result = obj;int error; error =decode_cookie (xdr, &result->cookie);
@@ -545,8 +552,9 @@ out:*/ static int nlm4_xdr_dec_res (struct rpc_rqst *req,struct xdr_stream *xdr, -struct nlm_res *result) +void *obj) { +struct nlm_res *result = obj;int error; error =decode_cookie (xdr, &result->cookie);
@@ -566,8 +574,8 @@ out:#define PROC (proc, argtype, restype) \ [NLMPROC_##proc] = { \ .p_proc = NLMPROC_##proc, \ - .p_encode = (kxdreproc_t)nlm4_xdr_enc_##argtype, \ - .p_decode = (kxdrdproc_t)nlm4_xdr_dec_##restype, \ + .p_encode = nlm4_xdr_enc_##argtype, \ + .p_decode = nlm4_xdr_dec_##restype, \ .p_arglen = NLM4_##argtype##_sz, \ .p_replen = NLM4_##restype##_sz, \ .p_statidx = NLMPROC_##proc, \
fs/lockd/clntxdr.c +18 -10
@@ -374,8 +374,9 @@ static void encode_nlm_lock(struct xdr_stream *xdr,*/ static void nlm_xdr_enc_testargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -395,8 +396,9 @@ static void nlm_xdr_enc_testargs(struct rpc_rqst *req,*/ static void nlm_xdr_enc_lockargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -417,8 +419,9 @@ static void nlm_xdr_enc_lockargs(struct rpc_rqst *req,*/ static void nlm_xdr_enc_cancargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -435,8 +438,9 @@ static void nlm_xdr_enc_cancargs(struct rpc_rqst *req,*/ static void nlm_xdr_enc_unlockargs (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_args *args) +void *obj) { +const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);
@@ -451,8 +455,9 @@ static void nlm_xdr_enc_unlockargs(struct rpc_rqst *req,*/ static void nlm_xdr_enc_res (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_res *result) +void *obj) { +const struct nlm_res *result = obj;encode_cookie (xdr, &result->cookie);encode_nlm_stat (xdr, result->status); }
@@ -479,8 +484,9 @@ static void encode_nlm_testrply(struct xdr_stream *xdr,static void nlm_xdr_enc_testres (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nlm_res *result) +void *obj) { +const struct nlm_res *result = obj;encode_cookie (xdr, &result->cookie);encode_nlm_stat (xdr, result->status);encode_nlm_testrply (xdr, result);
@@ -523,8 +529,9 @@ out:static int nlm_xdr_dec_testres (struct rpc_rqst *req,struct xdr_stream *xdr, -struct nlm_res *result) +void *obj) { +struct nlm_res *result = obj;int error; error =decode_cookie (xdr, &result->cookie);
@@ -543,8 +550,9 @@ out:*/ static int nlm_xdr_dec_res (struct rpc_rqst *req,struct xdr_stream *xdr, -struct nlm_res *result) +void *obj) { +struct nlm_res *result = obj;int error; error =decode_cookie (xdr, &result->cookie);
@@ -564,8 +572,8 @@ out:#define PROC (proc, argtype, restype) \ [NLMPROC_##proc] = { \ .p_proc = NLMPROC_##proc, \ - .p_encode = (kxdreproc_t)nlm_xdr_enc_##argtype, \ - .p_decode = (kxdrdproc_t)nlm_xdr_dec_##restype, \ + .p_encode = nlm_xdr_enc_##argtype, \ + .p_decode = nlm_xdr_dec_##restype, \ .p_arglen = NLM_##argtype##_sz, \ .p_replen = NLM_##restype##_sz, \ .p_statidx = NLMPROC_##proc, \
fs/lockd/mon.c +12 -8
@@ -527,22 +527,25 @@ static void encode_priv(struct xdr_stream *xdr, const struct nsm_args *argp) }static void nsm_xdr_enc_mon (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nsm_args *argp) +void *obj) { +const struct nsm_args *argp = obj;encode_mon_id (xdr, argp);encode_priv (xdr, argp); }static void nsm_xdr_enc_unmon (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nsm_args *argp) +void *obj) { +const struct nsm_args *argp = obj;encode_mon_id (xdr, argp); }static int nsm_xdr_dec_stat_res (struct rpc_rqst *rqstp,struct xdr_stream *xdr, -struct nsm_res *resp) +void *obj) { +struct nsm_res *resp = obj;__be32 *p; p =xdr_inline_decode (xdr,4 +4 );
@@ -558,8 +561,9 @@ static int nsm_xdr_dec_stat_res(struct rpc_rqst *rqstp,static int nsm_xdr_dec_stat (struct rpc_rqst *rqstp,struct xdr_stream *xdr, -struct nsm_res *resp) +void *obj) { +struct nsm_res *resp = obj;__be32 *p; p =xdr_inline_decode (xdr,4 );
@@ -583,8 +587,8 @@ static int nsm_xdr_dec_stat(struct rpc_rqst *rqstp,static struct rpc_procinfo nsm_procedures[] = { [NSMPROC_MON ] = { .p_proc =NSMPROC_MON , - .p_encode = (kxdreproc_t )nsm_xdr_enc_mon, - .p_decode = (kxdrdproc_t )nsm_xdr_dec_stat_res, + .p_encode = nsm_xdr_enc_mon, + .p_decode = nsm_xdr_dec_stat_res, .p_arglen = SM_mon_sz, .p_replen = SM_monres_sz, .p_statidx =NSMPROC_MON ,
@@ -592,8 +596,8 @@ static struct rpc_procinfo nsm_procedures[] = { }, [NSMPROC_UNMON] = { .p_proc = NSMPROC_UNMON, - .p_encode = (kxdreproc_t)nsm_xdr_enc_unmon, - .p_decode = (kxdrdproc_t)nsm_xdr_dec_stat, + .p_encode = nsm_xdr_enc_unmon, + .p_decode = nsm_xdr_dec_stat, .p_arglen = SM_mon_id_sz, .p_replen = SM_unmonres_sz, .p_statidx = NSMPROC_UNMON,
fs/nfs/mount_clnt.c +12 -9
@@ -306,8 +306,9 @@ static void encode_mntdirpath(struct xdr_stream *xdr, const char *pathname) }static void mnt_xdr_enc_dirpath (struct rpc_rqst *req,struct xdr_stream *xdr, -const char *dirpath) +void *obj) { +const char *dirpath = obj;encode_mntdirpath (xdr, dirpath); }
@@ -359,8 +360,9 @@ static int decode_fhandle(struct xdr_stream *xdr, struct mountres *res)static int mnt_xdr_dec_mountres (struct rpc_rqst *req,struct xdr_stream *xdr, -struct mountres *res) +void *obj) { +struct mountres *res = obj;int status; status =decode_status (xdr, res);
@@ -451,8 +453,9 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res)static int mnt_xdr_dec_mountres3 (struct rpc_rqst *req,struct xdr_stream *xdr, -struct mountres *res) +void *obj) { +struct mountres *res = obj;int status; status =decode_fhs_status (xdr, res);
@@ -469,8 +472,8 @@ static int mnt_xdr_dec_mountres3(struct rpc_rqst *req,static struct rpc_procinfo mnt_procedures[] = { [MOUNTPROC_MNT ] = { .p_proc =MOUNTPROC_MNT , - .p_encode = (kxdreproc_t )mnt_xdr_enc_dirpath, - .p_decode = (kxdrdproc_t )mnt_xdr_dec_mountres, + .p_encode = mnt_xdr_enc_dirpath, + .p_decode = mnt_xdr_dec_mountres, .p_arglen = MNT_enc_dirpath_sz, .p_replen = MNT_dec_mountres_sz, .p_statidx =MOUNTPROC_MNT ,
@@ -478,7 +481,7 @@ static struct rpc_procinfo mnt_procedures[] = { }, [MOUNTPROC_UMNT] = { .p_proc = MOUNTPROC_UMNT, - .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath, + .p_encode = mnt_xdr_enc_dirpath, .p_arglen = MNT_enc_dirpath_sz, .p_statidx = MOUNTPROC_UMNT, .p_name = "UMOUNT",
@@ -488,8 +491,8 @@ static struct rpc_procinfo mnt_procedures[] = {static struct rpc_procinfo mnt3_procedures[] = { [MOUNTPROC3_MNT ] = { .p_proc =MOUNTPROC3_MNT , - .p_encode = (kxdreproc_t )mnt_xdr_enc_dirpath, - .p_decode = (kxdrdproc_t )mnt_xdr_dec_mountres3, + .p_encode = mnt_xdr_enc_dirpath, + .p_decode = mnt_xdr_dec_mountres3, .p_arglen = MNT_enc_dirpath_sz, .p_replen = MNT_dec_mountres3_sz, .p_statidx =MOUNTPROC3_MNT ,
@@ -497,7 +500,7 @@ static struct rpc_procinfo mnt3_procedures[] = { }, [MOUNTPROC3_UMNT] = { .p_proc = MOUNTPROC3_UMNT, - .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath, + .p_encode = mnt_xdr_enc_dirpath, .p_arglen = MNT_enc_dirpath_sz, .p_statidx = MOUNTPROC3_UMNT, .p_name = "UMOUNT",
fs/nfs/nfs2xdr.c +36 -19
178 lines not on this page · raw message
fs/nfs/nfs3xdr.c +80 -43
400 lines not on this page · raw message
fs/nfs/nfs4xdr.c +194 -98
971 lines not on this page · raw message
fs/nfsd/nfs4callback.c +10 -6
@@ -486,8 +486,9 @@ static void nfs4_xdr_enc_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr,* 20.2. Operation 4: CB_RECALL - Recall a Delegation */ static void nfs4_xdr_enc_cb_recall (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nfsd4_callback *cb) +void *obj) { +const struct nfsd4_callback *cb = obj;const struct nfs4_delegation *dp =cb_to_delegation (cb);struct nfs4_cb_compound_hdr hdr = { .ident = cb->cb_clp->cl_cb_ident,
@@ -521,8 +522,9 @@ static int nfs4_xdr_dec_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr,*/ static int nfs4_xdr_dec_cb_recall (struct rpc_rqst *rqstp,struct xdr_stream *xdr, -struct nfsd4_callback *cb) +void *obj) { +struct nfsd4_callback *cb = obj;struct nfs4_cb_compound_hdr hdr;enum nfsstat4 nfserr;int status;
@@ -601,8 +603,9 @@ static void encode_cb_layout4args(struct xdr_stream *xdr,static void nfs4_xdr_enc_cb_layout (struct rpc_rqst *req,struct xdr_stream *xdr, -const struct nfsd4_callback *cb) +void *obj) { +const struct nfsd4_callback *cb = obj;const struct nfs4_layout_stateid *ls = container_of(cb, struct nfs4_layout_stateid, ls_recall);struct nfs4_cb_compound_hdr hdr = {
@@ -618,8 +621,9 @@ static void nfs4_xdr_enc_cb_layout(struct rpc_rqst *req,static int nfs4_xdr_dec_cb_layout (struct rpc_rqst *rqstp,struct xdr_stream *xdr, -struct nfsd4_callback *cb) +void *obj) { +struct nfsd4_callback *cb = obj;struct nfs4_cb_compound_hdr hdr;enum nfsstat4 nfserr;int status;
@@ -648,8 +652,8 @@ out:#define PROC (proc, call, argtype, restype) \ [NFSPROC4_CLNT_##proc] = { \ .p_proc = NFSPROC4_CB_##call, \ - .p_encode = (kxdreproc_t)nfs4_xdr_enc_##argtype, \ - .p_decode = (kxdrdproc_t)nfs4_xdr_dec_##restype, \ + .p_encode = nfs4_xdr_enc_##argtype, \ + .p_decode = nfs4_xdr_dec_##restype, \ .p_arglen = NFS4_enc_##argtype##_sz, \ .p_replen = NFS4_dec_##restype##_sz, \ .p_statidx = NFSPROC4_CB_##call, \
include/linux/sunrpc/xdr.h +3 -2
@@ -210,8 +210,9 @@ struct xdr_stream {/* * These are the xdr_stream style generic XDR encode and decode functions. */ -typedef void (*kxdreproc_t )(void *rqstp,struct xdr_stream *xdr,void *obj); -typedef int (*kxdrdproc_t )(void *rqstp,struct xdr_stream *xdr,void *obj); +struct rpc_rqst ; +typedef void (*kxdreproc_t )(struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj); +typedef int (*kxdrdproc_t )(struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj);extern void xdr_init_encode (struct xdr_stream *xdr,struct xdr_buf *buf,__be32 *p);extern __be32 *xdr_reserve_space (struct xdr_stream *xdr,size_t nbytes);
net/sunrpc/auth_gss/gss_rpc_upcall.c +2 -2
@@ -55,8 +55,8 @@ enum {#define PROC (proc, name) \ [GSSX_##proc] = { \ .p_proc = GSSX_##proc, \ - .p_encode = (kxdreproc_t)gssx_enc_##name, \ - .p_decode = (kxdrdproc_t)gssx_dec_##name, \ + .p_encode = gssx_enc_##name, \ + .p_decode = gssx_dec_##name, \ .p_arglen = GSSX_ARG_##name##_sz, \ .p_replen = GSSX_RES_##name##_sz, \ .p_statidx = GSSX_##proc, \
net/sunrpc/auth_gss/gss_rpc_xdr.c +4 -2
@@ -733,8 +733,9 @@ static int gssx_enc_cb(struct xdr_stream *xdr, struct gssx_cb *cb)void gssx_enc_accept_sec_context (struct rpc_rqst *req,struct xdr_stream *xdr, -struct gssx_arg_accept_sec_context *arg) +void *obj) { +struct gssx_arg_accept_sec_context *arg = obj;int err; err =gssx_enc_call_ctx (xdr, &arg->call_ctx);
@@ -789,8 +790,9 @@ done:int gssx_dec_accept_sec_context (struct rpc_rqst *rqstp,struct xdr_stream *xdr, -struct gssx_res_accept_sec_context *res) +void *obj) { +struct gssx_res_accept_sec_context *res = obj;u32 value_follows;int err;
net/sunrpc/auth_gss/gss_rpc_xdr.h +2 -2
@@ -179,10 +179,10 @@ struct gssx_res_accept_sec_context {#define gssx_dec_init_sec_context NULLvoid gssx_enc_accept_sec_context (struct rpc_rqst *req,struct xdr_stream *xdr, -struct gssx_arg_accept_sec_context *args); +void *);int gssx_dec_accept_sec_context (struct rpc_rqst *rqstp,struct xdr_stream *xdr, -struct gssx_res_accept_sec_context *res); +void *);#define gssx_enc_release_handle NULL#define gssx_dec_release_handle NULL#define gssx_enc_get_mic NULL
net/sunrpc/clnt.c +2 -2
@@ -2392,11 +2392,11 @@ out_overflow: goto out_garbage; } -static void rpcproc_encode_null (void *rqstp,struct xdr_stream *xdr,void *obj) +static void rpcproc_encode_null (struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj) { } -static int rpcproc_decode_null (void *rqstp,struct xdr_stream *xdr,void *obj) +static int rpcproc_decode_null (struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj) {return 0 ; }
net/sunrpc/rpcb_clnt.c +28 -23
140 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC 36/39 nfs3: Return posix acl encode errors
In reply to Andreas GruenbacherWhen an error occurs when encoding a posix acl, return the error instead of causing a BUG().
--- fs/nfs/nfs3xdr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/nfs/nfs3xdr.c +4 -3
@@ -1384,13 +1384,14 @@ static int nfs3_xdr_enc_setacl3args(struct rpc_rqst *req, error =nfsacl_encode (xdr->buf, base, args->inode, (args->mask &NFS_ACL ) ? args->acl_access :NULL ,1 ,0 ); -/* FIXME: this is just broken */ -BUG_ON (error <0 ); +if (error <0 ) +return error; error =nfsacl_encode (xdr->buf, base + error, args->inode, (args->mask &NFS_DFACL ) ? args->acl_default :NULL ,1 ,NFS_ACL_DEFAULT ); -BUG_ON (error <0 ); +if (error <0 ) +return error;return 0 ; }
Signature · 1 line
2.1.0
RFC 38/39 rpc: Allow to demand-allocate pages to encode into
In reply to Andreas GruenbacherWhen encoding large, variable-length objects such as acls into xdr_bufs, it is easier to allocate buffer pages on demand rather than computing the required buffer size beforehand.
--- net/sunrpc/xdr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/sunrpc/xdr.c +8 -0
@@ -537,6 +537,14 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,*/ xdr->scratch.iov_base = xdr->p; xdr->scratch.iov_len = frag1bytes; + +if (!*xdr->page_ptr) { +struct page *page =alloc_page (GFP_KERNEL ); +if (!page) +return ERR_PTR (-ENOMEM ); + *xdr->page_ptr = page; + } + p =page_address (*xdr->page_ptr);/* * Note this is where the next encode will start after we've
Signature · 1 line
2.1.0
RFC 39/39 nfs: Add richacl support
In reply to Andreas GruenbacherChanges nfs to support the "system.richacl" xattr instead of "system.nfs4_acl".
The "system.nfs4_acl" xattr nfs uses directly exposes the on-the-wire format of NFSv4's acl attribute to user space. This has at least two downsides: (1) the format is different from other file systems, so user-space code needs to be nfs filesystem aware; (2) when symbolic user@domain and group@domain names are used in the acl, user-space needs to perform ID mapping in the same way as the kernel.
When user-space requested only the length of the "system.nfs4_acl" attribute, nfs doesn't always need to retrieve the entire "system.nfs4_acl" attribute. With the "system.richacl" xattr, the length of "system.richacl" cannot be computed from the length of the NFSv4 acl attribute, so we always retrieve and cache the acl even when user-space only asks for the attribute length.
When the returned acl exactly matches the file mode, we could discard it and return -ENODATA for "system.richacl". It isn't trivial to determine when an acl matches the file mode, though.
FIXME: For backwards compatibility, add support for "system.nfs4_acl" on top of the richacl support as well.
--- fs/nfs/inode.c | 2 +- fs/nfs/nfs4proc.c | 334 ++++++++++++++++++++-------------------------- fs/nfs/nfs4xdr.c | 209 ++++++++++++++++++++++++++--- fs/nfs/super.c | 4 +- include/linux/nfs_fs.h | 2 +- include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 6 +- 7 files changed, 349 insertions(+), 210 deletions(-)
fs/nfs/inode.c +1 -1
@@ -1825,7 +1825,7 @@ struct inode *nfs_alloc_inode(struct super_block *sb) nfsi->flags =0UL ; nfsi->cache_validity =0UL ;#if IS_ENABLED (CONFIG_NFS_V4 ) - nfsi->nfs4_acl =NULL ; + nfsi->cached_acl_len =0 ;#endif /* CONFIG_NFS_V4 */ return &nfsi->vfs_inode; }
fs/nfs/nfs4proc.c +148 -186
490 lines not on this page · raw message
fs/nfs/nfs4xdr.c +191 -18
266 lines not on this page · raw message
fs/nfs/super.c +2 -2
@@ -2318,7 +2318,7 @@ void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)/* The VFS shouldn't apply the umask to mode bits. We will do * so ourselves when necessary. */ - sb->s_flags |=MS_POSIXACL ; + sb->s_flags |=MS_RICHACL ; sb->s_time_gran =1 ; }
@@ -2345,7 +2345,7 @@ void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)/* The VFS shouldn't apply the umask to mode bits. We will do * so ourselves when necessary. */ - sb->s_flags |=MS_POSIXACL ; + sb->s_flags |=MS_RICHACL ; }nfs_initialise_sb (sb);
include/linux/nfs_fs.h +1 -1
@@ -176,7 +176,7 @@ struct nfs_inode {wait_queue_head_t waitqueue;#if IS_ENABLED (CONFIG_NFS_V4 ) -struct nfs4_cached_acl *nfs4_acl; +uint32_t cached_acl_len;/* NFSv4 state */ struct list_head open_states;struct nfs_delegation __rcu *delegation;
include/linux/nfs_fs_sb.h +2 -0
@@ -237,5 +237,7 @@ struct nfs_server {#define NFS_CAP_SEEK (1U << 19)#define NFS_CAP_ALLOCATE (1U << 20)#define NFS_CAP_DEALLOCATE (1U << 21) +#define NFS_CAP_ALLOW_ACLS (1U << 22) +#define NFS_CAP_DENY_ACLS (1U << 23)#endif
include/linux/nfs_xdr.h +4 -2
@@ -638,7 +638,9 @@ struct nfs_setattrargs {struct nfs_setaclargs {struct nfs4_sequence_args seq_args; +const struct nfs_server * server;struct nfs_fh * fh; +struct richacl * acl;size_t acl_len;struct page ** acl_pages; };
@@ -658,9 +660,9 @@ struct nfs_getaclargs {#define NFS4_ACL_TRUNC 0x0001/* ACL was truncated */ struct nfs_getaclres {struct nfs4_sequence_res seq_res; +const struct nfs_server * server;size_t acl_len; -size_t acl_data_offset; -int acl_flags; +struct richacl * acl;struct page * acl_scratch; };
Signature · 1 line
2.1.0
RFC 6/39 vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD permission flags
In reply to Andreas GruenbacherNormally, 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
RFC 7/39 vfs: Make the inode passed to inode_change_ok non-const
In reply to Andreas GruenbacherWe 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
RFC 12/39 richacl: Update the file masks in chmod()
In reply to Andreas GruenbacherDoing 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
@@ -301,3 +301,43 @@ restart: acl->a_flags &= ~RICHACL_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 ) | +RICHACE_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 &RICHACL_MASKED )) +return acl; + + clone =richacl_clone (acl,GFP_KERNEL ); +richacl_put (acl); +if (!clone) +return ERR_PTR (-ENOMEM ); + + clone->a_flags |=RICHACL_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
@@ -289,5 +289,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
RFC 14/39 vfs: Cache base_acl objects in inodes
In reply to Andreas GruenbacherPOSIX 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
@@ -168,7 +168,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
RFC 20/39 vfs: Add richacl permission checking
In reply to Andreas GruenbacherHook 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
@@ -35,6 +35,7 @@#include <linux/fs_struct.h> #include <linux/posix_acl.h> #include <linux/hash.h> +#include <linux/richacl.h> #include <asm/uaccess.h> #include "internal.h"
@@ -256,7 +257,40 @@ void putname(struct filename *name)__putname (name); } -static int check_acl (struct inode *inode,int mask) +static int check_richacl (struct inode *inode,int mask) +{ +#ifdef CONFIG_FS_RICHACL +struct richacl *acl; + +if (mask &MAY_NOT_BLOCK ) { + acl =get_cached_richacl_rcu (inode); +if (!acl) + goto no_acl; +/* no ->get_richacl() calls in RCU mode... */ +if (acl ==ACL_NOT_CACHED ) +return -ECHILD ; +return richacl_permission (inode, acl, mask & ~MAY_NOT_BLOCK ); + } + + acl =get_richacl (inode); +if (IS_ERR (acl)) +return PTR_ERR (acl); +if (acl) { +int error =richacl_permission (inode, acl, mask); +richacl_put (acl); +return error; + } +no_acl: +#endif +if (mask & (MAY_DELETE_SELF |MAY_TAKE_OWNERSHIP | +MAY_CHMOD |MAY_SET_TIMES )) { +/* File permission bits cannot grant this. */ +return -EACCES ; + } +return -EAGAIN ; +} + +static int check_posix_acl (struct inode *inode,int mask) {#ifdef CONFIG_FS_POSIX_ACL struct posix_acl *acl;
@@ -291,11 +325,24 @@ static int acl_permission_check(struct inode *inode, int mask) {unsigned int mode = inode->i_mode; +/* +* With POSIX ACLs, the (mode & S_IRWXU) bits exactly match the owner +* permissions, and we can skip checking posix acls for the owner. +* With richacls, the owner may be granted fewer permissions than the +* mode bits seem to suggest (for example, append but not write), and +* we always need to check the richacl. +*/ + +if (IS_RICHACL (inode)) { +int error =check_richacl (inode, mask); +if (error != -EAGAIN ) +return error; + }if (likely (uid_eq (current_fsuid (), inode->i_uid))) mode >>=6 ;else {if (IS_POSIXACL (inode) && (mode &S_IRWXG )) { -int error =check_acl (inode, mask); +int error =check_posix_acl (inode, mask);if (error != -EAGAIN )return error; }
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
RFC 21/39 ext4: Add richacl support
In reply to Andreas GruenbacherFrom: "Aneesh Kumar K.V" <[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 | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/richacl.h | 47 ++++++++++++ fs/ext4/xattr.c | 6 ++ fs/ext4/xattr.h | 1 + 12 files changed, 314 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 +211 -0
211 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
RFC 32/39 nfsd: Use richacls as internal acl representation
In reply to Andreas GruenbacherWhen converting from NFSv4 ACLs to POSIX ACLs, nfsd so far was using struct nfs4_acl as its internal representation. This representation is a subset of richacls, so get rid of struct nfs4_acl. Richacls even have a more compact in-memory representation, so a few more ACL entries can easily be supported.
--- fs/Kconfig | 6 + fs/nfs_common/Makefile | 1 + fs/nfs_common/nfs4acl.c | 41 ++++++ fs/nfsd/Kconfig | 1 + fs/nfsd/acl.h | 24 ++-- fs/nfsd/nfs4acl.c | 372 ++++++++++++++++++++++-------------------------- fs/nfsd/nfs4proc.c | 15 +- fs/nfsd/nfs4xdr.c | 64 +++------ fs/nfsd/xdr4.h | 6 +- include/linux/nfs4.h | 23 --- include/linux/nfs4acl.h | 7 + 11 files changed, 271 insertions(+), 289 deletions(-) create mode 100644 fs/nfs_common/nfs4acl.c create mode 100644 include/linux/nfs4acl.h
fs/Kconfig +6 -0
@@ -268,6 +268,12 @@ config NFS_COMMON depends on NFSD || NFS_FS || LOCKD default y +config NFS_RICHACL + bool + depends on NFSD_V4 || NFS_V4 + select FS_RICHACL + default y + source "net/sunrpc/Kconfig" source "fs/ceph/Kconfig" source "fs/cifs/Kconfig"
fs/nfs_common/Makefile +1 -0
@@ -4,5 +4,6 @@ obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o nfs_acl-objs := nfsacl.o +obj-$(CONFIG_NFS_RICHACL) += nfs4acl.o obj-$(CONFIG_GRACE_PERIOD) += grace.o
fs/nfs_common/nfs4acl.c new file +41 -0
41 lines not on this page · raw message
fs/nfsd/Kconfig +1 -0
@@ -69,6 +69,7 @@ config NFSD_V4 depends on NFSD && PROC_FS select NFSD_V3 select FS_POSIX_ACL + select FS_RICHACL select SUNRPC_GSS select CRYPTO select GRACE_PERIOD
fs/nfsd/acl.h +13 -11
@@ -35,25 +35,27 @@#ifndef LINUX_NFS4_ACL_H #define LINUX_NFS4_ACL_H -struct nfs4_acl ; +struct richacl ; +struct richace ;struct svc_fh ;struct svc_rqst ;/* * Maximum ACL we'll accept from a client; chosen (somewhat * arbitrarily) so that kmalloc'ing the ACL shouldn't require a -* high-order allocation. This allows 204 ACEs on x86_64: +* high-order allocation. This allows 339 ACEs on x86_64: */ -#define NFS4_ACL_MAX ((PAGE_SIZE - sizeof(struct nfs4_acl)) \ - / sizeof(struct nfs4_ace)) +#define NFSD4_ACL_MAX ((PAGE_SIZE - sizeof(struct richacl)) \ + / sizeof(struct richace)) -int nfs4_acl_bytes (int entries); -int nfs4_acl_get_whotype (char *,u32 ); -__be32 nfs4_acl_write_who (struct xdr_stream *xdr,int who); +__be32 nfsd4_decode_ace_who (struct richace *ace,struct svc_rqst *rqstp, +char *who,u32 len); +__be32 nfsd4_encode_ace_who (struct xdr_stream *xdr,struct svc_rqst *rqstp, +struct richace *ace); -int nfsd4_get_nfs4_acl (struct svc_rqst *rqstp,struct dentry *dentry, -struct nfs4_acl **acl); -__be32 nfsd4_set_nfs4_acl (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfs4_acl *acl); +int nfsd4_get_acl (struct svc_rqst *rqstp,struct dentry *dentry, +struct richacl **acl); +__be32 nfsd4_set_acl (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct richacl *acl);#endif /* LINUX_NFS4_ACL_H */
fs/nfsd/nfs4acl.c +170 -202
621 lines not on this page · raw message
fs/nfsd/nfs4proc.c +7 -8
@@ -159,12 +159,12 @@ is_create_with_attrs(struct nfsd4_open *open)* in the returned attr bitmap. */ static void -do_set_nfs4_acl (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfs4_acl *acl,u32 *bmval) +do_set_acl (struct svc_rqst *rqstp,struct svc_fh *fhp,struct richacl *acl, +u32 *bmval) {__be32 status; - status =nfsd4_set_nfs4_acl (rqstp, fhp, acl); + status =nfsd4_set_acl (rqstp, fhp, acl);if (status)/* * We should probably fail the whole open at this point,
@@ -299,7 +299,7 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru goto out;if (is_create_with_attrs (open) && open->op_acl !=NULL ) -do_set_nfs4_acl (rqstp, *resfh, open->op_acl, open->op_bmval); +do_set_acl (rqstp, *resfh, open->op_acl, open->op_bmval);nfsd4_set_open_owner_reply_cache (cstate, open, *resfh); accmode =NFSD_MAY_NOP ;
@@ -674,8 +674,7 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,nfsd4_security_inode_setsecctx (&resfh, &create->cr_label, create->cr_bmval);if (create->cr_acl !=NULL ) -do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, - create->cr_bmval); +do_set_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);fh_unlock (&cstate->current_fh);set_change_info (&create->cr_cinfo, &cstate->current_fh);
@@ -942,8 +941,8 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out;if (setattr->sa_acl !=NULL ) - status =nfsd4_set_nfs4_acl (rqstp, &cstate->current_fh, - setattr->sa_acl); + status =nfsd4_set_acl (rqstp, &cstate->current_fh, + setattr->sa_acl);if (status) goto out;if (setattr->sa_label.len)
fs/nfsd/nfs4xdr.c +22 -42
130 lines not on this page · raw message
fs/nfsd/xdr4.h +3 -3
@@ -119,7 +119,7 @@ struct nfsd4_create {u32 cr_bmval[3 ];/* request */ struct iattr cr_iattr;/* request */ struct nfsd4_change_info cr_cinfo;/* response */ -struct nfs4_acl *cr_acl; +struct richacl *cr_acl;struct xdr_netobj cr_label; };#define cr_datalen u.link.datalen
@@ -248,7 +248,7 @@ struct nfsd4_open {struct nfs4_openowner *op_openowner;/* used during processing */ struct nfs4_file *op_file;/* used during processing */ struct nfs4_ol_stateid *op_stp;/* used during processing */ -struct nfs4_acl *op_acl; +struct richacl *op_acl;struct xdr_netobj op_label; };
@@ -331,7 +331,7 @@ struct nfsd4_setattr {stateid_t sa_stateid;/* request */ u32 sa_bmval[3 ];/* request */ struct iattr sa_iattr;/* request */ -struct nfs4_acl *sa_acl; +struct richacl *sa_acl;struct xdr_netobj sa_label; };
include/linux/nfs4.h +0 -23
@@ -16,29 +16,6 @@#include <linux/uidgid.h> #include <uapi/linux/nfs4.h> -enum nfs4_acl_whotype { -NFS4_ACL_WHO_NAMED =0 , -NFS4_ACL_WHO_OWNER , -NFS4_ACL_WHO_GROUP , -NFS4_ACL_WHO_EVERYONE , -}; - -struct nfs4_ace { -uint32_t type; -uint32_t flag; -uint32_t access_mask; -int whotype; -union { -kuid_t who_uid; -kgid_t who_gid; - }; -}; - -struct nfs4_acl { -uint32_t naces; -struct nfs4_ace aces[0 ]; -}; -#define NFS4_MAXLABELLEN 2048struct nfs4_label {
include/linux/nfs4acl.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __LINUX_NFS4ACL_H +#define __LINUX_NFS4ACL_H + +int nfs4acl_who_to_special_id (const char *,u32 ); +bool nfs4acl_special_id_to_who (unsigned int ,const char **,unsigned int *); + +#endif
Signature · 1 line
2.1.0
RFC 33/39 nfsd: Add richacl support
In reply to Andreas GruenbacherOn file systems with richacls enabled, get and set richacls directly instead of converting from / to posix acls.
--- fs/nfsd/nfs4acl.c | 89 ++++++++++++++++++++++++++++++++++++++++++++---------- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4xdr.c | 21 ++++++++++--- 3 files changed, 91 insertions(+), 21 deletions(-)
fs/nfsd/nfs4acl.c +73 -16
@@ -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 **acif (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)
fs/nfsd/nfs4proc.c +1 -1
@@ -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; }
fs/nfsd/nfs4xdr.c +17 -4
@@ -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 ;
Signature · 1 line
2.1.0
RFC 35/39 nfs/sunrpc: Return status code from encode functions
In reply to Andreas GruenbacherReturn a status code from the sunrpc xdr encode functions. While these functions were originally returning a status code before commit 9f06c719 from December 2010, it was found that none of them can actually fail and so they were turned into void functions. With more complex objects like NFSv4 ACLs to encode, it makes sense to do memory allocations and some of the error checking inside the encode functions, so those functions may fail.
--- fs/lockd/clnt4xdr.c | 42 +++--- fs/lockd/clntxdr.c | 42 +++--- fs/lockd/mon.c | 10 +- fs/nfs/mount_clnt.c | 3 +- fs/nfs/nfs2xdr.c | 84 ++++++----- fs/nfs/nfs3xdr.c | 133 +++++++++-------- fs/nfs/nfs4xdr.c | 292 ++++++++++++++++++++++---------------- fs/nfsd/nfs4callback.c | 17 ++- include/linux/sunrpc/xdr.h | 2 +- net/sunrpc/auth.c | 7 +- net/sunrpc/auth_gss/gss_rpc_xdr.c | 7 +- net/sunrpc/auth_gss/gss_rpc_xdr.h | 6 +- net/sunrpc/clnt.c | 3 +- net/sunrpc/rpcb_clnt.c | 10 +- 14 files changed, 380 insertions(+), 278 deletions(-)
fs/lockd/clnt4xdr.c +24 -18
@@ -379,9 +379,9 @@ static void encode_nlm4_lock(struct xdr_stream *xdr,* struct nlm4_lock alock; * }; */ -static void nlm4_xdr_enc_testargs (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nlm4_xdr_enc_testargs (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;
@@ -389,6 +389,7 @@ static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,encode_cookie (xdr, &args->cookie);encode_bool (xdr, lock->fl.fl_type ==F_WRLCK );encode_nlm4_lock (xdr, lock); +return 0 ; }/*
@@ -401,9 +402,9 @@ static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,* int state; * }; */ -static void nlm4_xdr_enc_lockargs (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nlm4_xdr_enc_lockargs (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;
@@ -414,6 +415,7 @@ static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,encode_nlm4_lock (xdr, lock);encode_bool (xdr, args->reclaim);encode_int32 (xdr, args->state); +return 0 ; }/*
@@ -424,9 +426,9 @@ static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,* struct nlm4_lock alock; * }; */ -static void nlm4_xdr_enc_cancargs (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nlm4_xdr_enc_cancargs (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;
@@ -435,6 +437,7 @@ static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,encode_bool (xdr, args->block);encode_bool (xdr, lock->fl.fl_type ==F_WRLCK );encode_nlm4_lock (xdr, lock); +return 0 ; }/*
@@ -443,15 +446,16 @@ static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,* struct nlm4_lock alock; * }; */ -static void nlm4_xdr_enc_unlockargs (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nlm4_xdr_enc_unlockargs (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nlm_args *args = obj;const struct nlm_lock *lock = &args->lock;encode_cookie (xdr, &args->cookie);encode_nlm4_lock (xdr, lock); +return 0 ; }/*
@@ -460,13 +464,14 @@ static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,* nlm4_stat stat; * }; */ -static void nlm4_xdr_enc_res (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nlm4_xdr_enc_res (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nlm_res *result = obj;encode_cookie (xdr, &result->cookie);encode_nlm4_stat (xdr, result->status); +return 0 ; }/*
@@ -482,15 +487,16 @@ static void nlm4_xdr_enc_res(struct rpc_rqst *req,* nlm4_testrply test_stat; * }; */ -static void nlm4_xdr_enc_testres (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nlm4_xdr_enc_testres (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nlm_res *result = obj;encode_cookie (xdr, &result->cookie);encode_nlm4_stat (xdr, result->status);if (result->status == nlm_lck_denied)encode_nlm4_holder (xdr, result); +return 0 ; }
fs/lockd/clntxdr.c +24 -18
111 lines not on this page · raw message
fs/lockd/mon.c +6 -4
@@ -526,19 +526,21 @@ static void encode_priv(struct xdr_stream *xdr, const struct nsm_args *argp)xdr_encode_opaque_fixed (p, argp->priv->data,SM_PRIV_SIZE ); } -static void nsm_xdr_enc_mon (struct rpc_rqst *req,struct xdr_stream *xdr, -void *obj) +static int nsm_xdr_enc_mon (struct rpc_rqst *req,struct xdr_stream *xdr, +void *obj) {const struct nsm_args *argp = obj;encode_mon_id (xdr, argp);encode_priv (xdr, argp); +return 0 ; } -static void nsm_xdr_enc_unmon (struct rpc_rqst *req,struct xdr_stream *xdr, -void *obj) +static int nsm_xdr_enc_unmon (struct rpc_rqst *req,struct xdr_stream *xdr, +void *obj) {const struct nsm_args *argp = obj;encode_mon_id (xdr, argp); +return 0 ; } static int nsm_xdr_dec_stat_res(struct rpc_rqst *rqstp,
fs/nfs/mount_clnt.c +2 -1
@@ -305,11 +305,12 @@ static void encode_mntdirpath(struct xdr_stream *xdr, const char *pathname)xdr_encode_opaque (p, pathname, pathname_len); } -static void mnt_xdr_enc_dirpath (struct rpc_rqst *req,struct xdr_stream *xdr, +static int mnt_xdr_enc_dirpath (struct rpc_rqst *req,struct xdr_stream *xdr,void *obj) {const char *dirpath = obj;encode_mntdirpath (xdr, dirpath); +return 0 ; }/*
fs/nfs/nfs2xdr.c +48 -36
196 lines not on this page · raw message
fs/nfs/nfs3xdr.c +76 -57
324 lines not on this page · raw message
fs/nfs/nfs4xdr.c +171 -121
849 lines not on this page · raw message
fs/nfsd/nfs4callback.c +10 -7
@@ -476,17 +476,18 @@ out_default:/* * NB: Without this zero space reservation, callbacks over krb5p fail */ -static void nfs4_xdr_enc_cb_null (struct rpc_rqst *req,struct xdr_stream *xdr, -void *__unused) +static int nfs4_xdr_enc_cb_null (struct rpc_rqst *req,struct xdr_stream *xdr, +void *__unused) {xdr_reserve_space (xdr,0 ); +return 0 ; }/* * 20.2. Operation 4: CB_RECALL - Recall a Delegation */ -static void nfs4_xdr_enc_cb_recall (struct rpc_rqst *req,struct xdr_stream *xdr, -void *obj) +static int nfs4_xdr_enc_cb_recall (struct rpc_rqst *req,struct xdr_stream *xdr, +void *obj) {const struct nfsd4_callback *cb = obj;const struct nfs4_delegation *dp =cb_to_delegation (cb);
@@ -499,6 +500,7 @@ static void nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, struct xdr_stream *xdr,encode_cb_sequence4args (xdr, cb, &hdr);encode_cb_recall4args (xdr, dp, &hdr);encode_cb_nops (&hdr); +return 0 ; }
@@ -601,9 +603,9 @@ static void encode_cb_layout4args(struct xdr_stream *xdr, hdr->nops++; } -static void nfs4_xdr_enc_cb_layout (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +static int nfs4_xdr_enc_cb_layout (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {const struct nfsd4_callback *cb = obj; const struct nfs4_layout_stateid *ls =
@@ -617,6 +619,7 @@ static void nfs4_xdr_enc_cb_layout(struct rpc_rqst *req,encode_cb_sequence4args (xdr, cb, &hdr);encode_cb_layout4args (xdr, ls, &hdr);encode_cb_nops (&hdr); +return 0 ; } static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp,
include/linux/sunrpc/xdr.h +1 -1
@@ -211,7 +211,7 @@ struct xdr_stream {* These are the xdr_stream style generic XDR encode and decode functions. */ struct rpc_rqst ; -typedef void (*kxdreproc_t )(struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj); +typedef int (*kxdreproc_t )(struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj);typedef int (*kxdrdproc_t )(struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj);extern void xdr_init_encode (struct xdr_stream *xdr,struct xdr_buf *buf,__be32 *p);
net/sunrpc/auth.c +3 -4
@@ -767,13 +767,13 @@ rpcauth_checkverf(struct rpc_task *task, __be32 *p)return cred->cr_ops->crvalidate (task, p); } -static void rpcauth_wrap_req_encode (kxdreproc_t encode,struct rpc_rqst *rqstp, +static int rpcauth_wrap_req_encode (kxdreproc_t encode,struct rpc_rqst *rqstp,__be32 *data,void *obj) {struct xdr_stream xdr;xdr_init_encode (&xdr, &rqstp->rq_snd_buf, data); -encode (rqstp, &xdr, obj); +return encode (rqstp, &xdr, obj); }int
@@ -787,8 +787,7 @@ rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp,if (cred->cr_ops->crwrap_req)return cred->cr_ops->crwrap_req (task, encode, rqstp, data, obj);/* By default, we encode the arguments normally. */ -rpcauth_wrap_req_encode (encode, rqstp, data, obj); -return 0 ; +return rpcauth_wrap_req_encode (encode, rqstp, data, obj); } static int
net/sunrpc/auth_gss/gss_rpc_xdr.c +4 -3
@@ -731,9 +731,9 @@ static int gssx_enc_cb(struct xdr_stream *xdr, struct gssx_cb *cb)return err; } -void gssx_enc_accept_sec_context (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *obj) +int gssx_enc_accept_sec_context (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *obj) {struct gssx_arg_accept_sec_context *arg = obj;int err;
@@ -786,6 +786,7 @@ void gssx_enc_accept_sec_context(struct rpc_rqst *req, done:if (err)dprintk ("RPC: gssx_enc_accept_sec_context: %d\n" , err); +return 0 ; } int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
net/sunrpc/auth_gss/gss_rpc_xdr.h +3 -3
@@ -177,9 +177,9 @@ struct gssx_res_accept_sec_context {#define gssx_dec_store_cred NULL#define gssx_enc_init_sec_context NULL#define gssx_dec_init_sec_context NULL -void gssx_enc_accept_sec_context (struct rpc_rqst *req, -struct xdr_stream *xdr, -void *); +int gssx_enc_accept_sec_context (struct rpc_rqst *req, +struct xdr_stream *xdr, +void *);int gssx_dec_accept_sec_context (struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *);
net/sunrpc/clnt.c +2 -1
@@ -2392,8 +2392,9 @@ out_overflow: goto out_garbage; } -static void rpcproc_encode_null (struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj) +static int rpcproc_encode_null (struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj) { +return 0 ; }static int rpcproc_decode_null (struct rpc_rqst *rqstp,struct xdr_stream *xdr,void *obj)
net/sunrpc/rpcb_clnt.c +6 -4
@@ -844,8 +844,8 @@ static void rpcb_getport_done(struct rpc_task *child, void *data)* XDR functions for rpcbind */ -static void rpcb_enc_mapping (struct rpc_rqst *req,struct xdr_stream *xdr, -void *obj) +static int rpcb_enc_mapping (struct rpc_rqst *req,struct xdr_stream *xdr, +void *obj) {const struct rpcbind_args *rpcb = obj;__be32 *p;
@@ -860,6 +860,7 @@ static void rpcb_enc_mapping(struct rpc_rqst *req, struct xdr_stream *xdr, *p++ =cpu_to_be32 (rpcb->r_vers); *p++ =cpu_to_be32 (rpcb->r_prot); *p =cpu_to_be32 (rpcb->r_port); +return 0 ; } static int rpcb_dec_getport(struct rpc_rqst *req, struct xdr_stream *xdr,
@@ -921,8 +922,8 @@ static void encode_rpcb_string(struct xdr_stream *xdr, const char *string,xdr_encode_opaque (p, string, len); } -static void rpcb_enc_getaddr (struct rpc_rqst *req,struct xdr_stream *xdr, -void *obj) +static int rpcb_enc_getaddr (struct rpc_rqst *req,struct xdr_stream *xdr, +void *obj) {const struct rpcbind_args *rpcb = obj;__be32 *p;
@@ -940,6 +941,7 @@ static void rpcb_enc_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr,encode_rpcb_string (xdr, rpcb->r_netid,RPCBIND_MAXNETIDLEN );encode_rpcb_string (xdr, rpcb->r_addr,RPCBIND_MAXUADDRLEN );encode_rpcb_string (xdr, rpcb->r_owner,RPCB_MAXOWNERLEN ); +return 0 ; } static int rpcb_dec_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr,
Signature · 1 line
2.1.0
RFC 37/39 nfs: Remove unused xdr page offsets in getacl/setacl arguments
In reply to Andreas GruenbacherThe arguments passed around for getacl and setacl xdr encoding, struct nfs_setaclargs and struct nfs_getaclargs, both contain an array of pages, an offset into the first page, and the length of the page data. The offset is unused as it is always zero; remove it.
--- fs/nfs/nfs4proc.c | 5 ++--- fs/nfs/nfs4xdr.c | 4 ++-- include/linux/nfs_xdr.h | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-)
fs/nfs/nfs4proc.c +2 -3
@@ -4440,7 +4440,7 @@ static inline int nfs4_server_supports_acls(struct nfs_server *server)#define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)static int buf_to_pages_noslab (const void *buf,size_t buflen, -struct page **pages,unsigned int *pgbase) +struct page **pages) {struct page *newpage, **spages;int rc =0 ;
@@ -4584,7 +4584,6 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu goto out_free; args.acl_len = npages *PAGE_SIZE ; - args.acl_pgbase =0 ;dprintk ("%s buf %p buflen %zu npages %d args.acl_len %zu\n" , __func__, buf, buflen, npages, args.acl_len);
@@ -4676,7 +4675,7 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflreturn -EOPNOTSUPP ;if (npages >ARRAY_SIZE (pages))return -ERANGE ; - i =buf_to_pages_noslab (buf, buflen, arg.acl_pages, &arg.acl_pgbase); + i =buf_to_pages_noslab (buf, buflen, arg.acl_pages);if (i <0 )return i;nfs4_inode_return_delegation (inode);
fs/nfs/nfs4xdr.c +2 -2
@@ -1644,7 +1644,7 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun *p =cpu_to_be32 (FATTR4_WORD0_ACL ); p =reserve_space (xdr,4 ); *p =cpu_to_be32 (arg->acl_len); -xdr_write_pages (xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); +xdr_write_pages (xdr, arg->acl_pages,0 , arg->acl_len); } static void
@@ -2517,7 +2517,7 @@ static int nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,encode_getattr_two (xdr,FATTR4_WORD0_ACL ,0 , &hdr);xdr_inline_pages (&req->rq_rcv_buf, replen <<2 , - args->acl_pages, args->acl_pgbase, args->acl_len); + args->acl_pages,0 , args->acl_len);encode_nops (&hdr);return 0 ;
include/linux/nfs_xdr.h +0 -2
@@ -640,7 +640,6 @@ struct nfs_setaclargs {struct nfs4_sequence_args seq_args;struct nfs_fh * fh;size_t acl_len; -unsigned int acl_pgbase;struct page ** acl_pages; };
@@ -652,7 +651,6 @@ struct nfs_getaclargs {struct nfs4_sequence_args seq_args;struct nfs_fh * fh;size_t acl_len; -unsigned int acl_pgbase;struct page ** acl_pages; };
Signature · 1 line
2.1.0
cover Richacls (2)
In reply to a message not in the archiveAdding cc: to linux-cifs mailing list
This will be useful for cifs to have a standard VFS mapping to get at our RichACL interfaces, currently only available via a cifs specific xattr.
---------- Forwarded message ----------
From: Andreas Gruenbacher <[email protected]>
Date: Fri, Mar 27, 2015 at 11:49 AM
Subject: [RFC 00/39] Richacls (2)
To: [email protected], [email protected], [email protected], [email protected], samba-technical-w/[email protected], Steve French <[email protected]>, [email protected]
Hello,
here is an update to the richacl patch queue. The changes since the last posting (https://lwn.net/Articles/634870/) include:
* The ACL4_ and ACE4_ prefixes used for various richacl flags were renamed to RICHACL_ and RICHACE_. The flag values are still identical with NFSv4 for flags that exist in NFSv4.
* The code is now uid/gid namespace aware.
* The nfs server now uses richacls as its internal acl representation; struct nfs4_acl is gone. On the underlying file system, it uses either POSIX ACLs or richacls depending on what that file system supports.
* The nfs client now exports NFSv4 acls as richacls in the "system.richacl" attribute instead of the nfs-specific "system.nfs4_acl" attribute, just like local file systems.
Note that the richacl xattr format has changed from the previous version and is incompatible.
The git version is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git \
richacl-2015-03-27For comparison, the previous version is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git \
richacl-2015-02-26Things still to be done, or which I'm not entirely happy with:
* We may need to add back support for the "system.nfs4_acl" attribute on nfs mounts for backwards compatible. Is anyone actually using that attribute?
* While richacls do support Automatic Inheritance, the nfs client and server don't because they don't support the NFSv4.1 "dacl" attribute yet (see RFC 5661).
* The nfs server performs some access checking on its own before calling into the vfs which is rersponsible for the actual access checking (see where it calls inode_permission()). With the additional MAY_ flags introduced in this patch queue, the nfsd access checks may now be too restrictive in some cases; I have yet to figure out how to deal with this.
* It would make sense for CIFS to expose Windows ACLs as richacls as well. Steve maybe?
* The base_acl code is still rather ugly.
* 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.
Andreas Gruenbacher (37):
vfs: Minor documentation fix
uapi: Remove kernel internal declaration
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
vfs: Cache base_acl objects in inodes
vfs: Cache richacl in struct inode
richacl: Create-time inheritance
richacl: Check if an acl is equivalent to a file mode
richacl: Automatic Inheritance
richacl: xattr mapping functions
vfs: Add richacl permission checking
richacl: acl editing helper functions
richacl: Move everyone@ aces down the acl
richacl: Propagate everyone@ permissions to other aces
richacl: Isolate the owner and group classes
richacl: Apply the file masks to a richacl
richacl: Create richacl from mode values
richacl: Create acl with masks applied in richacl_from_mode()
nfsd: Remove dead declarations
nfsd: Keep list of acls to dispose of in compoundargs
nfsd: Use richacls as internal acl representation
nfsd: Add richacl support
nfs/sunrpc: No more encode and decode function pointer casting nfs/sunrpc: Return status code from encode functions
nfs3: Return posix acl encode errors
nfs: Remove unused xdr page offsets in getacl/setacl arguments
rpc: Allow to demand-allocate pages to encode into
nfs: Add richacl support
Aneesh Kumar K.V (2):
ext4: Add richacl support
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 | 9 + fs/Makefile | 3 + 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 | 211 ++++++ 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/lockd/clnt4xdr.c | 58 +- fs/lockd/clntxdr.c | 58 +- fs/lockd/mon.c | 26 +- fs/namei.c | 108 ++- fs/nfs/inode.c | 2 +- fs/nfs/mount_clnt.c | 24 +- fs/nfs/nfs2xdr.c | 115 ++-- fs/nfs/nfs3xdr.c | 225 ++++--- fs/nfs/nfs4proc.c | 335 +++++----- fs/nfs/nfs4xdr.c | 699 ++++++++++++++------ fs/nfs/super.c | 4 +- fs/nfs_common/Makefile | 1 + fs/nfs_common/nfs4acl.c | 41 ++ fs/nfsd/Kconfig | 1 + fs/nfsd/acl.h | 24 +- fs/nfsd/nfs4acl.c | 467 ++++++------- fs/nfsd/nfs4callback.c | 29 +- fs/nfsd/nfs4proc.c | 17 +- fs/nfsd/nfs4xdr.c | 103 +-- fs/nfsd/xdr4.h | 12 +- fs/posix_acl.c | 31 +- fs/richacl_base.c | 549 ++++++++++++++++ fs/richacl_compat.c | 835 ++++++++++++++++++++++++ fs/richacl_inode.c | 195 ++++++ fs/richacl_xattr.c | 210 ++++++ fs/xattr.c | 34 +- include/linux/fs.h | 47 +- include/linux/nfs4.h | 16 - include/linux/nfs4acl.h | 7 + include/linux/nfs_fs.h | 2 +- include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 8 +- include/linux/posix_acl.h | 12 +- include/linux/richacl.h | 330 ++++++++++ include/linux/richacl_compat.h | 40 ++ include/linux/richacl_xattr.h | 52 ++ include/linux/sunrpc/xdr.h | 5 +- include/uapi/linux/fs.h | 3 +- include/uapi/linux/nfs4.h | 7 - include/uapi/linux/xattr.h | 2 + net/sunrpc/auth.c | 7 +- net/sunrpc/auth_gss/gss_rpc_upcall.c | 4 +- net/sunrpc/auth_gss/gss_rpc_xdr.c | 11 +- net/sunrpc/auth_gss/gss_rpc_xdr.h | 8 +- net/sunrpc/clnt.c | 5 +- net/sunrpc/rpcb_clnt.c | 57 +- net/sunrpc/xdr.c | 8 + 69 files changed, 4283 insertions(+), 1059 deletions(-) create mode 100644 fs/ext4/richacl.c create mode 100644 fs/ext4/richacl.h create mode 100644 fs/nfs_common/nfs4acl.c create mode 100644 fs/richacl_base.c create mode 100644 fs/richacl_compat.c create mode 100644 fs/richacl_inode.c create mode 100644 fs/richacl_xattr.c create mode 100644 include/linux/nfs4acl.h create mode 100644 include/linux/richacl.h create mode 100644 include/linux/richacl_compat.h create mode 100644 include/linux/richacl_xattr.h
--
2.1.0
Signature · 3 lines
Thanks, Steve
Re: [RFC 02/39] uapi: Remove kernel internal declaration
In reply to Andreas GruenbacherQuoted 2 lines · Andreas Gruenbacher
The enum
nfs4_acl_whotypeis only used in nfs4d's internal nfs4 acl representation. No longer expose it to user space.
I'll go ahead and apply that now.
--b.
Quoted 50 lines
Signed-off-by Andreas Gruenbacher <[email protected]>--- include/linux/nfs4.h | 7 +++++++ include/uapi/linux/nfs4.h | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-)include/linux/nfs4.h +7
-0@@ -16,6 +16,13 @@#include <linux/uidgid.h> #include <uapi/linux/nfs4.h> +enum nfs4_acl_whotype { +NFS4_ACL_WHO_NAMED =0 , +NFS4_ACL_WHO_OWNER , +NFS4_ACL_WHO_GROUP , +NFS4_ACL_WHO_EVERYONE , +}; +struct nfs4_ace {uint32_t type;uint32_t flag;include/uapi/linux/nfs4.h +0
-7@@ -162,13 +162,6 @@*/ #define NFS4_MAX_BACK_CHANNEL_OPS 2 -enum nfs4_acl_whotype { -NFS4_ACL_WHO_NAMED =0 , -NFS4_ACL_WHO_OWNER , -NFS4_ACL_WHO_GROUP , -NFS4_ACL_WHO_EVERYONE , -}; -#endif /* _UAPI_LINUX_NFS4_H */ /* Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 11/39] richacl: Compute maximum file masks from an acl
In reply to Andreas GruenbacherQuoted 103 lines · Andreas Gruenbacher
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().Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/richacl_base.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 129 insertions(+)fs/richacl_base.c +77
-0@@ -173,3 +173,131 @@ richacl_want_to_mask(unsigned int want)return mask; }EXPORT_SYMBOL_GPL (richacl_want_to_mask); + +/** +* richacl_allowed_to_who - mask flags allowed to a specific who value +* +* Computes the mask values allowed to a specific who value, taking +* EVERYONE@ entries into account. +*/ +static unsigned int richacl_allowed_to_who (struct richacl *acl, +struct richace *who) +{ +struct richace *ace; +unsigned int allowed =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_same_identifier (ace, who) || +richace_is_everyone (ace)) { +if (richace_is_allow (ace)) + allowed |= ace->e_mask; +else if (richace_is_deny (ace)) + allowed &= ~ace->e_mask; + } + } +return allowed; +} + +/** +* richacl_group_class_allowed - maximum permissions the group class is allowed +* +* See richacl_compute_max_masks(). +*/ +static unsigned int richacl_group_class_allowed (struct richacl *acl) +{ +struct richace *ace; +unsigned int everyone_allowed =0 , group_class_allowed =0 ; +int had_group_ace =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace) || +richace_is_owner (ace)) +continue ; + +if (richace_is_everyone (ace)) { +if (richace_is_allow (ace)) + everyone_allowed |= ace->e_mask; +else if (richace_is_deny (ace)) + everyone_allowed &= ~ace->e_mask; + }else { + group_class_allowed |= +richacl_allowed_to_who (acl, ace); + +if (richace_is_group (ace)) + had_group_ace =1 ; + } + } +if (!had_group_ace) + group_class_allowed |= everyone_allowed; +return group_class_allowed; +} + +/** +* richacl_compute_max_masks - compute upper bound masks +* +* Computes upper bound owner, group, and other masks so that none of +* the mask flags allowed by the acl are disabled (for any choice of the +* file owner or group membership). +*/ +void richacl_compute_max_masks (struct richacl *acl) +{ +unsigned int gmask = ~0 ; +struct richace *ace; + +/* +* @gmask contains all permissions which the group class is ever +* allowed. We use it to avoid adding permissions to the group mask +* from everyone@ allow aces which the group class is always denied
fs/richacl_base.c richacl_want_to_mask(unsigned int want) · line 262
Quoted 10 lines
fs/richacl_base.c +10
-0+* through other aces. For example, the following acl would otherwise +* result in a group mask or rw: +* +* group@:w::deny +* everyone@:rw::allow +* +* Avoid computing @gmask for acls which do not include any group class +* deny aces: in such acls, the group class is never denied any +* permissions from everyone@ allow aces. +*/
Cripes, by the time I got to this point I'd already written one response where I complained this was wrong, another where I explained why it was right, and gone back and forth a couple more times.
Feel free to add a
but maybe we could use a couple more examples here. Or a paper.
--b.
Quoted 59 lines
fs/richacl_base.c +41
-0+ +restart: + acl->a_owner_mask =0 ; + acl->a_group_mask =0 ; + acl->a_other_mask =0 ; + +richacl_for_each_entry_reverse (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; + +if (richace_is_owner (ace)) { +if (richace_is_allow (ace)) + acl->a_owner_mask |= ace->e_mask; +else if (richace_is_deny (ace)) + acl->a_owner_mask &= ~ace->e_mask; + }else if (richace_is_everyone (ace)) { +if (richace_is_allow (ace)) { + acl->a_owner_mask |= ace->e_mask; + acl->a_group_mask |= ace->e_mask & gmask; + acl->a_other_mask |= ace->e_mask; + }else if (richace_is_deny (ace)) { + acl->a_owner_mask &= ~ace->e_mask; + acl->a_group_mask &= ~ace->e_mask; + acl->a_other_mask &= ~ace->e_mask; + } + }else { +if (richace_is_allow (ace)) { + acl->a_owner_mask |= ace->e_mask & gmask; + acl->a_group_mask |= ace->e_mask & gmask; + }else if (richace_is_deny (ace) && gmask == ~0 ) { + gmask =richacl_group_class_allowed (acl); +if (likely (gmask != ~0 )) +/* should always be true */ + goto restart; + } + } + } + + acl->a_flags &= ~RICHACL_MASKED ; +} +EXPORT_SYMBOL_GPL (richacl_compute_max_masks);include/linux/richacl.h +1
-0@@ -288,5 +288,6 @@ extern struct richacl *richacl_alloc(int, gfp_t);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 · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC 11/39] richacl: Compute maximum file masks from an acl
2015-04-20 23:28 GMT+02:00 J. Bruce Fields <[email protected]>:
Quoted 9 lines
Cripes, by the time I got to this point I'd already written one response where I complained this was wrong, another where I explained why it was right, and gone back and forth a couple more times.
Feel free to add a
Reviewed-by J. Bruce Fields <[email protected]>but maybe we could use a couple more examples here. Or a paper.
Thanks, I've tried to explain things a little better in the updated patch queue just pushed out.
Andreas
Re: [RFC 02/39] uapi: Remove kernel internal declaration
In reply to J. Bruce Fields2015-04-20 20:57 GMT+02:00 J. Bruce Fields <[email protected]>:
Quoted 5 lines · Andreas Gruenbacher
Quoted 2 lines
The enum
nfs4_acl_whotypeis only used in nfs4d's internal nfs4 acl representation. No longer expose it to user space.I'll go ahead and apply that now.
There's other very low-hanging fruit for nfsd as well:
nfsd: Checking for acl support does not require fetching any acls
https://git.kernel.org/cgit/linux/kernel/git/agruen/linux-richacl.git/commit/?h=richacl-2015-04-24&id=b3a09e6f1071ea01de64aa3071cb533e79fb4b18
nfsd: Remove dead declarations
https://git.kernel.org/cgit/linux/kernel/git/agruen/linux-richacl.git/commit/?h=richacl-2015-04-24&id=e6e2fa620584c6e2375572191fff7337a902805a
And for nfs:
nfs: Remove unused xdr page offsets in getacl/setacl arguments
https://git.kernel.org/cgit/linux/kernel/git/agruen/linux-richacl.git/commit/?h=richacl-2015-04-24&id=082664972e957e6585c059865a397185ba7d5c88
Thanks,
Andreas