Richacls
Subsystems (12)
v10 cover Richacls
From: Andreas Gruenbacher <[email protected]>
Here is another update of the richacl patch queue. I would like to ask for feedback so that the core and local filesystem code (patches 1-24) can be merged in the 4.4 merge window. Changes since the last posting
(https://lwn.net/Articles/659350/):
* Support for xfs; this depends on a new incompatible feature flag. The user-space changes can be found here:
https://github.com/andreas-gruenbacher/xfsprogs.git
* ext4: Update ctime when setting a mode-equivalent richacl.
* The richacl_inherit_inode and richacl_create helpers now take a umode_t argument instead of an inode (xfs uses richacl_create before creating an inode). Some other minor changes.
The complete patch queue is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git \ richacl-2015-10-12
The richacl user-space utilitites and test suite are available here:
https://github.com/andreas-gruenbacher/richacl/
Some more information is avaliable here:
http://www.bestbits.at/richacl/
We still have two open issues in nfs, but those only affect nfs.
Thanks,
Andreas
Andreas Gruenbacher (44):
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: Permission check algorithm
vfs: Cache base_acl objects in inodes
vfs: Add get_richacl and set_richacl inode operations
vfs: Cache richacl in struct inode
richacl: Update the file masks in chmod()
richacl: Check if an acl is equivalent to a file mode
richacl: Create-time inheritance
richacl: Automatic Inheritance
richacl: xattr mapping functions
richacl: Add richacl xattr handler
vfs: Add richacl permission checking
xfs: Fix error path in xfs_get_acl
xfs: Make xfs_set_mode non-static
xfs: Add richacl support
richacl: acl editing helper functions
richacl: Move everyone@ aces down the acl
richacl: Propagate everyone@ permissions to other aces
richacl: Set the owner permissions to the owner mask
richacl: Set the other permissions to the other mask
richacl: Isolate the owner and group classes
richacl: Apply the file masks to a richacl
richacl: Create richacl from mode values
nfsd: Keep list of acls to dispose of in compoundargs
nfsd: Use richacls as internal acl representation
nfsd: Add richacl support
nfsd: Add support for the v4.1 dacl attribute
nfsd: Add support for the MAY_CREATE_{FILE,DIR} permissions
richacl: Add support for unmapped identifiers
ext4: Don't allow unmapped identifiers in richacls
sunrpc: Allow to demand-allocate pages to encode into
sunrpc: Add xdr_init_encode_pages
nfs: Fix GETATTR bitmap verification
nfs: Remove unused xdr page offsets in getacl/setacl arguments
nfs: Add richacl support
nfs: Add support for the v4.1 dacl attribute
richacl: uapi header split
Aneesh Kumar K.V (2):
ext4: Add richacl support
ext4: Add richacl feature flag
drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- fs/Kconfig | 9 + fs/Makefile | 3 + fs/attr.c | 81 ++- fs/ext4/Kconfig | 11 + fs/ext4/Makefile | 1 + fs/ext4/ext4.h | 6 +- fs/ext4/file.c | 3 + fs/ext4/ialloc.c | 7 +- fs/ext4/inode.c | 10 +- fs/ext4/namei.c | 5 + fs/ext4/richacl.c | 133 ++++ fs/ext4/richacl.h | 42 ++ fs/ext4/super.c | 42 +- fs/ext4/xattr.c | 7 + fs/f2fs/acl.c | 4 +- fs/inode.c | 15 +- fs/jffs2/acl.c | 6 +- fs/namei.c | 111 ++- fs/nfs/inode.c | 3 - fs/nfs/nfs4proc.c | 701 +++++++++++++----- fs/nfs/nfs4xdr.c | 257 ++++++- fs/nfs/super.c | 4 +- fs/nfs_common/Makefile | 1 + fs/nfs_common/nfs4acl.c | 44 ++ fs/nfsd/Kconfig | 1 + fs/nfsd/acl.h | 23 +- fs/nfsd/nfs4acl.c | 482 +++++++------ fs/nfsd/nfs4proc.c | 25 +- fs/nfsd/nfs4xdr.c | 268 ++++--- fs/nfsd/nfsd.h | 6 +- fs/nfsd/nfsfh.c | 8 +- fs/nfsd/vfs.c | 28 +- fs/nfsd/vfs.h | 17 +- fs/nfsd/xdr4.h | 12 +- fs/posix_acl.c | 26 +- fs/richacl_base.c | 685 ++++++++++++++++++ fs/richacl_compat.c | 915 ++++++++++++++++++++++++ fs/richacl_inode.c | 333 +++++++++ fs/richacl_xattr.c | 345 +++++++++ fs/xattr.c | 34 +- fs/xfs/Kconfig | 11 + fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_format.h | 16 +- fs/xfs/xfs_acl.c | 37 +- fs/xfs/xfs_acl.h | 1 - fs/xfs/xfs_inode.c | 18 + fs/xfs/xfs_inode.h | 2 + fs/xfs/xfs_iops.c | 42 +- fs/xfs/xfs_richacl.c | 97 +++ fs/xfs/xfs_richacl.h | 34 + fs/xfs/xfs_super.c | 14 +- fs/xfs/xfs_super.h | 9 +- fs/xfs/xfs_xattr.c | 4 + include/linux/fs.h | 51 +- include/linux/nfs4.h | 24 +- include/linux/nfs4acl.h | 7 + include/linux/nfs_fs.h | 1 - include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 13 +- include/linux/posix_acl.h | 12 +- include/linux/richacl.h | 276 +++++++ include/linux/richacl_compat.h | 40 ++ include/linux/richacl_xattr.h | 49 ++ include/linux/sunrpc/xdr.h | 2 + include/uapi/linux/Kbuild | 2 + include/uapi/linux/fs.h | 3 +- include/uapi/linux/nfs4.h | 3 +- include/uapi/linux/richacl.h | 111 +++ include/uapi/linux/richacl_xattr.h | 43 ++ include/uapi/linux/xattr.h | 2 + net/sunrpc/xdr.c | 34 + 72 files changed, 4916 insertions(+), 761 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 fs/xfs/xfs_richacl.c create mode 100644 fs/xfs/xfs_richacl.h 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 create mode 100644 include/uapi/linux/richacl.h create mode 100644 include/uapi/linux/richacl_xattr.h
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 1/46 vfs: Add IS_ACL() and IS_RICHACL() tests
From: Andreas Gruenbacher <[email protected]>
The vfs does not apply the umask for file systems that support acls. The test used for this used to be called IS_POSIXACL(). Switch to a new IS_ACL() test to check for either posix acls or richacls instead. Add a new MS_RICHACL flag and IS_RICHACL() test for richacls alone. The IS_POSIXACL() test is still needed by 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
@@ -56,6 +56,9 @@ endif # BLOCK config FS_POSIX_ACL def_bool n +config FS_RICHACL + def_bool n + config EXPORTFS tristate
fs/namei.c +4 -4
@@ -2798,7 +2798,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 );
@@ -2982,7 +2982,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
@@ -3553,7 +3553,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)
@@ -3622,7 +3622,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
@@ -1781,6 +1781,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)
@@ -1794,6 +1800,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.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 2/46 vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Richacls distinguish between creating non-directories and directories. To support that, add an isdir parameter to may_create(). When checking inode_permission() for create permission, pass in an additional MAY_CREATE_FILE or MAY_CREATE_DIR mask flag.
To allow checking for delete *and* create access when replacing an existing file via vfs_rename(), add a replace parameter to may_delete().
--- fs/namei.c | 43 +++++++++++++++++++++++++------------------ include/linux/fs.h | 2 ++ 2 files changed, 27 insertions(+), 18 deletions(-)
fs/namei.c +25 -18
@@ -453,7 +453,9 @@ 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. +* MAY_WRITE must be set in @mask whenever MAY_APPEND, MAY_CREATE_FILE, or +* MAY_CREATE_DIR are set. That way, file systems that don't support these +* permissions will check for MAY_WRITE instead. */ int inode_permission (struct inode *inode,int mask) {
@@ -2549,10 +2551,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 =d_backing_inode (victim); -int error; +int error, mask =MAY_WRITE |MAY_EXEC ;if (d_is_negative (victim))return -ENOENT ;
@@ -2561,7 +2564,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))
@@ -2592,14 +2597,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); }/*
@@ -2649,7 +2656,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;
@@ -3494,7 +3501,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;
@@ -3586,7 +3593,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)
@@ -3667,7 +3674,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;
@@ -3789,7 +3796,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;
@@ -3923,7 +3930,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;
@@ -4006,7 +4013,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;
@@ -4194,19 +4201,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;
@@ -4469,7 +4476,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
@@ -82,6 +82,8 @@ typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate);#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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 3/46 vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD permission flags
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Normally, deleting a file requires MAY_WRITE access to the parent directory. With richacls, a file may be deleted with MAY_DELETE_CHILD access to the parent directory or with MAY_DELETE_SELF access to the file.
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 overrides the sticky directory check.
--- fs/namei.c | 21 ++++++++++++--------- include/linux/fs.h | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-)
fs/namei.c +12 -9
@@ -453,9 +453,9 @@ 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. * -* MAY_WRITE must be set in @mask whenever MAY_APPEND, MAY_CREATE_FILE, or -* MAY_CREATE_DIR are set. That way, file systems that don't support these -* permissions will check for MAY_WRITE instead. +* MAY_WRITE must be set in @mask whenever MAY_APPEND, MAY_CREATE_FILE, +* MAY_CREATE_DIR, or MAY_DELETE_CHILD are set. That way, file systems that +* don't support these permissions will check for MAY_WRITE instead. */ int inode_permission (struct inode *inode,int mask) {
@@ -2555,7 +2555,7 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir, bool replace) {struct inode *inode =d_backing_inode (victim); -int error, mask =MAY_WRITE |MAY_EXEC ; +int error, mask =MAY_EXEC ;if (d_is_negative (victim))return -ENOENT ;
@@ -2565,15 +2565,18 @@ 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 &&check_sticky (dir, inode)) + error = -EPERM ; +if (error &&IS_RICHACL (inode) && +inode_permission (inode,MAY_DELETE_SELF ) ==0 ) + error =0 ;if (error)return error;if (IS_APPEND (dir))return -EPERM ; - -if (check_sticky (dir, inode) ||IS_APPEND (inode) || -IS_IMMUTABLE (inode) ||IS_SWAPFILE (inode)) +if (IS_APPEND (inode) ||IS_IMMUTABLE (inode) ||IS_SWAPFILE (inode))return -EPERM ;if (isdir) {if (!d_is_dir (victim))
include/linux/fs.h +2 -0
@@ -84,6 +84,8 @@ typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate);#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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 4/46 vfs: Make the inode passed to inode_change_ok non-const
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
We will need to call iop->permission and iop->get_acl from inode_change_ok() for additional permission checks, and both take a non-const inode.
--- fs/attr.c | 2 +- include/linux/fs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/attr.c +1 -1
@@ -28,7 +28,7 @@* Should be called as the first thing in ->setattr implementations, * possibly after taking additional locks. */ -int inode_change_ok (const struct inode *inode,struct iattr *attr) +int inode_change_ok (struct inode *inode,struct iattr *attr) {unsigned int ia_valid = attr->ia_valid;
include/linux/fs.h +1 -1
@@ -2871,7 +2871,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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 5/46 vfs: Add permission flags for setting file attributes
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Richacls support permissions that allow to take ownership of a file, change the file permissions, and set the file timestamps. Support that by introducing new permission mask flags and by checking for those mask flags in inode_change_ok().
--- fs/attr.c | 79 +++++++++++++++++++++++++++++++++++++++++++++--------- include/linux/fs.h | 3 +++ 2 files changed, 70 insertions(+), 12 deletions(-)
fs/attr.c +67 -12
@@ -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
@@ -86,6 +86,9 @@ typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate);#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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 6/46 richacl: In-memory representation and helper functions
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
A richacl consists of an NFSv4 acl and an owner, group, and other mask. These three masks correspond to the owner, group, and other file permission bits, but they contain NFSv4 permissions instead of POSIX permissions.
Each entry in the NFSv4 acl applies to the file owner (OWNER@), the owning group (GROUP@), everyone (EVERYONE@), or to a specific uid or gid.
As in the standard POSIX file permission model, each process is the owner, group, or other file class. A richacl grants a requested access only if the NFSv4 acl in the richacl grants the access (according to the NFSv4 permission check algorithm), and the file mask that applies to the process includes the requested permissions.
--- fs/Makefile | 2 + fs/richacl_base.c | 67 +++++++++++++ include/linux/richacl.h | 256 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 325 insertions(+) create mode 100644 fs/richacl_base.c create mode 100644 include/linux/richacl.h
fs/Makefile +2 -0
@@ -48,6 +48,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 +67 -0
67 lines not on this page · raw message
include/linux/richacl.h new file +256 -0
256 lines not on this page · raw message
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 7/46 richacl: Permission mapping functions
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
We need to map from POSIX permissions to NFSv4 permissions when a chmod() is done, from NFSv4 permissions to POSIX permissions when an acl is set (which implicitly sets the file permission bits), and from the MAY_READ/MAY_WRITE/MAY_EXEC/MAY_APPEND flags to NFSv4 permissions when doing an access check in a richacl.
--- fs/richacl_base.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 47 ++++++++++++++++++- 2 files changed, 164 insertions(+), 1 deletion(-)
fs/richacl_base.c +118 -0
@@ -65,3 +65,121 @@ richace_copy(struct richace *to, const struct richace *from) {memcpy (to, from,sizeof (struct richace )); } + +/* +* richacl_mask_to_mode - compute the file permission bits from mask +* @mask: %RICHACE_* permission mask +* +* Compute the file permission bits corresponding to a particular set of +* richacl permissions. +* +* 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 file permission bits from 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(); they must be explicitly enabled in the +* 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 +* @mode: mode to convert to richacl permissions +* +* 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. +*/ +unsigned int +richacl_mode_to_mask (umode_t mode) +{ +unsigned int mask =0 ; + +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 -1
58 lines not on this page · raw message
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 8/46 richacl: Compute maximum file masks from an acl
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Compute upper bound owner, group, and other file masks with as few permissions as possible without denying any permissions that the NFSv4 acl in a richacl grants.
This algorithm is used when a file inherits an acl at create time and when an acl is set via a mechanism that does not provide file masks (such as setting an acl via nfsd). When user-space sets an acl via setxattr, the extended attribute already includes the file masks.
Setting an acl also sets the file mode permission bits: they are determined by the file masks; see richacl_masks_to_mode().
--- fs/richacl_base.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 158 insertions(+)
fs/richacl_base.c +157 -0
@@ -183,3 +183,160 @@ richacl_want_to_mask(unsigned int want)return mask; }EXPORT_SYMBOL_GPL (richacl_want_to_mask); + +/* +* Note: functions like richacl_allowed_to_who(), richacl_group_class_allowed(), +* and richacl_compute_max_masks() iterate through the entire acl in reverse +* order as an optimization. +* +* In the standard algorithm, aces are considered in forward order. When a +* process matches an ace, the permissions in the ace are either allowed or +* denied depending on the ace type. Once a permission has been allowed or +* denied, it is no longer considered in further aces. +* +* By iterating through the acl in reverse order, we can compute the same +* result without having to keep track of which permissions have been allowed +* and denied already. +*/ + +/** +* richacl_allowed_to_who - permissions allowed to a specific who value +* +* Compute the maximum mask values allowed to a specific who value, taking +* everyone@ aces 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 of the group class +* +* Compute the maximum mask values allowed to a process in the group class +* (i.e., a process which is not the owner but is in the owning group or +* matches a user or group acl entry). This includes permissions granted or +* denied by everyone@ aces. +* +* 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 the acl doesn't contain any group@ aces, richacl_allowed_to_who() +* wasn't called for the owning group. We could make that call now, but +* we already know the result (everyone_allowed). +*/ +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 +* permissions allowed by the acl are disabled. +* +* We don't make assumptions about who the owner is so that the owner can +* change with no effect on the file masks or file mode permission bits; this +* means that we must assume that all entries can match the owner. +*/ +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 of 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, and the group class cannot +* have fewer permissions than the other class. +*/ + +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_WRITE_THROUGH |RICHACL_MASKED ); +} +EXPORT_SYMBOL_GPL (richacl_compute_max_masks);
include/linux/richacl.h +1 -0
@@ -297,5 +297,6 @@ extern void richace_copy(struct richace *, const struct richace *);extern int richacl_masks_to_mode (const struct richacl *);extern unsigned int richacl_mode_to_mask (umode_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.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 9/46 richacl: Permission check algorithm
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
A richacl roughly 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 | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 3 + 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 fs/richacl_inode.c
fs/Makefile +1 -1
@@ -49,7 +49,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 +149 -0
149 lines not on this page · raw message
include/linux/richacl.h +3 -0
@@ -299,4 +299,7 @@ extern unsigned int richacl_mode_to_mask(umode_t);extern unsigned int richacl_want_to_mask (unsigned int );extern void richacl_compute_max_masks (struct richacl *); +/* richacl_inode.c */ +extern int richacl_permission (struct inode *,const struct richacl *,int ); +#endif /* __RICHACL_H */
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 10/46 vfs: Cache base_acl objects in inodes
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
POSIX ACLs and richacls are both objects allocated by kmalloc() with a reference count which are freed by kfree_rcu(). An inode can either cache an access and a default POSIX ACL, or a richacl (richacls do not have default acls). To allow an inode to cache either of the two kinds of acls, introduce a new base_acl type and convert i_acl and i_default_acl to that type. In most cases, the vfs then doesn't have to care which kind of acl an inode caches (if any).
--- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- fs/f2fs/acl.c | 4 ++-- fs/inode.c | 4 ++-- fs/jffs2/acl.c | 6 ++++-- fs/posix_acl.c | 18 +++++++++--------- include/linux/fs.h | 25 ++++++++++++++++++++++--- include/linux/posix_acl.h | 12 ++++-------- include/linux/richacl.h | 2 +- 8 files changed, 45 insertions(+), 28 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
@@ -1118,7 +1118,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/jffs2/acl.c +4 -2
@@ -294,13 +294,15 @@ int jffs2_init_acl_post(struct inode *inode)int rc;if (inode->i_default_acl) { - rc =__jffs2_set_acl (inode,JFFS2_XPREFIX_ACL_DEFAULT , inode->i_default_acl); + rc =__jffs2_set_acl (inode,JFFS2_XPREFIX_ACL_DEFAULT , + *acl_by_type (inode,ACL_TYPE_DEFAULT ));if (rc)return rc; }if (inode->i_acl) { - rc =__jffs2_set_acl (inode,JFFS2_XPREFIX_ACL_ACCESS , inode->i_acl); + rc =__jffs2_set_acl (inode,JFFS2_XPREFIX_ACL_ACCESS , + *acl_by_type (inode,ACL_TYPE_ACCESS ));if (rc)return rc; }
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);
@@ -162,7 +162,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; }
@@ -384,7 +384,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) {
@@ -439,7 +439,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 +22 -3
@@ -576,6 +576,12 @@ static inline void mapping_allow_writable(struct address_space *mapping)#define i_size_ordered_init (inode) do { } while (0)#endif +struct base_acl { +union { +atomic_t ba_refcount; +struct rcu_head ba_rcu; + }; +};struct posix_acl ;#define ACL_NOT_CACHED ((void *)(-1))
@@ -595,9 +601,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;
@@ -3059,4 +3065,17 @@ static inline bool dir_relax(struct inode *inode)extern bool path_noexec (const struct path *path); +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 (acl, ba_rcu); +} +#endif /* _LINUX_FS_H */
include/linux/posix_acl.h +4 -8
@@ -43,10 +43,7 @@ struct posix_acl_entry { };struct posix_acl { -union { -atomic_t a_refcount; -struct rcu_head a_rcu; - }; +struct base_acl a_base;unsigned int a_count;struct posix_acl_entry a_entries[0 ]; };
@@ -61,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; }
@@ -72,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 (acl, a_rcu); +BUILD_BUG_ON (offsetof(struct posix_acl , a_base) !=0 ); +put_base_acl (&acl->a_base); }
include/linux/richacl.h +1 -1
@@ -176,7 +176,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.5.0
PATCH v10 11/46 vfs: Add get_richacl and set_richacl inode operations
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
These operations are similar to the get_acl and set_acl operations for POSIX ACLs. The distinction between access and default ACLs doesn't exist for richacls.
--- include/linux/fs.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/fs.h +2 -0
@@ -1662,6 +1662,7 @@ struct inode_operations {const char * (*follow_link) (struct dentry *,void **);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 inode *,void *);
@@ -1691,6 +1692,7 @@ struct inode_operations { umode_t create_mode, int *opened);int (*tmpfile) (struct inode *,struct dentry *,umode_t );int (*set_acl)(struct inode *,struct posix_acl *,int ); +int (*set_richacl)(struct inode *,struct richacl *);/* WARNING: probably going away soon, do not use! */ }____cacheline_aligned ;
Signature · 1 line
2.5.0
PATCH v10 12/46 vfs: Cache richacl in struct inode
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Cache richacls in struct inode so that this doesn't have to be done individually in each filesystem. This is similar to POSIX ACLs.
--- fs/inode.c | 11 ++++++-- fs/posix_acl.c | 2 +- fs/richacl_base.c | 4 +-- fs/richacl_inode.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 5 +++- include/linux/richacl.h | 15 ++++++---- 6 files changed, 100 insertions(+), 12 deletions(-)
fs/inode.c +8 -3
@@ -174,8 +174,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 +2 -2
@@ -33,7 +33,7 @@ richacl_alloc(int count, gfp_t gfp)struct richacl *acl =kzalloc (size, gfp);if (acl) { -atomic_set (&acl->a_refcount,1 ); +atomic_set (&acl->a_base.ba_refcount,1 ); acl->a_count = count; }return acl;
@@ -52,7 +52,7 @@ richacl_clone(const struct richacl *acl, gfp_t gfp)if (dup) {memcpy (dup, acl, size); -atomic_set (&dup->a_refcount,1 ); +atomic_set (&dup->a_base.ba_refcount,1 ); }return dup; }
fs/richacl_inode.c +75 -0
81 lines not on this page · raw message
include/linux/fs.h +4 -1
@@ -583,6 +583,7 @@ struct base_acl { }; };struct posix_acl ; +struct richacl ;#define ACL_NOT_CACHED ((void *)(-1))#define IOP_FASTPERM 0x0001
@@ -601,9 +602,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;
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;
@@ -175,8 +175,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; }
@@ -186,10 +185,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.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 13/46 richacl: Update the file masks in chmod()
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Doing a chmod() sets the file mode, which includes the file permission bits. When a file has a richacl, the permissions that the richacl grants need to be limited to what the new file permission bits allow.
This is done by setting the file masks in the richacl to what the file permission bits map to. The richacl access check algorithm takes the file masks into account, which ensures that the richacl cannot grant too many permissions.
It is possible to explicitly add permissions to the file masks which go beyond what the file permission bits can grant (like the RICHACE_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 | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/richacl_inode.c | 30 ++++++++++++++++++++++++++++++ include/linux/richacl.h | 2 ++ 3 files changed, 74 insertions(+)
fs/richacl_base.c +42 -0
@@ -340,3 +340,45 @@ restart: acl->a_flags &= ~(RICHACL_WRITE_THROUGH |RICHACL_MASKED ); }EXPORT_SYMBOL_GPL (richacl_compute_max_masks); + +/** +* __richacl_chmod - update the file masks to reflect the new mode +* @acl: access control list +* @mode: new file permission bits including the file type +* +* 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,umode_t mode) +{ +unsigned int x =S_ISDIR (mode) ?0 :RICHACE_DELETE_CHILD ; +unsigned int owner_mask, group_mask, other_mask; +struct richacl *clone; + + owner_mask =richacl_mode_to_mask (mode >>6 ) & ~x; + group_mask =richacl_mode_to_mask (mode >>3 ) & ~x; + other_mask =richacl_mode_to_mask (mode) & ~x; + +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_WRITE_THROUGH )) +return acl; + + clone =richacl_clone (acl,GFP_KERNEL ); +richacl_put (acl); +if (!clone) +return ERR_PTR (-ENOMEM ); + + clone->a_flags |= (RICHACL_WRITE_THROUGH |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);
fs/richacl_inode.c +30 -0
@@ -222,3 +222,33 @@ out:return denied ? -EACCES :0 ; }EXPORT_SYMBOL_GPL (richacl_permission); + +/** +* richacl_chmod - filesystem chmod helper +* @inode: inode whose file permission bits to change +* @mode: new file permission bits including the file type +* +* Helper for filesystems to use to perform a chmod on the richacl of an inode. +*/ +int +richacl_chmod (struct inode *inode,umode_t mode) +{ +struct richacl *acl; +int retval; + +if (S_ISLNK (mode)) +return -EOPNOTSUPP ; +if (!inode->i_op->set_richacl) +return -EOPNOTSUPP ; + acl =get_richacl (inode); +if (IS_ERR_OR_NULL (acl)) +return PTR_ERR (acl); + acl =__richacl_chmod (acl, mode); +if (IS_ERR (acl)) +return PTR_ERR (acl); + retval = inode->i_op->set_richacl (inode, acl); +richacl_put (acl); + +return retval; +} +EXPORT_SYMBOL (richacl_chmod);
include/linux/richacl.h +2 -0
@@ -303,8 +303,10 @@ extern int richacl_masks_to_mode(const struct richacl *);extern unsigned int richacl_mode_to_mask (umode_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 *,umode_t );/* richacl_inode.c */ extern int richacl_permission (struct inode *,const struct richacl *,int ); +extern int richacl_chmod (struct inode *,umode_t );#endif /* __RICHACL_H */
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 14/46 richacl: Check if an acl is equivalent to a file mode
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
ACLs are considered equivalent to file modes if they only consist of owner@, group@, and everyone@ entries, the owner@ permissions do not depend on whether the owner is a member in the owning group, and no inheritance flags are set. This test is used to avoid storing richacls if the acl can be computed from the file permission bits.
--- fs/richacl_base.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 105 insertions(+)
fs/richacl_base.c +104 -0
@@ -382,3 +382,107 @@ __richacl_chmod(struct richacl *acl, umode_t mode)return clone; }EXPORT_SYMBOL_GPL (__richacl_chmod); + +/** +* richacl_equiv_mode - compute the mode equivalent of @acl +* +* An acl is considered equivalent to a file mode if it only consists of +* owner@, group@, and everyone@ entries and the owner@ permissions do not +* depend on whether the owner is a member in the owning group. +*/ +int +richacl_equiv_mode (const struct richacl *acl,umode_t *mode_p) +{ +umode_t mode = *mode_p; + +/* +* The RICHACE_DELETE_CHILD flag is meaningless for non-directories, so +* we ignore it. +*/ +unsigned int x =S_ISDIR (mode) ?0 :RICHACE_DELETE_CHILD ; +struct { +unsigned int allowed; +unsigned int defined;/* allowed or denied */ + } owner = { + .defined =RICHACE_POSIX_ALWAYS_ALLOWED | +RICHACE_POSIX_OWNER_ALLOWED | x, + }, group = { + .defined =RICHACE_POSIX_ALWAYS_ALLOWED | x, + }, everyone = { + .defined =RICHACE_POSIX_ALWAYS_ALLOWED | x, + }; +const struct richace *ace; + +if (acl->a_flags & ~(RICHACL_WRITE_THROUGH |RICHACL_MASKED )) +return -1 ; + +richacl_for_each_entry (ace, acl) { +if (ace->e_flags & ~RICHACE_SPECIAL_WHO ) +return -1 ; + +if (richace_is_owner (ace) ||richace_is_everyone (ace)) { + x = ace->e_mask & ~owner.defined; +if (richace_is_allow (ace)) { +unsigned int group_denied = + group.defined & ~group.allowed; + +if (x & group_denied) +return -1 ; + owner.allowed |= x; + }else /* if (richace_is_deny(ace)) */ { +if (x & group.allowed) +return -1 ; + } + owner.defined |= x; + +if (richace_is_everyone (ace)) { + x = ace->e_mask; +if (richace_is_allow (ace)) { + group.allowed |= + x & ~group.defined; + everyone.allowed |= + x & ~everyone.defined; + } + group.defined |= x; + everyone.defined |= x; + } + }else if (richace_is_group (ace)) { + x = ace->e_mask & ~group.defined; +if (richace_is_allow (ace)) + group.allowed |= x; + group.defined |= x; + }else +return -1 ; + } + +if (group.allowed & ~owner.defined) +return -1 ; + +if (acl->a_flags &RICHACL_MASKED ) { +if (acl->a_flags &RICHACL_WRITE_THROUGH ) { + owner.allowed = acl->a_owner_mask; + everyone.allowed = acl->a_other_mask; + }else { + owner.allowed &= acl->a_owner_mask; + everyone.allowed &= acl->a_other_mask; + } + group.allowed &= acl->a_group_mask; + } + + mode = (mode & ~S_IRWXUGO ) | + (richacl_mask_to_mode (owner.allowed) <<6 ) | + (richacl_mask_to_mode (group.allowed) <<3 ) | +richacl_mask_to_mode (everyone.allowed); + +/* Mask flags we can ignore */ + x =S_ISDIR (mode) ?0 :RICHACE_DELETE_CHILD ; + +if (((richacl_mode_to_mask (mode >>6 ) ^ owner.allowed) & ~x) || + ((richacl_mode_to_mask (mode >>3 ) ^ group.allowed) & ~x) || + ((richacl_mode_to_mask (mode) ^ everyone.allowed) & ~x)) +return -1 ; + + *mode_p = mode; +return 0 ; +} +EXPORT_SYMBOL_GPL (richacl_equiv_mode);
include/linux/richacl.h +1 -0
@@ -304,6 +304,7 @@ extern unsigned int richacl_mode_to_mask(umode_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 *,umode_t ); +extern int richacl_equiv_mode (const struct richacl *,umode_t *);/* richacl_inode.c */ extern int richacl_permission (struct inode *,const struct richacl *,int );
Signature · 1 line
2.5.0
PATCH v10 15/46 richacl: Create-time inheritance
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
When a new file is created, it can inherit an acl from its parent directory; this is similar to how default acls work in POSIX (draft) ACLs.
As with POSIX ACLs, if a file inherits an acl from its parent directory, the intersection between the create mode and the permissions granted by the inherited acl determines the file masks and file permission bits, and the umask is ignored.
--- fs/richacl_base.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ fs/richacl_inode.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 2 ++ 3 files changed, 140 insertions(+)
fs/richacl_base.c +68 -0
@@ -486,3 +486,71 @@ richacl_equiv_mode(const struct richacl *acl, umode_t *mode_p)return 0 ; }EXPORT_SYMBOL_GPL (richacl_equiv_mode); + +/** +* 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 ; +richace_copy (ace, dir_ace); +if (dir_ace->e_flags &RICHACE_NO_PROPAGATE_INHERIT_ACE ) + ace->e_flags &= ~RICHACE_INHERITANCE_FLAGS ; +else if (!(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 ; +richace_copy (ace, dir_ace); + ace->e_flags &= ~RICHACE_INHERITANCE_FLAGS ; +/* +* RICHACE_DELETE_CHILD is meaningless for +* non-directories, so clear it. +*/ + ace->e_mask &= ~RICHACE_DELETE_CHILD ; + ace++; + } + } + +return acl; +}
fs/richacl_inode.c +70 -0
73 lines not on this page · raw message
include/linux/richacl.h +2 -0
@@ -305,9 +305,11 @@ extern unsigned int richacl_want_to_mask(unsigned int);extern void richacl_compute_max_masks (struct richacl *);extern struct richacl *__richacl_chmod (struct richacl *,umode_t );extern int richacl_equiv_mode (const struct richacl *,umode_t *); +extern struct richacl *richacl_inherit (const struct richacl *,int );/* richacl_inode.c */ extern int richacl_permission (struct inode *,const struct richacl *,int );extern int richacl_chmod (struct inode *,umode_t ); +extern struct richacl *richacl_create (umode_t *,struct inode *);#endif /* __RICHACL_H */
Signature · 1 line
2.5.0
PATCH v10 16/46 richacl: Automatic Inheritance
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Automatic Inheritance (AI) allows changes to the acl of a directory to propagate down to children.
This is mostly implemented in user space: when a process changes the permissions of a directory and Automatic Inheritance is enabled for that directory, the process must propagate those changes to all children, recursively.
The kernel enables this by keeping track of which permissions have been inherited at create time. In addition, it makes sure that permission propagation is turned off when the permissions are set explicitly (for example, upon create or chmod).
Automatic Inheritance works as follows:
- When the RICHACL_AUTO_INHERIT flag in the acl of a file or directory is not set, the file or directory is not affected by AI.
- When the RICHACL_AUTO_INHERIT flag in the acl of a directory is set and a file or subdirectory is created in that directory, the inherited acl will have the RICHACL_AUTO_INHERIT flag set, and all inherited aces will have the RICHACE_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 RICHACL_PROTECTED acl flag in the acl of a file or directory is set, AI will not modify the acl. 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 or directories without setting the file permission bits, so all files created inside a directory with RICHACL_AUTO_INHERIT set will have the RICHACL_PROTECTED flag set. This effectively disables Automatic Inheritance.
Protocols which support creating files without specifying permissions can explicitly clear the RICHACL_PROTECTED flag after creating a file and reset the file masks to "undo" applying the create mode; see richacl_compute_max_masks(). They should set the RICHACL_DEFAULTED flag. (A mechanism that would allow to indicate to the kernel to ignore the create mode in the first place when there are inherited permissions would be nice to have.)
--- fs/richacl_base.c | 10 +++++++++- fs/richacl_inode.c | 7 +++++++ include/linux/richacl.h | 23 ++++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-)
fs/richacl_base.c +9 -1
@@ -366,7 +366,8 @@ __richacl_chmod(struct richacl *acl, umode_t mode) acl->a_group_mask == group_mask && acl->a_other_mask == other_mask && (acl->a_flags &RICHACL_MASKED ) && - (acl->a_flags & RICHACL_WRITE_THROUGH)) + (acl->a_flags &RICHACL_WRITE_THROUGH ) && + (!richacl_is_auto_inherit(acl) || richacl_is_protected(acl))) return acl; clone =richacl_clone (acl,GFP_KERNEL );
@@ -378,6 +379,8 @@ __richacl_chmod(struct richacl *acl, umode_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; }
@@ -551,6 +554,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 +7 -0
@@ -277,6 +277,13 @@ richacl_inherit_inode(const struct richacl *dir_acl, umode_t *mode_p)richacl_put (acl); acl =NULL ; }else { +/* +* 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
include/linux/richacl.h +22 -1
@@ -53,10 +53,16 @@ struct richacl { _ace--)/* a_flags values */ +#define RICHACL_AUTO_INHERIT 0x01 +#define RICHACL_PROTECTED 0x02 +#define RICHACL_DEFAULTED 0x04#define RICHACL_WRITE_THROUGH 0x40#define RICHACL_MASKED 0x80#define RICHACL_VALID_FLAGS ( \ + RICHACL_AUTO_INHERIT | \ + RICHACL_PROTECTED | \ + RICHACL_DEFAULTED | \ RICHACL_WRITE_THROUGH | \ RICHACL_MASKED)
@@ -70,6 +76,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 ( \
@@ -78,13 +85,15 @@ struct richacl { RICHACE_NO_PROPAGATE_INHERIT_ACE | \ RICHACE_INHERIT_ONLY_ACE | \ RICHACE_IDENTIFIER_GROUP | \ + RICHACE_INHERITED_ACE | \ RICHACE_SPECIAL_WHO)#define RICHACE_INHERITANCE_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 )/* e_mask bitflags */ #define RICHACE_READ_DATA 0x00000001
@@ -195,6 +204,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 */
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 17/46 richacl: xattr mapping functions
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Map between "system.richacl" xattrs and the in-kernel representation.
--- fs/Makefile | 2 +- fs/richacl_xattr.c | 220 ++++++++++++++++++++++++++++++++++++++++++ fs/xattr.c | 34 +++++-- include/linux/richacl_xattr.h | 62 ++++++++++++ include/uapi/linux/xattr.h | 2 + 5 files changed, 313 insertions(+), 7 deletions(-) create mode 100644 fs/richacl_xattr.c create mode 100644 include/linux/richacl_xattr.h
fs/Makefile +1 -1
@@ -49,7 +49,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 +220 -0
220 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 @@ out: }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 +62 -0
62 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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 18/46 richacl: Add richacl xattr handler
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Add richacl xattr handler implementing the xattr operations based on the get_richacl and set_richacl inode operations.
--- fs/richacl_xattr.c | 78 +++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl_xattr.h | 2 ++ 2 files changed, 80 insertions(+)
fs/richacl_xattr.c +78 -0
@@ -18,7 +18,9 @@#include <linux/fs.h> #include <linux/slab.h> #include <linux/module.h> +#include <linux/xattr.h> #include <linux/richacl_xattr.h> +#include <uapi/linux/xattr.h> MODULE_LICENSE ("GPL" );
@@ -161,6 +163,82 @@ richacl_to_xattr(struct user_namespace *user_ns, }EXPORT_SYMBOL_GPL (richacl_to_xattr); +static size_t +richacl_xattr_list (struct dentry *dentry,char *list,size_t list_len, +const char *name,size_t name_len,int handler_flags) +{ +const size_t size =sizeof (XATTR_NAME_RICHACL ); + +if (!IS_RICHACL (d_backing_inode (dentry))) +return 0 ; +if (list && size <= list_len) +memcpy (list,XATTR_NAME_RICHACL , size); +return size; +} + +static int +richacl_xattr_get (struct dentry *dentry,const char *name,void *buffer, +size_t buffer_size,int handler_flags) +{ +struct inode *inode =d_backing_inode (dentry); +struct richacl *acl; +int error; + +if (strcmp (name,"" ) !=0 ) +return -EINVAL ; +if (!IS_RICHACL (inode)) +return EOPNOTSUPP ; +if (S_ISLNK (inode->i_mode)) +return -EOPNOTSUPP ; + acl =get_richacl (inode); +if (IS_ERR (acl)) +return PTR_ERR (acl); +if (acl ==NULL ) +return -ENODATA ; + error =richacl_to_xattr (&init_user_ns, acl, buffer, buffer_size); +richacl_put (acl); +return error; +} + +static int +richacl_xattr_set (struct dentry *dentry,const char *name, +const void *value,size_t size,int flags,int handler_flags) +{ +struct inode *inode =d_backing_inode (dentry); +struct richacl *acl =NULL ; +int ret; + +if (strcmp (name,"" ) !=0 ) +return -EINVAL ; +if (!IS_RICHACL (inode)) +return -EOPNOTSUPP ; +if (!inode->i_op->set_richacl) +return -EOPNOTSUPP ; + +if (!uid_eq (current_fsuid (), inode->i_uid) && +inode_permission (inode,MAY_CHMOD ) && + !capable (CAP_FOWNER )) +return -EPERM ; + +if (value) { + acl =richacl_from_xattr (&init_user_ns, value, size); +if (IS_ERR (acl)) +return PTR_ERR (acl); + } + + ret = inode->i_op->set_richacl (inode, acl); +richacl_put (acl); +return ret; +} + +struct xattr_handler richacl_xattr_handler = { + .prefix =XATTR_NAME_RICHACL , + .list = richacl_xattr_list, + .get = richacl_xattr_get, + .set = richacl_xattr_set, +}; +EXPORT_SYMBOL (richacl_xattr_handler); +/* * Fix up the uids and gids in richacl extended attributes in place. */
include/linux/richacl_xattr.h +2 -0
@@ -59,4 +59,6 @@ static inline void richacl_fix_xattr_to_user(void *value, size_t size) }#endif +extern struct xattr_handler richacl_xattr_handler; +#endif /* __RICHACL_XATTR_H */
Signature · 1 line
2.5.0
PATCH v10 19/46 vfs: Add richacl permission checking
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Hook the richacl permission checking function into the vfs.
--- fs/namei.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- fs/posix_acl.c | 6 +++--- 2 files changed, 52 insertions(+), 5 deletions(-)
fs/namei.c +49 -2
@@ -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"
@@ -255,7 +256,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;
@@ -290,11 +324,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.5.0
PATCH v10 20/46 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 | 11 +++++ fs/ext4/Makefile | 1 + fs/ext4/file.c | 3 ++ fs/ext4/ialloc.c | 7 ++- fs/ext4/inode.c | 10 +++-- fs/ext4/namei.c | 5 +++ fs/ext4/richacl.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/richacl.h | 43 ++++++++++++++++++ fs/ext4/xattr.c | 7 +++ 9 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 fs/ext4/richacl.c create mode 100644 fs/ext4/richacl.h
fs/ext4/Kconfig +11 -0
@@ -22,6 +22,17 @@ config EXT3_FS_POSIX_ACL This config option is here only for backward compatibility. ext3 filesystem is now handled by the ext4 driver. +config EXT4_FS_RICHACL + bool "Ext4 Rich Access Control Lists (EXPERIMENTAL)" + depends on EXT4_FS + select FS_RICHACL + help + Richacls are an implementation of NFSv4 ACLs, extended by file masks + to cleanly integrate into the POSIX file permission model. To learn + more about them, see http://www.bestbits.at/richacl/. + + If you don't know what Richacls are, say N. + config EXT3_FS_SECURITY bool "Ext3 Security Labels" depends on EXT3_FS
fs/ext4/Makefile +1 -0
@@ -14,3 +14,4 @@ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o ext4-$(CONFIG_EXT4_FS_ENCRYPTION) += crypto_policy.o crypto.o \ crypto_key.o crypto_fname.o +ext4-$(CONFIG_EXT4_FS_RICHACL) += richacl.o
fs/ext4/file.c +3 -0
@@ -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
@@ -719,6 +720,8 @@ const struct inode_operations ext4_file_inode_operations = { .removexattr = generic_removexattr, .get_acl = ext4_get_acl, .set_acl = ext4_set_acl, + .get_richacl = ext4_get_richacl, + .set_richacl = ext4_set_richacl, .fiemap = ext4_fiemap, };
fs/ext4/ialloc.c +6 -1
@@ -27,6 +27,7 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" +#include "richacl.h" #include <trace/events/ext4.h>
@@ -1052,7 +1053,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_acl (handle, inode, dir); +if (err) goto fail_free_drop;
fs/ext4/inode.c +7 -3
@@ -42,6 +42,7 @@#include "xattr.h" #include "acl.h" #include "truncate.h" +#include "richacl.h" #include <trace/events/ext4.h>
@@ -4805,9 +4806,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 =richacl_chmod (inode, inode->i_mode); +else + rc =posix_acl_chmod (inode, inode->i_mode); + } err_out:ext4_std_error (inode->i_sb, error);if (!error)
fs/ext4/namei.c +5 -0
@@ -38,6 +38,7 @@#include "xattr.h" #include "acl.h" +#include "richacl.h" #include <trace/events/ext4.h> /*
@@ -3854,6 +3855,8 @@ const struct inode_operations ext4_dir_inode_operations = { .removexattr = generic_removexattr, .get_acl = ext4_get_acl, .set_acl = ext4_set_acl, + .get_richacl = ext4_get_richacl, + .set_richacl = ext4_set_richacl, .fiemap = ext4_fiemap, };
@@ -3865,4 +3868,6 @@ const struct inode_operations ext4_special_inode_operations = { .removexattr = generic_removexattr, .get_acl = ext4_get_acl, .set_acl = ext4_set_acl, + .get_richacl = ext4_get_richacl, + .set_richacl = ext4_set_richacl, };
fs/ext4/richacl.c new file +129 -0
129 lines not on this page · raw message
fs/ext4/richacl.h new file +43 -0
43 lines not on this page · raw message
fs/ext4/xattr.c +7 -0
@@ -55,6 +55,7 @@#include <linux/slab.h> #include <linux/mbcache.h> #include <linux/quotaops.h> +#include <linux/richacl_xattr.h> #include "ext4_jbd2.h" #include "ext4.h" #include "xattr.h"
@@ -99,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] = &richacl_xattr_handler, +#endif }; const struct xattr_handler *ext4_xattr_handlers[] = {
@@ -111,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 + &richacl_xattr_handler, +#endifNULL };
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 21/46 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 | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +4 -2
@@ -991,7 +991,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 */
@@ -1582,6 +1582,7 @@ static inline int ext4_encrypted_inode(struct inode *inode)#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| \
@@ -1607,7 +1608,8 @@ static inline int ext4_encrypted_inode(struct inode *inode) EXT4_FEATURE_INCOMPAT_FLEX_BG| \ EXT4_FEATURE_INCOMPAT_MMP | \ EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ - EXT4_FEATURE_INCOMPAT_ENCRYPT) + EXT4_FEATURE_INCOMPAT_ENCRYPT | \ + 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 +33 -9
72 lines not on this page · raw message
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 22/46 xfs: Fix error path in xfs_get_acl
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Error codes from xfs_attr_get other than -ENOATTR were not properly reported. Fix that, and clean the code up somewhat.
In addition, the declaration of struct xfs_inode in xfs_acl.h isn't needed.
--- fs/xfs/xfs_acl.c | 19 +++++++------------ fs/xfs/xfs_acl.h | 1 - 2 files changed, 7 insertions(+), 13 deletions(-)
fs/xfs/xfs_acl.c +7 -12
@@ -122,7 +122,7 @@ struct posix_acl * xfs_get_acl(struct inode *inode, int type) {struct xfs_inode *ip =XFS_I (inode); -struct posix_acl *acl =NULL ; +struct posix_acl *acl;struct xfs_acl *xfs_acl;unsigned char *ea_name;int error;
@@ -158,18 +158,13 @@ xfs_get_acl(struct inode *inode, int type)* cache entry, for any other error assume it is transient and * leave the cache entry as ACL_NOT_CACHED. */ -if (error == -ENOATTR ) - goto out_update_cache; - goto out; - } + acl = (error == -ENOATTR ) ?NULL :ERR_PTR (error); + }else + acl =xfs_acl_from_disk (xfs_acl, +XFS_ACL_MAX_ENTRIES (ip->i_mount)); - acl =xfs_acl_from_disk (xfs_acl,XFS_ACL_MAX_ENTRIES (ip->i_mount)); -if (IS_ERR (acl)) - goto out; - -out_update_cache: -set_cached_acl (inode, type, acl); -out: +if (!IS_ERR (acl)) +set_cached_acl (inode, type, acl);kmem_free (xfs_acl);return acl; }
fs/xfs/xfs_acl.h +0 -1
@@ -20,7 +20,6 @@struct inode ;struct posix_acl ; -struct xfs_inode ;#ifdef CONFIG_XFS_POSIX_ACL extern struct posix_acl *xfs_get_acl (struct inode *inode,int type);
Signature · 1 line
2.5.0
PATCH v10 23/46 xfs: Make xfs_set_mode non-static
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Make xfs_set_mode non-static and move it from xfs_acl.c into xfs_inode.c.
--- fs/xfs/xfs_acl.c | 18 ------------------ fs/xfs/xfs_inode.c | 18 ++++++++++++++++++ fs/xfs/xfs_inode.h | 2 ++ 3 files changed, 20 insertions(+), 18 deletions(-)
fs/xfs/xfs_acl.c +0 -18
@@ -226,24 +226,6 @@ __xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) }static int -xfs_set_mode (struct inode *inode,umode_t mode) -{ -int error =0 ; - -if (mode != inode->i_mode) { -struct iattr iattr; - - iattr.ia_valid =ATTR_MODE |ATTR_CTIME ; - iattr.ia_mode = mode; - iattr.ia_ctime =current_fs_time (inode->i_sb); - - error =xfs_setattr_nonsize (XFS_I (inode), &iattr,XFS_ATTR_NOACL ); - } - -return error; -} - -static int xfs_acl_exists (struct inode *inode,unsigned char *name) {int len =XFS_ACL_MAX_SIZE (XFS_M (inode->i_sb));
fs/xfs/xfs_inode.c +18 -0
@@ -3587,3 +3587,21 @@ xfs_iflush_int( corrupt_out:return -EFSCORRUPTED ; } + +int +xfs_set_mode (struct inode *inode,umode_t mode) +{ +int error =0 ; + +if (mode != inode->i_mode) { +struct iattr iattr; + + iattr.ia_valid =ATTR_MODE |ATTR_CTIME ; + iattr.ia_mode = mode; + iattr.ia_ctime =current_fs_time (inode->i_sb); + + error =xfs_setattr_nonsize (XFS_I (inode), &iattr,XFS_ATTR_NOACL ); + } + +return error; +}
fs/xfs/xfs_inode.h +2 -0
@@ -424,6 +424,8 @@ int xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,int xfs_droplink (struct xfs_trans *,struct xfs_inode *);int xfs_bumplink (struct xfs_trans *,struct xfs_inode *); +int xfs_set_mode (struct inode *,umode_t ); +/* from xfs_file.c */ enum xfs_prealloc_flags {XFS_PREALLOC_SET = (1 <<1 ),
Signature · 1 line
2.5.0
Re: [PATCH v10 23/46] xfs: Make xfs_set_mode non-static
Quoted 5 lines · Andreas Gruenbacher
From: Andreas Gruenbacher <[email protected]>
Make
xfs_set_modenon-static and move it fromxfs_acl.cintoxfs_inode.c.Signed-off-by Andreas Gruenbacher <[email protected]>
.....
Quoted 13 lines
+++
b/fs/xfs/xfs_inode.cfs/xfs/xfs_inode.c +8
-0@@ -3587,3 +3587,21 @@ xfs_iflush_int( corrupt_out:return -EFSCORRUPTED ; } + +int +xfs_set_mode (struct inode *inode,umode_t mode) +{ +int error =0 ; + +if (mode != inode->i_mode) { +struct iattr iattr;
fs/xfs/xfs_inode.c xfs_iflush_int( · line 3607
Quoted 10 lines
fs/xfs/xfs_inode.c +10
-0+ + iattr.ia_valid =ATTR_MODE |ATTR_CTIME ; + iattr.ia_mode = mode; + iattr.ia_ctime =current_fs_time (inode->i_sb); + + error =xfs_setattr_nonsize (XFS_I (inode), &iattr,XFS_ATTR_NOACL ); + } + +return error; +}
Now needs a comment to explain that this function has a special "called only from ACL modification" context associated with it.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 24/46 xfs: Add richacl support
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
The richacl feature flag (mkfs.xfs -m richacl=1) determines whether an xfs filesystem supports posix acls or richacls. Richacls are stored in "system.richacl" xattrs.
If richacls are not compiled into the kernel, mounting richacl filesystems will fail.
--- fs/ext4/richacl.h | 1 - fs/xfs/Kconfig | 11 ++++++ fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_format.h | 16 +++++++- fs/xfs/xfs_iops.c | 42 +++++++++++++++----- fs/xfs/xfs_richacl.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_richacl.h | 34 ++++++++++++++++ fs/xfs/xfs_super.c | 14 ++++++- fs/xfs/xfs_super.h | 9 ++++- fs/xfs/xfs_xattr.c | 4 ++ 10 files changed, 215 insertions(+), 14 deletions(-) create mode 100644 fs/xfs/xfs_richacl.c create mode 100644 fs/xfs/xfs_richacl.h
fs/ext4/richacl.h +0 -1
@@ -24,7 +24,6 @@extern struct richacl *ext4_get_richacl (struct inode *);extern int ext4_set_richacl (struct inode *,struct richacl *); -extern int ext4_init_richacl (handle_t *,struct inode *,struct inode *);#else /* CONFIG_EXT4_FS_RICHACL */
fs/xfs/Kconfig +11 -0
@@ -52,6 +52,17 @@ config XFS_POSIX_ACL If you don't know what Access Control Lists are, say N. +config XFS_RICHACL + bool "XFS Rich Access Control Lists (EXPERIMENTAL)" + depends on XFS_FS + select FS_RICHACL + help + Richacls are an implementation of NFSv4 ACLs, extended by file masks + to cleanly integrate into the POSIX file permission model. To learn + more about them, see http://www.bestbits.at/richacl/. + + If you don't know what Richacls are, say N. + config XFS_RT bool "XFS Realtime subvolume support" depends on XFS_FS
fs/xfs/Makefile +1 -0
@@ -118,6 +118,7 @@ xfs-$(CONFIG_XFS_QUOTA) += xfs_dquot.o \ xfs-$(CONFIG_XFS_RT) += xfs_rtalloc.o xfs-$(CONFIG_XFS_POSIX_ACL) += xfs_acl.o +xfs-$(CONFIG_XFS_RICHACL) += xfs_richacl.o xfs-$(CONFIG_PROC_FS) += xfs_stats.o xfs-$(CONFIG_SYSCTL) += xfs_sysctl.o xfs-$(CONFIG_COMPAT) += xfs_ioctl32.o
fs/xfs/libxfs/xfs_format.h +15 -1
@@ -461,10 +461,18 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ + +#ifdef CONFIG_XFS_RICHACL +#define XFS_SB_FEAT_INCOMPAT_RICHACL (1 << 3)/* richacls */ +#else +#define XFS_SB_FEAT_INCOMPAT_RICHACL 0 +#endif +#define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID) + XFS_SB_FEAT_INCOMPAT_META_UUID| \ + XFS_SB_FEAT_INCOMPAT_RICHACL)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool
@@ -530,6 +538,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_hasrichacl (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_RICHACL ); +} +/* * end of superblock version macros */
fs/xfs/xfs_iops.c +33 -9
102 lines not on this page · raw message
fs/xfs/xfs_richacl.c new file +97 -0
97 lines not on this page · raw message
fs/xfs/xfs_richacl.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 2015 Red Hat, Inc. +* Author: Andreas Gruenbacher <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2.1 of the GNU Lesser General Public License +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +*/ + +#ifndef __FS_XFS_RICHACL_H +#define __FS_XFS_RICHACL_H + +#include <linux/richacl.h> + +#ifdef CONFIG_XFS_RICHACL + +#define XFS_IS_RICHACL (inode) IS_RICHACL(inode) + +extern struct richacl *xfs_get_richacl (struct inode *); +extern int xfs_set_richacl (struct inode *,struct richacl *); + +#else /* CONFIG_XFS_RICHACL */ + +#define XFS_IS_RICHACL (inode) (0) +#define xfs_get_richacl NULL +#define xfs_set_richacl NULL + +#endif /* CONFIG_XFS_RICHACL */ +#endif /* __FS_XFS_RICHACL_H */
fs/xfs/xfs_super.c +13 -1
@@ -1500,7 +1500,19 @@ xfs_fs_fill_super( sb->s_maxbytes =xfs_max_file_offset (sb->s_blocksize_bits); sb->s_max_links =XFS_MAXLINK ; sb->s_time_gran =1 ; -set_posix_acl_flag (sb); + +if (xfs_sb_version_hasrichacl (&mp->m_sb)) { +#ifdef CONFIG_XFS_RICHACL + sb->s_flags |=MS_RICHACL ; +#else + error = -EOPNOTSUPP ; + goto out_free_sb; +#endif + }else { +#ifdef CONFIG_XFS_POSIX_ACL + sb->s_flags |=MS_POSIXACL ; +#endif + }/* version 5 superblocks support inode version counters. */ if (XFS_SB_VERSION_NUM (&mp->m_sb) ==XFS_SB_VERSION_5 )
fs/xfs/xfs_super.h +7 -2
@@ -30,10 +30,14 @@ extern void xfs_qm_exit(void);#ifdef CONFIG_XFS_POSIX_ACL # define XFS_ACL_STRING "ACLs, " -# define set_posix_acl_flag (sb) ((sb)->s_flags |= MS_POSIXACL)#else # define XFS_ACL_STRING -# define set_posix_acl_flag (sb) do { } while (0) +#endif + +#ifdef CONFIG_XFS_RICHACL +# define XFS_RICHACL_STRING "Richacls, " +#else +# define XFS_RICHACL_STRING #endif #define XFS_SECURITY_STRING "security attributes, "
@@ -52,6 +56,7 @@ extern void xfs_qm_exit(void);#define XFS_VERSION_STRING "SGI XFS"#define XFS_BUILD_OPTIONS XFS_ACL_STRING \ + XFS_RICHACL_STRING \ XFS_SECURITY_STRING \ XFS_REALTIME_STRING \ XFS_DBG_STRING/* DBG must be last */
fs/xfs/xfs_xattr.c +4 -0
@@ -28,6 +28,7 @@#include "xfs_acl.h" #include <linux/posix_acl_xattr.h> +#include <linux/richacl_xattr.h> #include <linux/xattr.h>
@@ -103,6 +104,9 @@ const struct xattr_handler *xfs_xattr_handlers[] = { &posix_acl_access_xattr_handler, &posix_acl_default_xattr_handler, #endif +#ifdef CONFIG_XFS_RICHACL + &richacl_xattr_handler, +#endifNULL };
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v10 24/46] xfs: Add richacl support
Quoted 30 lines · Andreas Gruenbacher
From: Andreas Gruenbacher <[email protected]>
The richacl feature flag (mkfs.xfs -m richacl=1) determines whether an xfs filesystem supports posix acls or richacls. Richacls are stored in "system.richacl" xattrs.
If richacls are not compiled into the kernel, mounting richacl filesystems will fail.
Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/ext4/richacl.h | 1 - fs/xfs/Kconfig | 11 ++++++ fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_format.h | 16 +++++++- fs/xfs/xfs_iops.c | 42 +++++++++++++++----- fs/xfs/xfs_richacl.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_richacl.h | 34 ++++++++++++++++ fs/xfs/xfs_super.c | 14 ++++++- fs/xfs/xfs_super.h | 9 ++++- fs/xfs/xfs_xattr.c | 4 ++ 10 files changed, 215 insertions(+), 14 deletions(-) create mode 100644 fs/xfs/xfs_richacl.c create mode 100644 fs/xfs/xfs_richacl.hfs/ext4/richacl.h +0
-0
fs/ext4/richacl.h line 29
Quoted 7 lines
fs/ext4/richacl.h +0
-1@@ -24,7 +24,6 @@extern struct richacl *ext4_get_richacl (struct inode *);extern int ext4_set_richacl (struct inode *,struct richacl *); -extern int ext4_init_richacl (handle_t *,struct inode *,struct inode *);#else /* CONFIG_EXT4_FS_RICHACL */
stray hunk.
Quoted 9 lines
fs/xfs/Kconfig +1
-0@@ -52,6 +52,17 @@ config XFS_POSIX_ACL If you don't know what Access Control Lists are, say N. +config XFS_RICHACL
fs/xfs/Kconfig config XFS_POSIX_ACL · line 65
Quoted 10 lines
fs/xfs/Kconfig +10
-0+ bool "XFS Rich Access Control Lists (EXPERIMENTAL)" + depends on XFS_FS + select FS_RICHACL + help + Richacls are an implementation of NFSv4 ACLs, extended by file masks + to cleanly integrate into the POSIX file permission model. To learn + more about them, see http://www.bestbits.at/richacl/. + + If you don't know what Richacls are, say N. +
So now we have multiple compile time ACL configs that we have to test. Personally, I see no reason for making either posix or rich acls compile time dependent. How about we just change CONFIG_FS_XFS to have "select FS_POSIX_ACL" and "select FS_RICHACL" unconditionally, and then we can get rid of all the conditional code?
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +0
-0
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 470
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +7
-0@@ -461,10 +461,18 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ + +#ifdef CONFIG_XFS_RICHACL +#define XFS_SB_FEAT_INCOMPAT_RICHACL (1 << 3)/* richacls */ +#else +#define XFS_SB_FEAT_INCOMPAT_RICHACL 0 +#endif +
Regardless of whether we build in richacl support, this is wrong. Feature bits are on-disk format definitions, so it will always have this value whether or not the kernel supports the feature.
fs/xfs/libxfs/xfs_format.h xfs_setattr_nonsize( · line 746
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +4
-1@@ -722,7 +737,10 @@ xfs_setattr_nonsize(* Posix ACL code seems to care about this issue either. */ if ((mask &ATTR_MODE ) && !(flags &XFS_ATTR_NOACL )) { - error =posix_acl_chmod (inode, inode->i_mode); +if (XFS_IS_RICHACL (inode)) + error =richacl_chmod (inode, inode->i_mode); +else + error =posix_acl_chmod (inode, inode->i_mode);if (error)return error; }
This sort of thing could do with a helper like:
static inline intxfs_acl_chmod(struct inode *inode, int mode)
{
if (IS_RICHACL(inode))
return richacl_chmod(inode, mode);
return posix_acl_chmod(inode, mode);
}fs/xfs/libxfs/xfs_format.h
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +11
-0+#include "xfs.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_inode.h" +#include "xfs_attr.h" + +#include <linux/richacl_xattr.h> + +struct richacl * +xfs_get_richacl (struct inode *inode) +{
...
If we always build in ACL support, this can all go in xfs_acl.c.
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h +8
-0+struct xfs_inode *ip =XFS_I (inode); +struct richacl *acl; +int size =XATTR_SIZE_MAX ; +void *value; +int error; + + value =kmem_zalloc_large (size,KM_SLEEP ); +if (!value)
fs/xfs/libxfs/xfs_format.h
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+return ERR_PTR (-ENOMEM ); + + error =xfs_attr_get (ip,XATTR_NAME_RICHACL , value, &size,ATTR_ROOT ); +if (error) { +/* +* If the attribute doesn't exist make sure we have a negative +* cache entry, for any other error assume it is transient and +* leave the cache entry as ACL_NOT_CACHED. +*/ + acl = (error == -ENOATTR ) ?NULL :ERR_PTR (error);
I rather dislike ternaries in code like this - it's hard to read the logic. Initalise acl to NULL, and then this simply becomes:
if (error != -ENOATTR) acl = ERR_PTR(error);
Quoted 16 lines
fs/xfs/libxfs/xfs_format.h +16
-0+ }else + acl =richacl_from_xattr (&init_user_ns, value, size); + +if (!IS_ERR (acl)) +set_cached_richacl (inode, acl); +kfree (value); + +return acl; +} + +int +xfs_set_richacl (struct inode *inode,struct richacl *acl) +{ +struct xfs_inode *ip =XFS_I (inode); +umode_t mode = inode->i_mode; +int error;
fs/xfs/libxfs/xfs_format.h
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+ +if (acl) { +/* Don't allow acls with unmapped identifiers. */ +if (richacl_has_unmapped_identifiers (acl)) +return -EINVAL ; + +if (richacl_equiv_mode (acl, &mode) ==0 ) { +xfs_set_mode (inode, mode); + acl =NULL ; + }
Comment needed here - why does this now seem to accidentally fall through to removing the ACL? Also, why is this in the XFS specific code when it's generic richacl functionality that is being checked?
Also, I really dislike the API where passing a NULL acl means to "set this acl" actually means "remove the existing ACL". Why no ->remove_acl method called from the generic code?
fs/xfs/libxfs/xfs_format.h
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h +8
-0+#ifndef __FS_XFS_RICHACL_H +#define __FS_XFS_RICHACL_H + +#include <linux/richacl.h> + +#ifdef CONFIG_XFS_RICHACL + +#define XFS_IS_RICHACL (inode) IS_RICHACL(inode)
No. Just use IS_RICHACL() everywhere, and whatever build conditional that uses.
Quoted 9 lines
fs/xfs/xfs_super.c +2
-1@@ -1500,7 +1500,19 @@ xfs_fs_fill_super( sb->s_maxbytes =xfs_max_file_offset (sb->s_blocksize_bits); sb->s_max_links =XFS_MAXLINK ; sb->s_time_gran =1 ; -set_posix_acl_flag (sb); + +if (xfs_sb_version_hasrichacl (&mp->m_sb)) {
fs/xfs/xfs_super.c xfs_fs_fill_super( · line 1514
Quoted 10 lines
fs/xfs/xfs_super.c +10
-0+#ifdef CONFIG_XFS_RICHACL + sb->s_flags |=MS_RICHACL ; +#else + error = -EOPNOTSUPP ; + goto out_free_sb; +#endif + }else { +#ifdef CONFIG_XFS_POSIX_ACL + sb->s_flags |=MS_POSIXACL ; +#endif
The whole point of having set_posix_acl_flag() is that it keeps the ifdef hackery out of the code. If we are going to keep build time config options for these, then please keep the wrappers to hide this mess...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v10 24/46] xfs: Add richacl support
2015-10-12 2:10 GMT+02:00 Dave Chinner <[email protected]>:
Quoted 7 lines · Andreas Gruenbacher
Quoted 6 lines
fs/ext4/richacl.h +0
-0@@ -24,7 +24,6 @@
Quoted 8 lines
fs/ext4/richacl.h line 29
Quoted 6 lines
fs/ext4/richacl.h +0
-1extern struct richacl *ext4_get_richacl (struct inode *);extern int ext4_set_richacl (struct inode *,struct richacl *); -extern int ext4_init_richacl (handle_t *,struct inode *,struct inode *);#else /* CONFIG_EXT4_FS_RICHACL */ stray hunk.
Oops, thanks.
Quoted 18 lines
Quoted 18 lines
fs/xfs/Kconfig +10
-0@@ -52,6 +52,17 @@ config XFS_POSIX_ACL If you don't know what Access Control Lists are, say N. +config XFS_RICHACL + bool "XFS Rich Access Control Lists (EXPERIMENTAL)" + depends on XFS_FS + select FS_RICHACL + help + Richacls are an implementation of NFSv4 ACLs, extended by file masks + to cleanly integrate into the POSIX file permission model. To learn + more about them, see http://www.bestbits.at/richacl/. + + If you don't know what Richacls are, say N.
Quoted 8 lines
fs/xfs/Kconfig config XFS_POSIX_ACL · line 65
Quoted 1 line
fs/xfs/Kconfig +1
-0+So now we have multiple compile time ACL configs that we have to test. Personally, I see no reason for making either posix or rich acls compile time dependent. How about we just change
CONFIG_FS_XFSto have "selectFS_POSIX_ACL" and "selectFS_RICHACL" unconditionally, and then we can get rid of all the conditional code?
I'm sure neither kind of ACLs makes sense on many tiny systems, it should be possible to disable them. XFS may not make sense on those kinds of systems either, that is not my call to make though.
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +3
-0@@ -461,10 +461,18 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ + +#ifdef CONFIG_XFS_RICHACL +#define XFS_SB_FEAT_INCOMPAT_RICHACL (1 << 3)/* richacls */
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 470
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +4
-0+#else +#define XFS_SB_FEAT_INCOMPAT_RICHACL 0 +#endif +Regardless of whether we build in richacl support, this is wrong. Feature bits are on-disk format definitions, so it will always have this value whether or not the kernel supports the feature.
This is so that xfs_mount_validate_sb() will complain when mounting a richacl filesystem on a kernel which doesn't have richacl suport compiled in. The same effect can be had with extra code there of course.
Quoted 15 lines
fs/xfs/libxfs/xfs_format.h xfs_setattr_nonsize( · line 746
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +4
-1@@ -722,7 +737,10 @@ xfs_setattr_nonsize(* Posix ACL code seems to care about this issue either. */ if ((mask &ATTR_MODE ) && !(flags &XFS_ATTR_NOACL )) { - error =posix_acl_chmod (inode, inode->i_mode); +if (XFS_IS_RICHACL (inode)) + error =richacl_chmod (inode, inode->i_mode); +else + error =posix_acl_chmod (inode, inode->i_mode);if (error)return error; }This sort of thing could do with a helper like:
Quoted 7 lines
static inline int
xfs_acl_chmod(struct inode *inode, int mode){ if (IS_RICHACL(inode)) return richacl_chmod(inode, mode); return posix_acl_chmod(inode, mode); }
Alright.
Quoted 38 lines
fs/xfs/libxfs/xfs_format.h
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +11
-0+#include "xfs.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_inode.h" +#include "xfs_attr.h" + +#include <linux/richacl_xattr.h> + +struct richacl * +xfs_get_richacl (struct inode *inode) +{...
If we always build in ACL support, this can all go in
xfs_acl.c.Quoted 8 lines
fs/xfs/libxfs/xfs_format.h +8
-0+struct xfs_inode *ip =XFS_I (inode); +struct richacl *acl; +int size =XATTR_SIZE_MAX ; +void *value; +int error; + + value =kmem_zalloc_large (size,KM_SLEEP ); +if (!value)fs/xfs/libxfs/xfs_format.h
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+return ERR_PTR (-ENOMEM ); + + error =xfs_attr_get (ip,XATTR_NAME_RICHACL , value, &size,ATTR_ROOT ); +if (error) { +/* +* If the attribute doesn't exist make sure we have a negative +* cache entry, for any other error assume it is transient and +* leave the cache entry as ACL_NOT_CACHED. +*/ + acl = (error == -ENOATTR ) ?NULL :ERR_PTR (error);I rather dislike ternaries in code like this - it's hard to read the logic. Initalise acl to NULL, and then this simply becomes:
Quoted 2 lines
if (error != -ENOATTR)
acl = ERR_PTR(error);As you prefer.
Quoted 21 lines
Quoted 21 lines
fs/xfs/libxfs/xfs_format.h +21
-0+ }else + acl =richacl_from_xattr (&init_user_ns, value, size); + +if (!IS_ERR (acl)) +set_cached_richacl (inode, acl); +kfree (value); + +return acl; +} + +int +xfs_set_richacl (struct inode *inode,struct richacl *acl) +{ +struct xfs_inode *ip =XFS_I (inode); +umode_t mode = inode->i_mode; +int error; + +if (acl) { +/* Don't allow acls with unmapped identifiers. */ +if (richacl_has_unmapped_identifiers (acl)) +return -EINVAL ;
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +5
-0+ +if (richacl_equiv_mode (acl, &mode) ==0 ) { +xfs_set_mode (inode, mode); + acl =NULL ; + }Comment needed here - why does this now seem to accidentally fall through to removing the ACL?
Setting an ACL that is equivalent to a file mode is the same as removing any existing ACLs and doing a chmod to that equivalent file mode. It's the sams as with POSIX ACLs, and the code is the same as well. I'll add a comment though.
Quoted 2 lines
Also, why is this in the XFS specific
code when it's generic richacl functionality that is being checked?
This turns into two non-atomic operations if we move it into generic code.
Quoted 3 lines
Also, I really dislike the API where passing a NULL acl means to "set this acl" actually means "remove the existing ACL". Why no ->remove_acl method called from the generic code?
It's not uncommon, it saves inode operations and wiring-up code.
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h +8
-0+#ifndef __FS_XFS_RICHACL_H +#define __FS_XFS_RICHACL_H + +#include <linux/richacl.h> + +#ifdef CONFIG_XFS_RICHACL + +#define XFS_IS_RICHACL (inode) IS_RICHACL(inode)No. Just use
IS_RICHACL()everywhere, and whatever build conditional that uses.
Okay.
Quoted 16 lines
Quoted 16 lines
fs/xfs/xfs_super.c +9
-1@@ -1500,7 +1500,19 @@ xfs_fs_fill_super( sb->s_maxbytes =xfs_max_file_offset (sb->s_blocksize_bits); sb->s_max_links =XFS_MAXLINK ; sb->s_time_gran =1 ; -set_posix_acl_flag (sb); + +if (xfs_sb_version_hasrichacl (&mp->m_sb)) { +#ifdef CONFIG_XFS_RICHACL + sb->s_flags |=MS_RICHACL ; +#else + error = -EOPNOTSUPP ; + goto out_free_sb; +#endif + }else {
Quoted 8 lines
fs/xfs/xfs_super.c xfs_fs_fill_super( · line 1514
Quoted 3 lines
fs/xfs/xfs_super.c +3
-0+#ifdef CONFIG_XFS_POSIX_ACL + sb->s_flags |=MS_POSIXACL ; +#endif The whole point of having
set_posix_acl_flag()is that it keeps the ifdef hackery out of the code. If we are going to keep build time config options for these, then please keep the wrappers to hide this mess...
That can indeed go away since xfs_mount_validate_sb() checks the mount flags already.
Thanks,
Andreas
Re: [PATCH v10 24/46] xfs: Add richacl support
Quoted 29 lines · Andreas Grünbacher
2015-10-12 2:10 GMT+02:00 Dave Chinner <[email protected]>:
Quoted 19 lines · Andreas Gruenbacher
Quoted 18 lines
fs/xfs/Kconfig +10
-0@@ -52,6 +52,17 @@ config XFS_POSIX_ACL If you don't know what Access Control Lists are, say N. +config XFS_RICHACL + bool "XFS Rich Access Control Lists (EXPERIMENTAL)" + depends on XFS_FS + select FS_RICHACL + help + Richacls are an implementation of NFSv4 ACLs, extended by file masks + to cleanly integrate into the POSIX file permission model. To learn + more about them, see http://www.bestbits.at/richacl/. + + If you don't know what Richacls are, say N.Quoted 8 lines
fs/xfs/Kconfig config XFS_POSIX_ACL · line 65
Quoted 1 line
fs/xfs/Kconfig +1
-0+So now we have multiple compile time ACL configs that we have to test. Personally, I see no reason for making either posix or rich acls compile time dependent. How about we just change
CONFIG_FS_XFSto have "selectFS_POSIX_ACL" and "selectFS_RICHACL" unconditionally, and then we can get rid of all the conditional code?
Quoted 3 lines
I'm sure neither kind of ACLs makes sense on many tiny systems, it should be possible to disable them. XFS may not make sense on those kinds of systems either, that is not my call to make though.
Well, the smallest systems that use XFS are typically 1-2 disk NAS boxes, and I can see them wanting richacls. As it is, the xfs kernel module is almost 1MB of object code, so it you have a small embedded box you don't want XFS. Almost all distros turn on ACL support I'm not sure that it makes sense to have these config options in XFS anymore....
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +3
-0@@ -461,10 +461,18 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ + +#ifdef CONFIG_XFS_RICHACL +#define XFS_SB_FEAT_INCOMPAT_RICHACL (1 << 3)/* richacls */ Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 470
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +4
-0+#else +#define XFS_SB_FEAT_INCOMPAT_RICHACL 0 +#endif +Regardless of whether we build in richacl support, this is wrong. Feature bits are on-disk format definitions, so it will always have this value whether or not the kernel supports the feature.
Quoted 4 lines
This is so that
xfs_mount_validate_sb()will complain when mounting a richacl filesystem on a kernel which doesn't have richacl suport compiled in. The same effect can be had with extra code there of course.
If the kernel doesn't know about a feature, then it will report "unknown feature". However, as of this patch set, the kernel will know about the richacl feature, and so the correct error message is to say "Rich ACLs not supported by this kernel".
Also, from a disk format perspective, this is a this is a read-only compat feature, as kernels that don't have richacl support are still able to mount and walk the filesystem without errors occurring. It's only when allowing modifications are made that problems will arise, so why did you make it an incompat feature?
Quoted 25 lines
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +11
-0+int +xfs_set_richacl (struct inode *inode,struct richacl *acl) +{ +struct xfs_inode *ip =XFS_I (inode); +umode_t mode = inode->i_mode; +int error; + +if (acl) { +/* Don't allow acls with unmapped identifiers. */ +if (richacl_has_unmapped_identifiers (acl)) +return -EINVAL ;Quoted 8 lines
fs/xfs/libxfs/xfs_format.h
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +5
-0+ +if (richacl_equiv_mode (acl, &mode) ==0 ) { +xfs_set_mode (inode, mode); + acl =NULL ; + }Comment needed here - why does this now seem to accidentally fall through to removing the ACL?
Setting an ACL that is equivalent to a file mode is the same as removing any existing ACLs and doing a chmod to that equivalent file mode. It's the sams as with POSIX ACLs, and the code is the same as well. I'll add a comment though.
Quoted 4 lines
Quoted 2 lines
Also, why is this in the XFS specific
code when it's generic richacl functionality that is being checked?This turns into two non-atomic operations if we move it into generic code.
I don't follow you - this isn't an atomic operation to begin with...
Quoted 5 lines
Quoted 3 lines
Also, I really dislike the API where passing a NULL acl means to "set this acl" actually means "remove the existing ACL". Why no ->remove_acl method called from the generic code?
It's not uncommon, it saves inode operations and wiring-up code.
I know it's common. All it does is put extra branches in the filesystem code to do this, because remove is a different operation to set. The API sucks, and we're not limited on inode operations, and the operator overloading makes the filesystem code unnecessarily complex as it has to detect when to branch out ot remove or not...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v10 24/46] xfs: Add richacl support
Quoted 34 lines · Dave Chinner
Quoted 29 lines · Andreas Grünbacher
2015-10-12 2:10 GMT+02:00 Dave Chinner <[email protected]>:
Quoted 19 lines · Andreas Gruenbacher
Quoted 18 lines
fs/xfs/Kconfig +10
-0@@ -52,6 +52,17 @@ config XFS_POSIX_ACL If you don't know what Access Control Lists are, say N. +config XFS_RICHACL + bool "XFS Rich Access Control Lists (EXPERIMENTAL)" + depends on XFS_FS + select FS_RICHACL + help + Richacls are an implementation of NFSv4 ACLs, extended by file masks + to cleanly integrate into the POSIX file permission model. To learn + more about them, see http://www.bestbits.at/richacl/. + + If you don't know what Richacls are, say N.Quoted 8 lines
fs/xfs/Kconfig config XFS_POSIX_ACL · line 65
Quoted 1 line
fs/xfs/Kconfig +1
-0+So now we have multiple compile time ACL configs that we have to test. Personally, I see no reason for making either posix or rich acls compile time dependent. How about we just change
CONFIG_FS_XFSto have "selectFS_POSIX_ACL" and "selectFS_RICHACL" unconditionally, and then we can get rid of all the conditional code?Quoted 3 lines
I'm sure neither kind of ACLs makes sense on many tiny systems, it should be possible to disable them. XFS may not make sense on those kinds of systems either, that is not my call to make though.
Quoted 6 lines
Well, the smallest systems that use XFS are typically 1-2 disk NAS boxes, and I can see them wanting richacls. As it is, the xfs kernel module is almost 1MB of object code, so it you have a small embedded box you don't want XFS. Almost all distros turn on ACL support I'm not sure that it makes sense to have these config options in XFS anymore....
You have me convinced about removing CONFIG_XFS_RICHACL.
Quoted 30 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +3
-0@@ -461,10 +461,18 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ + +#ifdef CONFIG_XFS_RICHACL +#define XFS_SB_FEAT_INCOMPAT_RICHACL (1 << 3)/* richacls */ Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 470
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +4
-0+#else +#define XFS_SB_FEAT_INCOMPAT_RICHACL 0 +#endif +Regardless of whether we build in richacl support, this is wrong. Feature bits are on-disk format definitions, so it will always have this value whether or not the kernel supports the feature.
Quoted 4 lines
This is so that
xfs_mount_validate_sb()will complain when mounting a richacl filesystem on a kernel which doesn't have richacl suport compiled in. The same effect can be had with extra code there of course.If the kernel doesn't know about a feature, then it will report "unknown feature". However, as of this patch set, the kernel will know about the richacl feature, and so the correct error message is to say "Rich ACLs not supported by this kernel".
Quoted 5 lines
Also, from a disk format perspective, this is a this is a read-only compat feature, as kernels that don't have richacl support are still able to mount and walk the filesystem without errors occurring. It's only when allowing modifications are made that problems will arise, so why did you make it an incompat feature?
As a read-only compat flag, kernels that cannot enforce richacls would still be able to mount richacl file systems read-only. That's a problem when acls are used to forbid read/execute access.
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +11
-0+int +xfs_set_richacl (struct inode *inode,struct richacl *acl) +{ +struct xfs_inode *ip =XFS_I (inode); +umode_t mode = inode->i_mode; +int error; + +if (acl) { +/* Don't allow acls with unmapped identifiers. */ +if (richacl_has_unmapped_identifiers (acl)) +return -EINVAL ;Quoted 8 lines
fs/xfs/libxfs/xfs_format.h
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +5
-0+ +if (richacl_equiv_mode (acl, &mode) ==0 ) { +xfs_set_mode (inode, mode); + acl =NULL ; + }Comment needed here - why does this now seem to accidentally fall through to removing the ACL?
Setting an ACL that is equivalent to a file mode is the same as removing any existing ACLs and doing a chmod to that equivalent file mode. It's the sams as with POSIX ACLs, and the code is the same as well. I'll add a comment though.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Also, why is this in the XFS specific
code when it's generic richacl functionality that is being checked?This turns into two non-atomic operations if we move it into generic code.
I don't follow you - this isn't an atomic operation to begin with...
Right, I shouldn't have used the term atomic. It's one inode operation under i_mutex, and the filesystem can pack it into one transaction.
Thanks,
Andreas
Re: [PATCH v10 24/46] xfs: Add richacl support
Quoted 40 lines · Andreas Gruenbacher
Quoted 33 lines · Dave Chinner
Quoted 22 lines · Andreas Grünbacher
2015-10-12 2:10 GMT+02:00 Dave Chinner <[email protected]>:
Quoted 12 lines · Andreas Gruenbacher
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +3
-0@@ -461,10 +461,18 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ + +#ifdef CONFIG_XFS_RICHACL +#define XFS_SB_FEAT_INCOMPAT_RICHACL (1 << 3)/* richacls */ Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 470
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +4
-0+#else +#define XFS_SB_FEAT_INCOMPAT_RICHACL 0 +#endif +Regardless of whether we build in richacl support, this is wrong. Feature bits are on-disk format definitions, so it will always have this value whether or not the kernel supports the feature.
Quoted 4 lines
This is so that
xfs_mount_validate_sb()will complain when mounting a richacl filesystem on a kernel which doesn't have richacl suport compiled in. The same effect can be had with extra code there of course.If the kernel doesn't know about a feature, then it will report "unknown feature". However, as of this patch set, the kernel will know about the richacl feature, and so the correct error message is to say "Rich ACLs not supported by this kernel".
Quoted 5 lines
Also, from a disk format perspective, this is a this is a read-only compat feature, as kernels that don't have richacl support are still able to mount and walk the filesystem without errors occurring. It's only when allowing modifications are made that problems will arise, so why did you make it an incompat feature?
Quoted 3 lines
As a read-only compat flag, kernels that cannot enforce richacls would still be able to mount richacl file systems read-only. That's a problem when acls are used to forbid read/execute access.
It's also an irrelevant problem, anyone with a minimal knowledge of the filesystem's on-disk layout can unset the feature bit by hand and force it to be mounted anyway, thus bypassing the ACL's (this is the case for any filesystem, not just XFS). If someone has access to the hardware, they have access to the data stored on it, period, irrespective of what the data says about how it should be accessed.
The 3 most common cases for trying to mount a filesystem with this on a kernel that doesn't support it are:
a. Someone is trying to recover data on their own system using something like SystemRescueCD.
b. Someone is trying to recover data from a non-functional system that they own or have been authorized to access for this purpose by connecting the disk to another system. c. Someone is trying to bisect a kernel bug or track down what config option is causing them issues.
All three of these cases _need_ to keep working properly without needing to manually twiddle with compat bits, otherwise it _will_ cause a lot of people to advocate not using richacls.
Re: [PATCH v10 24/46] xfs: Add richacl support
In reply to Dave ChinnerQuoted 6 lines · Dave Chinner
Quoted 5 lines · Andreas Grünbacher
2015-10-12 2:10 GMT+02:00 Dave Chinner <[email protected]>:
Quoted 3 lines
Also, I really dislike the API where passing a NULL acl means to "set this acl" actually means "remove the existing ACL". Why no ->remove_acl method called from the generic code?
Quoted 7 lines
Quoted 1 line
It's not uncommon, it saves inode operations and wiring-up code.
I know it's common. All it does is put extra branches in the filesystem code to do this, because remove is a different operation to set. The API sucks, and we're not limited on inode operations, and the operator overloading makes the filesystem code unnecessarily complex as it has to detect when to branch out ot remove or not...
I've tried it out. The filesystem code could be simplified (see the richacl-wip [*] branch until the next posting). Adding a remove_richacl inode operation on top of that really doesn't help.
Thanks,
Andreas
[*] git://git.kernel.org/pub/scm/linux/kernel/git/agruen/linux-richacl.git
richacl-wip
PATCH v10 25/46 richacl: acl editing helper functions
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
The 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 | 155 +++++++++++++++++++++++++++++++++++++++++ include/linux/richacl_compat.h | 40 +++++++++++ 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 fs/richacl_compat.c create mode 100644 include/linux/richacl_compat.h
fs/Makefile +2 -1
@@ -49,7 +49,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 +155 -0
155 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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 26/46 richacl: Move everyone@ aces down the acl
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
The 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 an everyone@ deny ace is unneeded.
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
@@ -153,3 +153,68 @@ richace_change_mask(struct richacl_alloc *alloc, struct richace **ace, }return 0 ; } + +/** +* richacl_move_everyone_aces_down - move everyone@ aces to the end of the acl +* @alloc: 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 *alloc) +{ +struct richace *ace; +unsigned int allowed =0 , denied =0 ; + +richacl_for_each_entry (ace, alloc->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 (alloc, &ace,0 )) +return -1 ; + }else { +if (richace_is_allow (ace)) { +if (richace_change_mask (alloc, &ace, allowed | + (ace->e_mask & ~denied))) +return -1 ; + }else if (richace_is_deny (ace)) { +if (richace_change_mask (alloc, &ace, denied | + (ace->e_mask & ~allowed))) +return -1 ; + } + } + } +if (allowed & ~RICHACE_POSIX_ALWAYS_ALLOWED ) { +struct richace *last_ace = ace -1 ; + +if (alloc->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 (alloc, &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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 27/46 richacl: Propagate everyone@ permissions to other aces
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
The 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 | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+)
fs/richacl_compat.c +198 -0
@@ -218,3 +218,201 @@ richacl_move_everyone_aces_down(struct richacl_alloc *alloc) }return 0 ; } + +/** +* __richacl_propagate_everyone - propagate everyone@ permissions up for @who +* @alloc: 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 *alloc,struct richace *who, +unsigned int allow) +{ +struct richace *allow_last =NULL , *ace; +struct richacl *acl = alloc->acl; + +/* +* 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, 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 ; + } + } + ace--; + +/* +* If for group class entries, all the remaining permissions will +* remain granted by the trailing everyone@ allow ace, no additional +* entry is needed. +*/ +if (!richace_is_owner (who) && +richace_is_everyone (ace) && + !(allow & ~(ace->e_mask & acl->a_other_mask))) + allow =0 ; + +if (allow) { +if (allow_last) +return richace_change_mask (alloc, &allow_last, + allow_last->e_mask | allow); +else { +struct richace who_copy; + +richace_copy (&who_copy, who); +if (richacl_insert_entry (alloc, &ace)) +return -1 ; +richace_copy (ace, &who_copy); + ace->e_type =RICHACE_ACCESS_ALLOWED_ACE_TYPE ; + ace->e_flags &= ~RICHACE_INHERITANCE_FLAGS ; + ace->e_mask = allow; + } + } +return 0 ; +} + +/** +* richacl_propagate_everyone - propagate everyone@ permissions up the acl +* @alloc: acl and number of allocated entries +* +* Make sure that 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. We modify the permissions of +* existing entries or add new entries before the final everyone@ allow ace to +* achieve that. +* +* For example, the following acl implicitly grants everyone rwpx access: +* +* joe:r::allow +* everyone@:rwpx::allow +* +* When applying mode 0660 to this acl, group@ would lose rwp access, and joe +* would lose wp access even though the mode does not exclude those +* permissions. After propagating the everyone@ permissions, the result for +* applying mode 0660 becomes: +* +* owner@:rwp::allow +* joe:rwp::allow +* group@:rwp::allow +* +* Deny aces complicate the matter. For example, the following acl grants +* everyone but joe write access: +* +* joe:wp::deny +* everyone@:rwpx::allow +* +* When applying mode 0660 to this acl, group@ would lose rwp access, and joe +* would lose r access. After propagating the everyone@ permissions, the +* result for applying mode 0660 becomes: +* +* owner@:rwp::allow +* joe:w::deny +* group@:rwp::allow +* joe:r::allow +*/ +static int +richacl_propagate_everyone (struct richacl_alloc *alloc) +{ +struct richace who = { .e_flags =RICHACE_SPECIAL_WHO }; +struct richacl *acl = alloc->acl; +struct richace *ace; +unsigned int owner_allow, group_allow; + +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 ; + +/* +* Permissions the owner and group class are granted through the +* trailing everyone@ allow ace. +*/ + owner_allow = ace->e_mask & acl->a_owner_mask; + group_allow = ace->e_mask & acl->a_group_mask; + +/* +* If the group or other masks hide permissions which the owner should +* be allowed, we need to propagate those permissions up. Otherwise, +* those permissions may be lost when applying the other mask to the +* trailing everyone@ allow ace, or when isolating the group class from +* the other class through additional deny aces. +*/ +if (owner_allow & ~(acl->a_group_mask & acl->a_other_mask)) { +/* Propagate everyone@ permissions through to owner@. */ + who.e_id.special =RICHACE_OWNER_SPECIAL_ID ; +if (__richacl_propagate_everyone (alloc, &who, owner_allow)) +return -1 ; + acl = alloc->acl; + } + +/* +* If the other mask hides permissions which the group class should be +* allowed, we need to propagate those permissions up to the owning +* group and to all other members in the group class. +*/ +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 (alloc, &who, group_allow)) +return -1 ; + acl = alloc->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 ; + +/* +* Any inserted entry will end up below the current +* entry. +*/ +if (__richacl_propagate_everyone (alloc, ace, + group_allow)) +return -1 ; + acl = alloc->acl; + } + } +return 0 ; +}
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 28/46 richacl: Set the owner permissions to the owner mask
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
In the write-through case, change the acl so that owner@ is granted the permissions set in the owner mask (to match what the permission check algorithm grants the owner).
--- fs/richacl_compat.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
fs/richacl_compat.c +46 -0
@@ -416,3 +416,49 @@ richacl_propagate_everyone(struct richacl_alloc *alloc) }return 0 ; } + +/** +* richacl_set_owner_permissions - set the owner permissions to the owner mask +* +* In the write-through case, change the acl so that owner@ is granted the +* permissions set in the owner mask (to match what the permission check +* algorithm grants the owner). This leaves at most one efective owner@ allow +* entry at the beginning of the acl. +*/ +static int +richacl_set_owner_permissions (struct richacl_alloc *alloc) +{ +unsigned int x =RICHACE_POSIX_ALWAYS_ALLOWED ; +unsigned int owner_mask = alloc->acl->a_owner_mask & ~x; +unsigned int denied =0 ; +struct richace *ace; + +if (!((alloc->acl->a_flags &RICHACL_WRITE_THROUGH ))) +return 0 ; + +richacl_for_each_entry (ace, alloc->acl) { +if (richace_is_owner (ace)) { +if (richace_is_allow (ace) && !(owner_mask & denied)) { +richace_change_mask (alloc, &ace, owner_mask); + owner_mask =0 ; + }else +richace_change_mask (alloc, &ace,0 ); + }else { +if (richace_is_deny (ace)) + denied |= ace->e_mask; + } + } + +if (owner_mask & (denied | + ~alloc->acl->a_other_mask | + ~alloc->acl->a_group_mask)) { + ace = alloc->acl->a_entries; +if (richacl_insert_entry (alloc, &ace)) +return -1 ; + 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 ; + } +return 0 ; +}
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 29/46 richacl: Set the other permissions to the other mask
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Change the acl so that everyone@ is granted the permissions set in the other mask.
--- fs/richacl_compat.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
fs/richacl_compat.c +41 -0
@@ -462,3 +462,44 @@ richacl_set_owner_permissions(struct richacl_alloc *alloc) }return 0 ; } + +/** +* richacl_set_other_permissions - set the other permissions to the other mask +* @alloc: acl and number of allocated entries +* @added: permissions added for everyone@ +* +* Change the acl so that everyone@ is granted the permissions set in the other +* mask. This leaves at most one efective everyone@ allow entry at the end of +* the acl. If everyone@ end up being granted additional permissions, these +* permissions are returned in @added. +*/ +static int +richacl_set_other_permissions (struct richacl_alloc *alloc,unsigned int *added) +{ +struct richacl *acl = alloc->acl; +unsigned int x =RICHACE_POSIX_ALWAYS_ALLOWED ; +unsigned int other_mask = acl->a_other_mask & ~x; +struct richace *ace; + +if (!(other_mask && + (acl->a_flags &RICHACL_WRITE_THROUGH ))) +return 0 ; + + *added = other_mask; + ace = acl->a_entries + acl->a_count -1 ; +if (acl->a_count ==0 || + !richace_is_everyone (ace) || +richace_is_inherit_only (ace)) { + ace++; +if (richacl_insert_entry (alloc, &ace)) +return -1 ; + 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 ; + }else { + *added &= ~ace->e_mask; +richace_change_mask (alloc, &ace, other_mask); + } +return 0 ; +}
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 30/46 richacl: Isolate the owner and group classes
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
When 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 0446 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 | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)
fs/richacl_compat.c +223 -0
@@ -503,3 +503,226 @@ richacl_set_other_permissions(struct richacl_alloc *alloc, unsigned int *added) }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 +* @alloc: 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. For 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 permissions from other aces. For example, +* given this acl: +* +* everyone@:rwx::allow +* +* when file masks corresponding to mode 0406 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 the owner w access: +* +* owner@:w::deny +* owner@:r::allow +* everyone@:rw::allow +*/ +static int +richacl_isolate_owner_class (struct richacl_alloc *alloc) +{ +struct richacl *acl = alloc->acl; +struct richace *ace; +unsigned int deny; + + deny =richacl_max_allowed (acl) & ~acl->a_owner_mask; +if (!deny) +return 0 ; + +/* +* Figure out if we can update an existig OWNER@ DENY entry. +*/ +richacl_for_each_entry (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_allow (ace)) +break ; +if (richace_is_owner (ace)) +return richace_change_mask (alloc, &ace, + ace->e_mask | deny); + } + +/* Insert an owner@ deny entry at the front. */ + ace = acl->a_entries; +if (richacl_insert_entry (alloc, &ace)) +return -1 ; + ace->e_type =RICHACE_ACCESS_DENIED_ACE_TYPE ; + ace->e_flags =RICHACE_SPECIAL_WHO ; + ace->e_mask = deny; + ace->e_id.special =RICHACE_OWNER_SPECIAL_ID ; +return 0 ; +} + +/** +* __richacl_isolate_who - isolate entry from everyone@ allow entry +* @alloc: 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 *alloc,struct richace *who, +unsigned int deny) +{ +struct richacl *acl = alloc->acl; +struct richace *ace, who_copy; +int n; + +/* +* Compute the permissions already defined for @who. There are no +* everyone@ deny aces left in the acl at this stage. +*/ +richacl_for_each_entry (ace, acl) { +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_same_identifier (ace, who)) + 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 = acl->a_count -2 ; n !=-1 ; n--) { + ace = acl->a_entries + n; +if (richace_is_inherit_only (ace)) +continue ; +if (richace_is_deny (ace)) { +if (richace_is_same_identifier (ace, who)) +return richace_change_mask (alloc, &ace, + ace->e_mask | deny); + }else if (richace_is_allow (ace) && + (ace->e_mask & deny)) +break ; + } + +/* +* Insert a new entry before the trailing everyone@ deny entry. +*/ +richace_copy (&who_copy, who); + ace = acl->a_entries + acl->a_count -1 ; +if (richacl_insert_entry (alloc, &ace)) +return -1 ; +richace_copy (ace, &who_copy); + ace->e_type =RICHACE_ACCESS_DENIED_ACE_TYPE ; + ace->e_flags &= ~RICHACE_INHERITANCE_FLAGS ; + ace->e_mask = deny; +return 0 ; +} + +/** +* richacl_isolate_group_class - limit the group class to the group file mask +* @alloc: acl and number of allocated entries +* @deny: additional permissions to deny +* +* POSIX requires that after a chmod, the group class is granted no more +* permissions than the group file permission bits. For 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 *alloc,unsigned int deny) +{ +struct richace who = { + .e_flags =RICHACE_SPECIAL_WHO , + .e_id.special =RICHACE_GROUP_SPECIAL_ID , + }; +struct richace *ace; + +if (!alloc->acl->a_count) +return 0 ; + ace = alloc->acl->a_entries + alloc->acl->a_count -1 ; +if (richace_is_inherit_only (ace) || !richace_is_everyone (ace)) +return 0 ; + deny |= ace->e_mask & ~alloc->acl->a_group_mask; + +if (deny) { +unsigned int n; + +if (__richacl_isolate_who (alloc, &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 = alloc->acl->a_count -2 ; n !=-1 ; n--) { + ace = alloc->acl->a_entries + n; + +if (richace_is_inherit_only (ace) || +richace_is_owner (ace) || +richace_is_group (ace)) +continue ; +if (__richacl_isolate_who (alloc, ace, deny)) +return -1 ; + } + } +return 0 ; +}
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 31/46 richacl: Apply the file masks to a richacl
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Put 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
@@ -726,3 +726,104 @@ richacl_isolate_group_class(struct richacl_alloc *alloc, unsigned int deny) }return 0 ; } + +/** +* __richacl_apply_masks - apply the file masks to all aces +* @alloc: 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 *alloc,kuid_t owner) +{ +struct richace *ace; + +richacl_for_each_entry (ace, alloc->acl) { +unsigned int mask; + +if (richace_is_inherit_only (ace) || !richace_is_allow (ace)) +continue ; +if (richace_is_owner (ace) || + (richace_is_unix_user (ace) &&uid_eq (owner, ace->e_id.uid))) + mask = alloc->acl->a_owner_mask; +else if (richace_is_everyone (ace)) + mask = alloc->acl->a_other_mask; +else + mask = alloc->acl->a_group_mask; +if (richace_change_mask (alloc, &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 everyone is granted the other mask permissions. This step can +* elevate elevate permissions for the owner and group classes, which is +* corrected later. +* +* - Make sure that the group class is not granted any permissions from +* everyone@. +* +* - Make sure the owner is granted the owner mask permissions. +* +* - Make sure the owner is not granted any permissions beyond the owner +* mask from group class aces or from everyone@. +* +* 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,kuid_t owner) +{ +if ((*acl)->a_flags &RICHACL_MASKED ) { +struct richacl_alloc alloc = { + .acl =richacl_clone (*acl,GFP_KERNEL ), + .count = (*acl)->a_count, + }; +unsigned int added =0 ; + +if (!alloc.acl) +return -ENOMEM ; +if (richacl_move_everyone_aces_down (&alloc) || +richacl_propagate_everyone (&alloc) || +__richacl_apply_masks (&alloc, owner) || +richacl_set_other_permissions (&alloc, &added) || +richacl_isolate_group_class (&alloc, added) || +richacl_set_owner_permissions (&alloc) || +richacl_isolate_owner_class (&alloc)) { +richacl_put (alloc.acl); +return -ENOMEM ; + } + + alloc.acl->a_flags &= ~(RICHACL_WRITE_THROUGH |RICHACL_MASKED ); +richacl_put (*acl); + *acl = alloc.acl; + } +return 0 ; +} +EXPORT_SYMBOL_GPL (richacl_apply_masks);
include/linux/richacl.h +3 -0
@@ -333,4 +333,7 @@ extern int richacl_permission(struct inode *, const struct richacl *, int);extern int richacl_chmod (struct inode *,umode_t );extern struct richacl *richacl_create (umode_t *,struct inode *); +/* richacl_compat.c */ +extern int richacl_apply_masks (struct richacl **,kuid_t ); +#endif /* __RICHACL_H */
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 32/46 richacl: Create richacl from mode values
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
A file can have "no acl" in the sense that only the file mode permission bits determine access. In that case, the getxattr system call fails with errno == ENODATA (No such attribute).
Over the NFSv4 protocol, a file always has an acl, and we convert the file mode permission bits into an equivalent acl with richacl_from_mode. Such "trivial" acls can be converted back to a file mode with richacl_equiv_mode.
--- fs/richacl_compat.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 89 insertions(+)
fs/richacl_compat.c +88 -0
@@ -827,3 +827,91 @@ richacl_apply_masks(struct richacl **acl, kuid_t owner)return 0 ; }EXPORT_SYMBOL_GPL (richacl_apply_masks); + +/** +* richacl_from_mode - create an acl which corresponds to @mode +* +* The resulting acl doesn't have the RICHACL_MASKED flag set. +* +* @mode: file mode including the file type +*/ +struct richacl * +richacl_from_mode (umode_t mode) +{ +unsigned int owner_mask =richacl_mode_to_mask (mode >>6 ); +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; + +/* 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 ; + } + + denied = ~owner_mask & (group_mask | other_mask); +if (denied) + entries++;/* owner@ deny entry needed */ +if (owner_mask & ~(group_mask & other_mask)) + entries++;/* owner@ allow entry needed */ + denied = ~group_mask & other_mask; +if (denied) + entries++;/* group@ deny entry needed */ +if (group_mask & ~other_mask) + entries++;/* group@ allow entry needed */ +if (other_mask) + entries++;/* everyone@ allow entry needed */ + + acl =richacl_alloc (entries,GFP_KERNEL ); +if (!acl) +return NULL ; + acl->a_owner_mask = owner_mask; + acl->a_group_mask = group_mask; + acl->a_other_mask = other_mask; + ace = acl->a_entries; + + 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 (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 = ~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 (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++; + } +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);
include/linux/richacl.h +1 -0
@@ -335,5 +335,6 @@ extern struct richacl *richacl_create(umode_t *, struct inode *);/* richacl_compat.c */ extern int richacl_apply_masks (struct richacl **,kuid_t ); +extern struct richacl *richacl_from_mode (umode_t );#endif /* __RICHACL_H */
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 33/46 nfsd: Keep list of acls to dispose of in compoundargs
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
We will decode acls in requests into richacls. Even if unlikely, there can be more than one acl in a single request; those richacls need to be richacl_put() at the end of the request instead of kfree()d, so keep a list of acls in compoundargs for that.
--- fs/nfsd/nfs4xdr.c | 27 +++++++++++++++++++++++++++ fs/nfsd/xdr4.h | 6 ++++++ 2 files changed, 33 insertions(+)
fs/nfsd/nfs4xdr.c +27 -0
@@ -40,6 +40,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"
@@ -196,6 +197,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.
@@ -4437,6 +4456,13 @@ 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 ; }
@@ -4455,6 +4481,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
@@ -570,6 +570,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;
@@ -579,6 +584,7 @@ struct nfsd4_compoundargs {__be32 tmp[8 ];__be32 * tmpp;struct svcxdr_tmpbuf *to_free; +struct svcxdr_richacl *acls;struct svc_rqst *rqstp;
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 34/46 nfsd: Use richacls as internal acl representation
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
When 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 | 44 ++++++ fs/nfsd/Kconfig | 1 + fs/nfsd/acl.h | 24 ++-- fs/nfsd/nfs4acl.c | 368 ++++++++++++++++++++++-------------------------- 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, 274 insertions(+), 285 deletions(-) create mode 100644 fs/nfs_common/nfs4acl.c create mode 100644 include/linux/nfs4acl.h
fs/Kconfig +6 -0
@@ -265,6 +265,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 +44 -0
44 lines not on this page · raw message
fs/nfsd/Kconfig +1 -0
@@ -70,6 +70,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 -198
611 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 ;
@@ -672,8 +672,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);
@@ -938,8 +937,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
@@ -118,7 +118,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_file *op_file;/* used during processing */ struct nfs4_ol_stateid *op_stp;/* used during processing */ struct nfs4_clnt_odstate *op_odstate;/* used during processing */ -struct nfs4_acl *op_acl; +struct richacl *op_acl;struct xdr_netobj op_label; };
@@ -332,7 +332,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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 35/46 nfsd: Add richacl support
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
On file systems with richacls enabled, get and set richacls directly instead of converting from / to posix acls.
--- fs/nfsd/acl.h | 3 +- fs/nfsd/nfs4acl.c | 124 ++++++++++++++++++++++++++++++++++++++--------------- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4xdr.c | 34 +++++++++++---- 4 files changed, 117 insertions(+), 46 deletions(-)
fs/nfsd/acl.h +1 -2
@@ -53,8 +53,7 @@ __be32 nfsd4_decode_ace_who(struct richace *ace, struct svc_rqst *rqstp,__be32 nfsd4_encode_ace_who (struct xdr_stream *xdr,struct svc_rqst *rqstp,struct richace *ace); -int nfsd4_get_acl (struct svc_rqst *rqstp,struct dentry *dentry, -struct richacl **acl); +struct richacl *nfsd4_get_acl (struct svc_rqst *rqstp,struct dentry *dentry);__be32 nfsd4_set_acl (struct svc_rqst *rqstp,struct svc_fh *fhp,struct richacl *acl);
fs/nfsd/nfs4acl.c +89 -35
203 lines not on this page · raw message
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 (d_inode (dentry))) +if (!IS_ACL (d_inode (dentry)))return nfserr_attrnotsupp; }
fs/nfsd/nfs4xdr.c +26 -8
@@ -340,11 +340,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 & ~NFS4_ACE_MASK_ALL ) +return nfserr_inval; + ace->e_mask = dummy32; + dummy32 =be32_to_cpup (p++);READ_BUF (dummy32); len +=XDR_QUADLEN (dummy32) <<2 ;
@@ -2330,7 +2343,11 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, fhp = tempfh; }if (bmval0 &FATTR4_WORD0_ACL ) { - err =nfsd4_get_acl (rqstp, dentry, &acl); + acl =nfsd4_get_acl (rqstp, dentry); +if (IS_ERR (acl)) { + err =PTR_ERR (acl); + acl =NULL ; + }if (err == -EOPNOTSUPP ) bmval0 &= ~FATTR4_WORD0_ACL ;else if (err == -EINVAL ) {
@@ -2370,7 +2387,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,u32 word1 =nfsd_suppattrs1 (minorversion);u32 word2 =nfsd_suppattrs2 (minorversion); -if (!IS_POSIXACL (dentry->d_inode)) +if (!IS_ACL (d_inode (dentry))) word0 &= ~FATTR4_WORD0_ACL ;if (!contextsupport) word2 &= ~FATTR4_WORD2_SECURITY_LABEL ;
@@ -2505,7 +2522,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,if (!p) goto out_resource; *p++ =cpu_to_be32 (ace->e_type); - *p++ =cpu_to_be32 (ace->e_flags & ~RICHACE_SPECIAL_WHO ); + *p++ =cpu_to_be32 (ace->e_flags & + ~(RICHACE_SPECIAL_WHO |RICHACE_INHERITED_ACE )); *p++ =cpu_to_be32 (ace->e_mask &NFS4_ACE_MASK_ALL ); status =nfsd4_encode_ace_who (xdr, rqstp, ace);if (status)
@@ -2517,7 +2535,7 @@ out_acl: p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; - *p++ =cpu_to_be32 (IS_POSIXACL (dentry->d_inode) ? + *p++ =cpu_to_be32 (IS_ACL (d_inode (dentry)) ?ACL4_SUPPORT_ALLOW_ACL |ACL4_SUPPORT_DENY_ACL :0 ); }if (bmval0 &FATTR4_WORD0_CANSETTIME ) {
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 36/46 nfsd: Add support for the v4.1 dacl attribute
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Richacls support the Automatic Inheritance permission propagation mechanism as specified in NFSv4.1. Over NFS, this requires support for the dacl attribute: compared to the acl attribute, the dacl attribute has an additional flags field which indicates when Automatic Inheritance is in use.
The server will only indicate dacl attribute support in protocol version 4.1 and later, on file systems with richacl support.
This commit also adds support for the NFSv4.1 NFS4_ACE_WRITE_RETENTION and NFS4_ACE_WRITE_RETENTION_HOLD ACL permissions.
--- fs/nfsd/nfs4proc.c | 3 +- fs/nfsd/nfs4xdr.c | 219 ++++++++++++++++++++++++++++++---------------- fs/nfsd/nfsd.h | 6 +- include/linux/nfs4.h | 1 + include/uapi/linux/nfs4.h | 3 +- 5 files changed, 155 insertions(+), 77 deletions(-)
fs/nfsd/nfs4proc.c +2 -1
@@ -1781,7 +1781,8 @@ static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,u32 bmap0 = bmap[0 ], bmap1 = bmap[1 ], bmap2 = bmap[2 ];u32 ret =0 ; -if (bmap0 &FATTR4_WORD0_ACL ) +if (bmap0 &FATTR4_WORD0_ACL || + bmap1 &FATTR4_WORD1_DACL )return svc_max_payload (rqstp);if (bmap0 &FATTR4_WORD0_FS_LOCATIONS )return svc_max_payload (rqstp);
fs/nfsd/nfs4xdr.c +146 -73
282 lines not on this page · raw message
fs/nfsd/nfsd.h +4 -2
@@ -339,7 +339,8 @@ void nfsd_lockd_shutdown(void); NFSD4_SUPPORTED_ATTRS_WORD0#define NFSD4_1_SUPPORTED_ATTRS_WORD1 \ - (NFSD4_SUPPORTED_ATTRS_WORD1 | PNFSD_SUPPORTED_ATTRS_WORD1) + (NFSD4_SUPPORTED_ATTRS_WORD1 | PNFSD_SUPPORTED_ATTRS_WORD1 | \ + FATTR4_WORD1_DACL)#define NFSD4_1_SUPPORTED_ATTRS_WORD2 \ (NFSD4_SUPPORTED_ATTRS_WORD2 | PNFSD_SUPPORTED_ATTRS_WORD2 | \
@@ -386,7 +387,8 @@ static inline u32 nfsd_suppattrs2(u32 minorversion) (FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL)#define NFSD_WRITEABLE_ATTRS_WORD1 \ (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \ - | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET) + | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET \ + | FATTR4_WORD1_DACL)#ifdef CONFIG_NFSD_V4_SECURITY_LABEL #define NFSD_WRITEABLE_ATTRS_WORD2 FATTR4_WORD2_SECURITY_LABEL#else
include/linux/nfs4.h +1 -0
@@ -394,6 +394,7 @@ enum lock_type4 {#define FATTR4_WORD1_TIME_MODIFY (1UL << 21)#define FATTR4_WORD1_TIME_MODIFY_SET (1UL << 22)#define FATTR4_WORD1_MOUNTED_ON_FILEID (1UL << 23) +#define FATTR4_WORD1_DACL (1UL << 26)#define FATTR4_WORD1_FS_LAYOUT_TYPES (1UL << 30)#define FATTR4_WORD2_LAYOUT_TYPES (1UL << 0)#define FATTR4_WORD2_LAYOUT_BLKSIZE (1UL << 1)
include/uapi/linux/nfs4.h +2 -1
@@ -121,7 +121,8 @@#define NFS4_ACE_GENERIC_READ 0x00120081#define NFS4_ACE_GENERIC_WRITE 0x00160106#define NFS4_ACE_GENERIC_EXECUTE 0x001200A0 -#define NFS4_ACE_MASK_ALL 0x001F01FF +#define NFS40_ACE_MASK_ALL 0x001F01FF +#define NFS4_ACE_MASK_ALL 0x001F07FF#define EXCHGID4_FLAG_SUPP_MOVED_REFER 0x00000001#define EXCHGID4_FLAG_SUPP_MOVED_MIGR 0x00000002
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 37/46 nfsd: Add support for the MAY_CREATE_{FILE,DIR} permissions
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
For local file systems, the vfs performs the necessary permission checks for operations like creating files and directories. NFSd duplicates several of those checks. The vfs checks have been extended to check for additional permissions like MAY_CREATE_FILE and MY_CREATE_DIR; the nfsd checks currently lack those extensions.
Ideally, all duplicate checks should be removed; for now, just fix the duplicate checks instead though.
--- fs/nfsd/nfs4proc.c | 5 +++-- fs/nfsd/nfsfh.c | 8 ++++---- fs/nfsd/vfs.c | 28 ++++++++++++++++++++-------- fs/nfsd/vfs.h | 17 +++++++++-------- 4 files changed, 36 insertions(+), 22 deletions(-)
fs/nfsd/nfs4proc.c +3 -2
@@ -599,14 +599,15 @@ static __be32 nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_create *create) { + int access = create->cr_type == NF4DIR ? +NFSD_MAY_CREATE_DIR :NFSD_MAY_CREATE_FILE ;struct svc_fh resfh;__be32 status;dev_t rdev;fh_init (&resfh,NFS4_FHSIZE ); - status =fh_verify (rqstp, &cstate->current_fh,S_IFDIR , -NFSD_MAY_CREATE ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFDIR , access);if (status)return status;
fs/nfsd/nfsfh.c +4 -4
@@ -319,10 +319,10 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)/* * We still have to do all these permission checks, even when * fh_dentry is already set: -* - fh_verify may be called multiple times with different -* "access" arguments (e.g. nfsd_proc_create calls -* fh_verify(...,NFSD_MAY_EXEC) first, then later (in -* nfsd_create) calls fh_verify(...,NFSD_MAY_CREATE). +* - fh_verify may be called multiple times with different +* "access" arguments (e.g. nfsd_proc_create calls +* fh_verify(...,NFSD_MAY_EXEC) first, then later (in +* nfsd_create) calls fh_verify(...,NFSD_MAY_CREATE_FILE). * - in the NFSv4 case, the filehandle may have been filled * in by fh_compose, and given a dentry, but further * compound operations performed with that filehandle
fs/nfsd/vfs.c +20 -8
@@ -1128,6 +1128,8 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,__be32 err;__be32 err2;int host_err; +int access = (type ==S_IFDIR ) ? +NFSD_MAY_CREATE_DIR :NFSD_MAY_CREATE_FILE ; err = nfserr_perm;if (!flen)
@@ -1136,7 +1138,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,if (isdotent (fname, flen)) goto out; - err =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); + err =fh_verify (rqstp, fhp,S_IFDIR , access);if (err) goto out;
@@ -1301,7 +1303,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,/* If file doesn't exist, check for permissions to create one */ if (d_really_is_negative (dchild)) { - err =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); + err =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE_FILE );if (err) goto out; }
@@ -1485,7 +1487,7 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,if (isdotent (fname, flen)) goto out; - err =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); + err =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE_FILE );if (err) goto out;
@@ -1532,7 +1534,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,__be32 err;int host_err; - err =fh_verify (rqstp, ffhp,S_IFDIR ,NFSD_MAY_CREATE ); + err =fh_verify (rqstp, ffhp,S_IFDIR ,NFSD_MAY_CREATE_FILE );if (err) goto out; err =fh_verify (rqstp, tfhp,0 ,NFSD_MAY_NOP );
@@ -1604,11 +1606,12 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,struct inode *fdir, *tdir;__be32 err;int host_err; +int access; err =fh_verify (rqstp, ffhp,S_IFDIR ,NFSD_MAY_REMOVE );if (err) goto out; - err =fh_verify (rqstp, tfhp,S_IFDIR ,NFSD_MAY_CREATE ); + err =fh_verify (rqstp, tfhp,S_IFDIR ,NFSD_MAY_NOP );if (err) goto out;
@@ -1647,6 +1650,13 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,if (odentry == trap) goto out_dput_old; + host_err =0 ; + access =S_ISDIR (d_inode (odentry)->i_mode) ? +NFSD_MAY_CREATE_DIR :NFSD_MAY_CREATE_FILE ; + err =fh_verify (rqstp, tfhp,S_IFDIR , access); +if (err) + goto out_dput_old; + ndentry =lookup_one_len (tname, tdentry, tlen); host_err =PTR_ERR (ndentry);if (IS_ERR (ndentry))
@@ -1672,7 +1682,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, out_dput_old:dput (odentry); out_nfserr: - err =nfserrno (host_err); +if (host_err) + err =nfserrno (host_err);/* * We cannot rely on fh_unlock on the two filehandles, * as that would do the wrong thing if the two directories
@@ -2005,8 +2016,9 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp, uid_eq(inode->i_uid, current_fsuid()))return 0 ; -/* This assumes NFSD_MAY_{READ,WRITE,EXEC} == MAY_{READ,WRITE,EXEC} */ - err =inode_permission (inode, acc & (MAY_READ |MAY_WRITE |MAY_EXEC )); +/* This assumes NFSD_MAY_{READ,WRITE,EXEC} == MAY_{READ,WRITE,EXEC}. */ + err =inode_permission (inode, acc & (MAY_READ |MAY_WRITE |MAY_EXEC | +MAY_CREATE_DIR |MAY_CREATE_FILE ));/* Allow read access to binaries even when mode 111 */ if (err == -EACCES && S_ISREG(inode->i_mode) &&
fs/nfsd/vfs.h +9 -8
@@ -19,18 +19,19 @@#define NFSD_MAY_TRUNC 0x010#define NFSD_MAY_LOCK 0x020#define NFSD_MAY_MASK 0x03f +#define NFSD_MAY_CREATE_FILE 0x103/* == MAY_{EXEC|WRITE|CREATE_FILE} */ +#define NFSD_MAY_CREATE_DIR 0x203/* == MAY_{EXEC|WRITE|CREATE_DIR} */ /* extra hints to permission and open routines: */ -#define NFSD_MAY_OWNER_OVERRIDE 0x040 -#define NFSD_MAY_LOCAL_ACCESS 0x080/* for device special files */ -#define NFSD_MAY_BYPASS_GSS_ON_ROOT 0x100 -#define NFSD_MAY_NOT_BREAK_LEASE 0x200 -#define NFSD_MAY_BYPASS_GSS 0x400 -#define NFSD_MAY_READ_IF_EXEC 0x800 +#define NFSD_MAY_OWNER_OVERRIDE 0x04000 +#define NFSD_MAY_LOCAL_ACCESS 0x08000/* for device special files */ +#define NFSD_MAY_BYPASS_GSS_ON_ROOT 0x10000 +#define NFSD_MAY_NOT_BREAK_LEASE 0x20000 +#define NFSD_MAY_BYPASS_GSS 0x40000 +#define NFSD_MAY_READ_IF_EXEC 0x80000 -#define NFSD_MAY_64BIT_COOKIE 0x1000/* 64 bit readdir cookies for >= NFSv3 */ +#define NFSD_MAY_64BIT_COOKIE 0x100000/* 64 bit readdir cookies for >= NFSv3 */ -#define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE)#define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)/*
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 38/46 richacl: Add support for unmapped identifiers
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Some remote file systems like nfs may return user or group identifiers that cannot be mapped to local uids / gids. Allow to represent such unmapped identifiers in richacls. (We still cannot represent unmapped owners and owning groups, however.)
In the in-memory representation, the richacl is followed by a list of NUL-terminated strings, with no padding. Entries with an unmapped identifier have the RICHACE_UNMAPPED_WHO flag set, and ace->e_id.offs specifies the offset into this list. Multiple entries can refer to the same offset.
The xattr representation is similar, but ace->e_id is ignored, and the list of unmapped identifier strings contains a string for each acl entry whose RICHACE_UNMAPPED_WHO flag is set.
--- fs/richacl_base.c | 139 ++++++++++++++++++++++++++++++++++++++++++++---- fs/richacl_compat.c | 18 +++---- fs/richacl_inode.c | 4 +- fs/richacl_xattr.c | 69 ++++++++++++++++++++---- include/linux/richacl.h | 33 ++++++++++-- 5 files changed, 227 insertions(+), 36 deletions(-)
fs/richacl_base.c +130 -9
@@ -23,22 +23,25 @@MODULE_LICENSE ("GPL" );/** -* richacl_alloc - allocate a richacl +* __richacl_alloc - allocate a richacl * @count: number of entries +* @unmapped_size: size to reserve for unmapped identifiers */ struct richacl * -richacl_alloc (int count,gfp_t gfp) +__richacl_alloc (unsigned int count,size_t unmapped_size,gfp_t gfp) { -size_t size =sizeof (struct richacl ) + count *sizeof (struct richace ); +size_t size =sizeof (struct richacl ) + count *sizeof (struct richace ) + + unmapped_size;struct richacl *acl =kzalloc (size, gfp);if (acl) {atomic_set (&acl->a_base.ba_refcount,1 ); acl->a_count = count; + acl->a_unmapped_size = unmapped_size; }return acl; } -EXPORT_SYMBOL_GPL (richacl_alloc); +EXPORT_SYMBOL_GPL (__richacl_alloc);/** * richacl_clone - create a copy of a richacl
@@ -47,7 +50,8 @@ struct richacl * richacl_clone(const struct richacl *acl, gfp_t gfp) { int count = acl->a_count; -size_t size =sizeof (struct richacl ) + count *sizeof (struct richace ); +size_t size =sizeof (struct richacl ) + count *sizeof (struct richace ) + + acl->a_unmapped_size;struct richacl *dup =kmalloc (size, gfp);if (dup) {
@@ -59,6 +63,9 @@ richacl_clone(const struct richacl *acl, gfp_t gfp)/** * richace_copy - copy an acl entry +* +* If @from has an unmapped who value (from->e_flags & RICHACE_UNMAPPED_WHO), +* it can only be copied within the same acl! */ void richace_copy (struct richace *to,const struct richace *from)
@@ -66,6 +73,82 @@ richace_copy(struct richace *to, const struct richace *from)memcpy (to, from,sizeof (struct richace )); } +/** +* richacl_add_unmapped_identifier +* @pacl: Pointer to an acl +* @pace: acl entry within @acl +* @who: unmapped identifier +* @len: length of @who +* @gfp: memory allocation flags +* +* Add an unmapped identifier to an acl, possibly reallocating the acl. +*/ +int richacl_add_unmapped_identifier (struct richacl **pacl, +struct richace **pace, +const char *who, +unsigned int len,gfp_t gfp) +{ +struct richacl *acl = *pacl; +size_t size =sizeof (struct richacl ) + + acl->a_count *sizeof (struct richace ) + + acl->a_unmapped_size + len +1 ; +unsigned int index = *pace - acl->a_entries; + + acl =krealloc (*pacl, size, gfp); +if (acl) { +char *unmapped = (char *)(acl->a_entries + acl->a_count); +struct richace *ace = acl->a_entries + index; + + ace->e_flags |=RICHACE_UNMAPPED_WHO ; + ace->e_flags &= ~RICHACE_SPECIAL_WHO ; + ace->e_id.offs = acl->a_unmapped_size; +memcpy (unmapped + ace->e_id.offs, who, len); + unmapped[ace->e_id.offs + len] =0 ; + acl->a_unmapped_size += len +1 ; + *pace = ace; + *pacl = acl; +return 0 ; + } +return -1 ; +} +EXPORT_SYMBOL_GPL (richacl_add_unmapped_identifier); + +/** +* richace_unmapped_identifier - get unmapped identifier +* @acl: acl containing @ace +* @ace: acl entry +* +* Get the unmapped identifier of @ace as a NUL-terminated string, or NULL if +* @ace doesn't have an unmapped identifier. +*/ +const char *richace_unmapped_identifier (const struct richace *ace, +const struct richacl *acl) +{ +const char *unmapped = (char *)(acl->a_entries + acl->a_count); + +if (!(ace->e_flags &RICHACE_UNMAPPED_WHO )) +return NULL ; +return unmapped + ace->e_id.offs; +} +EXPORT_SYMBOL (richace_unmapped_identifier); + +/** +* richacl_has_unmapped_identifiers +* +* Check if an acl has unmapped identifiers. +*/ +bool richacl_has_unmapped_identifiers (struct richacl *acl) +{ +struct richace *ace; + +richacl_for_each_entry (ace, acl) { +if (ace->e_flags &RICHACE_UNMAPPED_WHO ) +return true; + } +return false; +} +EXPORT_SYMBOL_GPL (richacl_has_unmapped_identifiers); +/* * richacl_mask_to_mode - compute the file permission bits from mask * @mask: %RICHACE_* permission mask
@@ -214,7 +297,7 @@ static unsigned int richacl_allowed_to_who(struct richacl *acl,richacl_for_each_entry_reverse (ace, acl) {if (richace_is_inherit_only (ace))continue ; -if (richace_is_same_identifier (ace, who) || +if (richace_is_same_identifier (acl, ace, who) ||richace_is_everyone (ace)) {if (richace_is_allow (ace)) allowed |= ace->e_mask;
@@ -505,45 +588,72 @@ richacl_inherit(const struct richacl *dir_acl, int isdir)const struct richace *dir_ace;struct richacl *acl =NULL ;struct richace *ace; -int count =0 ; +unsigned int count =0 , unmapped_size =0 , offset =0 ; +const char *dir_unmapped; +char *unmapped;if (isdir) {richacl_for_each_entry (dir_ace, dir_acl) {if (!richace_is_inheritable (dir_ace))continue ; + count++; + dir_unmapped = +richace_unmapped_identifier (dir_ace, dir_acl); +if (dir_unmapped) + unmapped_size +=strlen (dir_unmapped) +1 ; }if (!count)return NULL ; - acl =richacl_alloc (count,GFP_KERNEL ); + acl =__richacl_alloc (count, unmapped_size,GFP_KERNEL );if (!acl)return ERR_PTR (-ENOMEM ); ace = acl->a_entries; + unmapped = (char *)(acl->a_entries + acl->a_count);richacl_for_each_entry (dir_ace, dir_acl) {if (!richace_is_inheritable (dir_ace))continue ; +richace_copy (ace, dir_ace);if (dir_ace->e_flags &RICHACE_NO_PROPAGATE_INHERIT_ACE ) ace->e_flags &= ~RICHACE_INHERITANCE_FLAGS ;else if (!(dir_ace->e_flags &RICHACE_DIRECTORY_INHERIT_ACE )) ace->e_flags |=RICHACE_INHERIT_ONLY_ACE ; + + dir_unmapped = +richace_unmapped_identifier (dir_ace, dir_acl); +if (dir_unmapped) { +size_t sz =strlen (dir_unmapped) +1 ; + + ace->e_id.offs = offset; +memcpy (unmapped, dir_unmapped, sz); + unmapped += sz; + offset += sz; + } ace++; } }else {richacl_for_each_entry (dir_ace, dir_acl) {if (!(dir_ace->e_flags &RICHACE_FILE_INHERIT_ACE ))continue ; + count++; + dir_unmapped = +richace_unmapped_identifier (dir_ace, dir_acl); +if (dir_unmapped) + unmapped_size +=strlen (dir_unmapped) +1 ; }if (!count)return NULL ; - acl =richacl_alloc (count,GFP_KERNEL ); + acl =__richacl_alloc (count, unmapped_size,GFP_KERNEL );if (!acl)return ERR_PTR (-ENOMEM ); ace = acl->a_entries; + unmapped = (char *)(acl->a_entries + acl->a_count);richacl_for_each_entry (dir_ace, dir_acl) {if (!(dir_ace->e_flags &RICHACE_FILE_INHERIT_ACE ))continue ; +richace_copy (ace, dir_ace); ace->e_flags &= ~RICHACE_INHERITANCE_FLAGS ;/*
@@ -551,6 +661,17 @@ richacl_inherit(const struct richacl *dir_acl, int isdir)* non-directories, so clear it. */ ace->e_mask &= ~RICHACE_DELETE_CHILD ; + + dir_unmapped = +richace_unmapped_identifier (dir_ace, dir_acl); +if (dir_unmapped) { +size_t sz =strlen (dir_unmapped) +1 ; + + ace->e_id.offs = offset; +memcpy (unmapped, dir_unmapped, sz); + unmapped += sz; + offset += sz; + } ace++; } }
fs/richacl_compat.c +8 -10
@@ -71,11 +71,13 @@ richacl_insert_entry(struct richacl_alloc *alloc, struct richace **ace) {struct richacl *acl = alloc->acl;unsigned int index = *ace - acl->a_entries; -size_t tail_size = (acl->a_count - index) *sizeof (struct richace ); +size_t tail_size = (acl->a_count - index) *sizeof (struct richace ) + + acl->a_unmapped_size;if (alloc->count == acl->a_count) {size_t new_size =sizeof (struct richacl ) + - (acl->a_count +1 ) *sizeof (struct richace ); + (acl->a_count +1 ) *sizeof (struct richace ) + + acl->a_unmapped_size; acl =krealloc (acl, new_size,GFP_KERNEL );if (!acl)
@@ -103,10 +105,6 @@ struct richace *richacl_append_entry(struct richacl_alloc *alloc)struct richacl *acl = alloc->acl;struct richace *ace = acl->a_entries + acl->a_count; -if (alloc->count > alloc->acl->a_count) { - acl->a_count++; -return ace; - }return richacl_insert_entry (alloc, &ace) ?NULL : ace; }EXPORT_SYMBOL_GPL (richacl_append_entry);
@@ -261,12 +259,12 @@ __richacl_propagate_everyone(struct richacl_alloc *alloc, struct richace *who,if (richace_is_inherit_only (ace))continue ;if (richace_is_allow (ace)) { -if (richace_is_same_identifier (ace, who)) { +if (richace_is_same_identifier (acl, ace, who)) { allow &= ~ace->e_mask; allow_last = ace; } }else if (richace_is_deny (ace)) { -if (richace_is_same_identifier (ace, who)) +if (richace_is_same_identifier (acl, ace, who)) allow &= ~ace->e_mask;else if (allow & ace->e_mask) allow_last =NULL ;
@@ -613,7 +611,7 @@ __richacl_isolate_who(struct richacl_alloc *alloc, struct richace *who,richacl_for_each_entry (ace, acl) {if (richace_is_inherit_only (ace))continue ; -if (richace_is_same_identifier (ace, who)) +if (richace_is_same_identifier (acl, ace, who)) deny &= ~ace->e_mask; }if (!deny)
@@ -629,7 +627,7 @@ __richacl_isolate_who(struct richacl_alloc *alloc, struct richace *who,if (richace_is_inherit_only (ace))continue ;if (richace_is_deny (ace)) { -if (richace_is_same_identifier (ace, who)) +if (richace_is_same_identifier (acl, ace, who))return richace_change_mask (alloc, &ace, ace->e_mask | deny); } else if (richace_is_allow(ace) &&
fs/richacl_inode.c +3 -1
@@ -161,8 +161,10 @@ richacl_permission(struct inode *inode, const struct richacl *acl, }else if (richace_is_unix_group (ace)) {if (!in_group_p (ace->e_id.gid))continue ; - }else + }else if (richace_is_everyone (ace)) goto entry_matches_everyone; +else +continue ;/* * Apply the group file mask to entries other than owner@ and
fs/richacl_xattr.c +58 -11
136 lines not on this page · raw message
include/linux/richacl.h +28 -5
@@ -29,6 +29,7 @@ struct richace {kuid_t uid;kgid_t gid;unsigned int special; +unsigned short offs;/* unmapped offset */ } e_id; };
@@ -39,6 +40,7 @@ struct richacl {unsigned int a_other_mask;unsigned short a_count;unsigned short a_flags; +unsigned short a_unmapped_size;struct richace a_entries[0 ]; };
@@ -77,6 +79,7 @@ struct richacl {#define RICHACE_INHERIT_ONLY_ACE 0x0008#define RICHACE_IDENTIFIER_GROUP 0x0040#define RICHACE_INHERITED_ACE 0x0080 +#define RICHACE_UNMAPPED_WHO 0x2000#define RICHACE_SPECIAL_WHO 0x4000#define RICHACE_VALID_FLAGS ( \
@@ -86,6 +89,7 @@ struct richacl { RICHACE_INHERIT_ONLY_ACE | \ RICHACE_IDENTIFIER_GROUP | \ RICHACE_INHERITED_ACE | \ + RICHACE_UNMAPPED_WHO | \ RICHACE_SPECIAL_WHO)#define RICHACE_INHERITANCE_FLAGS ( \
@@ -310,14 +314,28 @@ richace_is_deny(const struct richace *ace)* richace_is_same_identifier - are both identifiers the same? */ static inline bool -richace_is_same_identifier (const struct richace *a,const struct richace *b) +richace_is_same_identifier (const struct richacl *acl, +const struct richace *ace1, +const struct richace *ace2) { -return !((a->e_flags ^ b->e_flags) & - (RICHACE_SPECIAL_WHO |RICHACE_IDENTIFIER_GROUP )) && - !memcmp (&a->e_id, &b->e_id,sizeof (a->e_id)); +const char *unmapped = (char *)(acl->a_entries + acl->a_count); + +return !((ace1->e_flags ^ ace2->e_flags) & + (RICHACE_SPECIAL_WHO | +RICHACE_IDENTIFIER_GROUP | +RICHACE_UNMAPPED_WHO )) && + ((ace1->e_flags &RICHACE_UNMAPPED_WHO ) ? + !strcmp (unmapped + ace1->e_id.offs, + unmapped + ace2->e_id.offs) : + !memcmp (&ace1->e_id, &ace2->e_id,sizeof (ace1->e_id))); +} + +extern struct richacl *__richacl_alloc (unsigned int ,size_t ,gfp_t ); +static inline struct richacl *richacl_alloc (unsigned int count,gfp_t gfp) +{ +return __richacl_alloc (count,0 , gfp); } -extern struct richacl *richacl_alloc (int ,gfp_t );extern struct richacl *richacl_clone (const struct richacl *,gfp_t );extern void richace_copy (struct richace *,const struct richace *);extern int richacl_masks_to_mode (const struct richacl *);
@@ -327,6 +345,11 @@ extern void richacl_compute_max_masks(struct richacl *);extern struct richacl *__richacl_chmod (struct richacl *,umode_t );extern int richacl_equiv_mode (const struct richacl *,umode_t *);extern struct richacl *richacl_inherit (const struct richacl *,int ); +extern int richacl_add_unmapped_identifier (struct richacl **,struct richace **, +const char *,unsigned int ,gfp_t ); +extern const char *richace_unmapped_identifier (const struct richace *, +const struct richacl *); +extern bool richacl_has_unmapped_identifiers (struct richacl *);/* richacl_inode.c */ extern int richacl_permission (struct inode *,const struct richacl *,int );
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v10 38/46] richacl: Add support for unmapped identifiers
Quoted 18 lines · Andreas Gruenbacher
From: Andreas Gruenbacher <[email protected]>
Some remote file systems like nfs may return user or group identifiers that cannot be mapped to local uids / gids. Allow to represent such unmapped identifiers in richacls. (We still cannot represent unmapped owners and owning groups, however.)
In the in-memory representation, the richacl is followed by a list of NUL-terminated strings, with no padding. Entries with an unmapped identifier have the
RICHACE_UNMAPPED_WHOflag set, andace->e_id.offsspecifies the offset into this list. Multiple entries can refer to the same offset.The xattr representation is similar, but
ace->e_idis ignored, and the list of unmapped identifier strings contains a string for each acl entry whoseRICHACE_UNMAPPED_WHOflag is set.Signed-off-by Andreas Gruenbacher <[email protected]>
....
Quoted 6 lines
fs/richacl_base.c +6
-0+/** +* richacl_has_unmapped_identifiers +* +* Check if an acl has unmapped identifiers. +*/ +bool richacl_has_unmapped_identifiers (struct richacl *acl)
fs/richacl_base.c richace_copy(struct richace *to, const struct richace *from) · line 150
Quoted 10 lines
fs/richacl_base.c +10
-0+{ +struct richace *ace; + +richacl_for_each_entry (ace, acl) { +if (ace->e_flags &RICHACE_UNMAPPED_WHO ) +return true; + } +return false; +} +EXPORT_SYMBOL_GPL (richacl_has_unmapped_identifiers);
This was used by the XFS support patch earlier in the series. Bisect problem here...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v10 38/46] richacl: Add support for unmapped identifiers
2015-10-12 2:22 GMT+02:00 Dave Chinner <[email protected]>:
Quoted 2 lines
This was used by the XFS support patch earlier in the series. Bisect problem here...
Yes, I'll fix that up as well.
Thanks,
Andreas
PATCH v10 39/46 ext4: Don't allow unmapped identifiers in richacls
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Don't allow acls which contain unmapped identifiers: they are meaningful for remote file systems only.
--- fs/ext4/richacl.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ext4/richacl.c +4 -0
@@ -62,6 +62,10 @@ __ext4_set_richacl(handle_t *handle, struct inode *inode, struct richacl *acl)int retval;if (acl) { +/* Don't allow acls with unmapped identifiers. */ +if (richacl_has_unmapped_identifiers (acl)) +return -EINVAL ; +if (richacl_equiv_mode (acl, &mode) ==0 ) { inode->i_ctime =ext4_current_time (inode); inode->i_mode = mode;
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 40/46 sunrpc: Allow to demand-allocate pages to encode into
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
When encoding large, variable-length objects such as acls into xdr_bufs, it is easier to allocate buffer pages on demand rather than precomputing the required buffer size.
--- net/sunrpc/xdr.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/sunrpc/xdr.c +9 -0
@@ -537,6 +537,15 @@ 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_NOFS ); + +if (!page) +return NULL ; + *xdr->page_ptr = page; + } + p =page_address (*xdr->page_ptr);/* * Note this is where the next encode will start after we've
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 41/46 sunrpc: Add xdr_init_encode_pages
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Initialize xdr_stream and xdr_buf from a pages array, for encoding into the pages.
--- include/linux/sunrpc/xdr.h | 2 ++ net/sunrpc/xdr.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/linux/sunrpc/xdr.h +2 -0
@@ -214,6 +214,8 @@ typedef void (*kxdreproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);typedef int (*kxdrdproc_t )(void *rqstp,struct xdr_stream *xdr,void *obj);extern void xdr_init_encode (struct xdr_stream *xdr,struct xdr_buf *buf,__be32 *p); +extern void xdr_init_encode_pages (struct xdr_stream *xdr,struct xdr_buf *buf, +struct page **pages,unsigned int len);extern __be32 *xdr_reserve_space (struct xdr_stream *xdr,size_t nbytes);extern void xdr_commit_encode (struct xdr_stream *xdr);extern void xdr_truncate_encode (struct xdr_stream *xdr,size_t len);
net/sunrpc/xdr.c +25 -0
@@ -483,6 +483,31 @@ void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p)EXPORT_SYMBOL_GPL (xdr_init_encode);/** +* xdr_init_encode_pages - Initialize struct xdr_stream for encoding into pages +* @xdr: pointer to xdr_stream struct +* @buf: pointer to XDR buffer in which to encode data +* @pages: pages array in which to encode +* @len: maximum length of @buf +* +* Initialize @xdr and @buf for encoding into the @pages array. If a +* page in @pages is NULL, it will be allocated on demand. +*/ +void xdr_init_encode_pages (struct xdr_stream *xdr,struct xdr_buf *buf, +struct page **pages,unsigned int len) +{ +memset (buf,0 ,sizeof (*buf)); + buf->pages = pages; + buf->page_len = len; + buf->buflen = len; + +memset (xdr,0 ,sizeof (*xdr)); + xdr->buf = buf; + xdr->iov = buf->head; + xdr->page_ptr = pages -1 ; +} +EXPORT_SYMBOL_GPL (xdr_init_encode_pages); + +/** * xdr_commit_encode - Ensure all data is written to buffer * @xdr: pointer to xdr_stream *
Signature · 1 line
2.5.0
PATCH v10 42/46 nfs: Fix GETATTR bitmap verification
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
When decoding GETATTR replies, the client checks the attribute bitmap for which attributes the server has sent. It misses bits at the word boundaries, though; fix that.
--- fs/nfs/nfs4xdr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
fs/nfs/nfs4xdr.c +23 -0
@@ -4375,6 +4375,11 @@ static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) goto xdr_error;if ((status =decode_attr_files_total (xdr, bitmap, &fsstat->tfiles)) !=0 ) goto xdr_error; + + status = -EIO ; +if (unlikely (bitmap[0 ])) + goto xdr_error; +if ((status =decode_attr_space_avail (xdr, bitmap, &fsstat->abytes)) !=0 ) goto xdr_error;if ((status =decode_attr_space_free (xdr, bitmap, &fsstat->fbytes)) !=0 )
@@ -4574,6 +4579,10 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, goto xdr_error; fattr->valid |= status; + status = -EIO ; +if (unlikely (bitmap[0 ])) + goto xdr_error; + status =decode_attr_mode (xdr, bitmap, &fmode);if (status <0 ) goto xdr_error;
@@ -4627,6 +4636,10 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, goto xdr_error; fattr->valid |= status; + status = -EIO ; +if (unlikely (bitmap[1 ])) + goto xdr_error; + status =decode_attr_mdsthreshold (xdr, bitmap, fattr->mdsthreshold);if (status <0 ) goto xdr_error;
@@ -4789,12 +4802,22 @@ static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)if ((status =decode_attr_maxwrite (xdr, bitmap, &fsinfo->wtmax)) !=0 ) goto xdr_error; fsinfo->wtpref = fsinfo->wtmax; + + status = -EIO ; +if (unlikely (bitmap[0 ])) + goto xdr_error; + status =decode_attr_time_delta (xdr, bitmap, &fsinfo->time_delta);if (status !=0 ) goto xdr_error; status =decode_attr_pnfstype (xdr, bitmap, &fsinfo->layouttype);if (status !=0 ) goto xdr_error; + + status = -EIO ; +if (unlikely (bitmap[1 ])) + goto xdr_error; + status =decode_attr_layout_blksize (xdr, bitmap, &fsinfo->blksize);if (status) goto xdr_error;
Signature · 1 line
2.5.0
PATCH v10 43/46 nfs: Remove unused xdr page offsets in getacl/setacl arguments
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
The 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
@@ -4530,7 +4530,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 ;
@@ -4674,7 +4674,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);
@@ -4766,7 +4765,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
@@ -1659,7 +1659,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
@@ -2491,7 +2491,7 @@ static void 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); }
include/linux/nfs_xdr.h +0 -2
@@ -685,7 +685,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; };
@@ -697,7 +696,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 · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 44/46 nfs: Add richacl support
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
Add support for the "system.richacl" xattr in nfs. The existing "system.nfs4_acl" xattr on nfs doesn't map user and group names to uids and gids; the "system.richacl" xattr does, and only keeps the on-the-wire names when there is no mapping. This allows to copy permissions across different file systems.
--- fs/nfs/inode.c | 3 - fs/nfs/nfs4proc.c | 698 +++++++++++++++++++++++++++++++++------------- fs/nfs/nfs4xdr.c | 179 ++++++++++-- fs/nfs/super.c | 4 +- include/linux/nfs_fs.h | 1 - include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 9 +- 7 files changed, 673 insertions(+), 223 deletions(-)
fs/nfs/inode.c +0 -3
@@ -1852,9 +1852,6 @@ struct inode *nfs_alloc_inode(struct super_block *sb)return NULL ; nfsi->flags =0UL ; nfsi->cache_validity =0UL ; -#if IS_ENABLED (CONFIG_NFS_V4 ) - nfsi->nfs4_acl =NULL ; -#endif /* CONFIG_NFS_V4 */ return &nfsi->vfs_inode; }EXPORT_SYMBOL_GPL (nfs_alloc_inode);
fs/nfs/nfs4proc.c +511 -187
846 lines not on this page · raw message
fs/nfs/nfs4xdr.c +153 -26
230 lines not on this page · raw message
fs/nfs/super.c +2 -2
@@ -2319,7 +2319,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 ; }
@@ -2346,7 +2346,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 +0 -1
@@ -176,7 +176,6 @@ struct nfs_inode {wait_queue_head_t waitqueue;#if IS_ENABLED (CONFIG_NFS_V4 ) -struct nfs4_cached_acl *nfs4_acl;/* NFSv4 state */ struct list_head open_states;struct nfs_delegation __rcu *delegation;
include/linux/nfs_fs_sb.h +2 -0
@@ -243,5 +243,7 @@ struct nfs_server {#define NFS_CAP_ALLOCATE (1U << 20)#define NFS_CAP_DEALLOCATE (1U << 21)#define NFS_CAP_LAYOUTSTATS (1U << 22) +#define NFS_CAP_ALLOW_ACLS (1U << 23) +#define NFS_CAP_DENY_ACLS (1U << 24)#endif
include/linux/nfs_xdr.h +5 -4
@@ -683,9 +683,10 @@ struct nfs_setattrargs {struct nfs_setaclargs {struct nfs4_sequence_args seq_args; +const struct nfs_server * server;struct nfs_fh * fh; -size_t acl_len;struct page ** acl_pages; +size_t acl_len; };struct nfs_setaclres {
@@ -703,9 +704,9 @@ struct nfs_getaclargs {#define NFS4_ACL_TRUNC 0x0001/* ACL was truncated */ struct nfs_getaclres {struct nfs4_sequence_res seq_res; -size_t acl_len; -size_t acl_data_offset; -int acl_flags; +const struct nfs_server * server; +struct richacl * acl; +umode_t mode;struct page * acl_scratch; };
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v10 44/46] nfs: Add richacl support
Hi Andreas,
Quoted 807 lines · Andreas Gruenbacher
From: Andreas Gruenbacher <[email protected]>
Add support for the "system.richacl" xattr in nfs. The existing "system.nfs4_acl" xattr on nfs doesn't map user and group names to uids and gids; the "system.richacl" xattr does, and only keeps the on-the-wire names when there is no mapping. This allows to copy permissions across different file systems.
Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/nfs/inode.c | 3 - fs/nfs/nfs4proc.c | 698 +++++++++++++++++++++++++++++++++------------- fs/nfs/nfs4xdr.c | 179 ++++++++++-- fs/nfs/super.c | 4 +- include/linux/nfs_fs.h | 1 - include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 9 +- 7 files changed, 673 insertions(+), 223 deletions(-)fs/nfs/inode.c +0
-3@@ -1852,9 +1852,6 @@ struct inode *nfs_alloc_inode(struct super_block *sb)return NULL ; nfsi->flags =0UL ; nfsi->cache_validity =0UL ; -#if IS_ENABLED (CONFIG_NFS_V4 ) - nfsi->nfs4_acl =NULL ; -#endif /* CONFIG_NFS_V4 */ return &nfsi->vfs_inode; }EXPORT_SYMBOL_GPL (nfs_alloc_inode);fs/nfs/nfs4proc.c +467
-182@@ -55,6 +55,9 @@#include <linux/xattr.h> #include <linux/utsname.h> #include <linux/freezer.h> +#include <linux/richacl.h> +#include <linux/richacl_xattr.h> +#include <linux/nfs4acl.h> #include "nfs4_fs.h" #include "delegation.h" @@ -2982,15 +2985,18 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f res.attr_bitmask[2 ] &=FATTR4_WORD2_NFS42_MASK ; }memcpy (server->attr_bitmask, res.attr_bitmask,sizeof (server->attr_bitmask)); - server->caps &= ~(NFS_CAP_ACLS |NFS_CAP_HARDLINKS | -NFS_CAP_SYMLINKS |NFS_CAP_FILEID | + server->caps &= ~(NFS_CAP_ALLOW_ACLS |NFS_CAP_DENY_ACLS | +NFS_CAP_HARDLINKS |NFS_CAP_SYMLINKS |NFS_CAP_FILEID |NFS_CAP_MODE |NFS_CAP_NLINK |NFS_CAP_OWNER |NFS_CAP_OWNER_GROUP |NFS_CAP_ATIME |NFS_CAP_CTIME |NFS_CAP_MTIME |NFS_CAP_SECURITY_LABEL ); -if (res.attr_bitmask[0 ] &FATTR4_WORD0_ACL && - res.acl_bitmask &ACL4_SUPPORT_ALLOW_ACL ) - server->caps |=NFS_CAP_ACLS ; +if (res.attr_bitmask[0 ] &FATTR4_WORD0_ACL ) { +if (res.acl_bitmask &ACL4_SUPPORT_ALLOW_ACL ) + server->caps |=NFS_CAP_ALLOW_ACLS ; +if (res.acl_bitmask &ACL4_SUPPORT_DENY_ACL ) + server->caps |=NFS_CAP_DENY_ACLS ; + }if (res.has_links !=0 ) server->caps |=NFS_CAP_HARDLINKS ;if (res.has_symlinks !=0 )@@ -4518,45 +4524,11 @@ static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)return 0 ; } -static inline int nfs4_server_supports_acls (struct nfs_server *server) -{ -return server->caps &NFS_CAP_ACLS ; -} - -/* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that -* it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on -* the stack. +/* A arbitrary limit; we allocate at most DIV_ROUND_UP(NFS4ACL_SIZE_MAX, +* PAGE_SIZE) pages and put an array of DIV_ROUND_UP(NFS4ACL_SIZE_MAX, +* PAGE_SIZE) pages on the stack when encoding or decoding acls. */ -#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) -{ -struct page *newpage, **spages; -int rc =0 ; -size_t len; - spages = pages; - -do { - len =min_t (size_t,PAGE_SIZE , buflen); - newpage =alloc_page (GFP_KERNEL ); - -if (newpage ==NULL ) - goto unwind; -memcpy (page_address (newpage), buf, len); - buf += len; - buflen -= len; - *pages++ = newpage; - rc++; - }while (buflen !=0 ); - -return rc; - -unwind: -for (; rc >0 ; rc--) -__free_page (spages[rc-1 ]); -return -ENOMEM ; -} +#define NFS4ACL_SIZE_MAX 65536struct nfs4_cached_acl {int cached;@@ -4564,66 +4536,9 @@ struct nfs4_cached_acl {char data[0 ]; }; -static void nfs4_set_cached_acl (struct inode *inode,struct nfs4_cached_acl *acl) -{ -struct nfs_inode *nfsi =NFS_I (inode); - -spin_lock (&inode->i_lock); -kfree (nfsi->nfs4_acl); - nfsi->nfs4_acl = acl; -spin_unlock (&inode->i_lock); -} -static void nfs4_zap_acl_attr (struct inode *inode) { -nfs4_set_cached_acl (inode,NULL ); -} - -static inline ssize_t nfs4_read_cached_acl (struct inode *inode,char *buf,size_t buflen) -{ -struct nfs_inode *nfsi =NFS_I (inode); -struct nfs4_cached_acl *acl; -int ret = -ENOENT ; - -spin_lock (&inode->i_lock); - acl = nfsi->nfs4_acl; -if (acl ==NULL ) - goto out; -if (buf ==NULL )/* user is just asking for length */ - goto out_len; -if (acl->cached ==0 ) - goto out; - ret = -ERANGE ;/* see getxattr(2) man page */ -if (acl->len > buflen) - goto out; -memcpy (buf, acl->data, acl->len); -out_len: - ret = acl->len; -out: -spin_unlock (&inode->i_lock); -return ret; -} - -static void nfs4_write_cached_acl (struct inode *inode,struct page **pages,size_t pgbase,size_t acl_len) -{ -struct nfs4_cached_acl *acl; -size_t buflen =sizeof (*acl) + acl_len; - -if (buflen <=PAGE_SIZE ) { - acl =kmalloc (buflen,GFP_KERNEL ); -if (acl ==NULL ) - goto out; - acl->cached =1 ; -_copy_from_pages (acl->data, pages, pgbase, acl_len); - }else { - acl =kmalloc (sizeof (*acl),GFP_KERNEL ); -if (acl ==NULL ) - goto out; - acl->cached =0 ; - } - acl->len = acl_len; -out: -nfs4_set_cached_acl (inode, acl); +forget_cached_richacl (inode); }/* @@ -4636,121 +4551,269 @@ out:* length. The next getxattr call will then produce another round trip to * the server, this time with the input buf of the required size. */ -static ssize_t __nfs4_get_acl_uncached (struct inode *inode,void *buf,size_t buflen) +static struct richacl *__nfs4_get_acl_uncached (struct inode *inode) { -struct page *pages[NFS4ACL_MAXPAGES ] = {NULL , }; +struct nfs_server *server =NFS_SERVER (inode); +struct page *pages[DIV_ROUND_UP (NFS4ACL_SIZE_MAX ,PAGE_SIZE )] = {};struct nfs_getaclargs args = { .fh =NFS_FH (inode), .acl_pages = pages, - .acl_len = buflen, + .acl_len =ARRAY_SIZE (pages) *PAGE_SIZE , };struct nfs_getaclres res = { - .acl_len = buflen, + .server = server, };struct rpc_message msg = { .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL ], .rpc_argp = &args, .rpc_resp = &res, }; -unsigned int npages =DIV_ROUND_UP (buflen,PAGE_SIZE ); -int ret = -ENOMEM , i; +int err, i; -/* As long as we're doing a round trip to the server anyway, -* let's be prepared for a page of acl data. */ -if (npages ==0 ) - npages =1 ; -if (npages >ARRAY_SIZE (pages)) -return -ERANGE ; - -for (i =0 ; i < npages; i++) { - pages[i] =alloc_page (GFP_KERNEL ); -if (!pages[i]) +if (ARRAY_SIZE (pages) >1 ) { +/* for decoding across pages */ + res.acl_scratch =alloc_page (GFP_KERNEL ); + err = -ENOMEM ; +if (!res.acl_scratch) goto out_free; } -/* for decoding across pages */ - res.acl_scratch =alloc_page (GFP_KERNEL ); -if (!res.acl_scratch) - goto out_free; - - args.acl_len = npages *PAGE_SIZE ; - -dprintk ("%s buf %p buflen %zu npages %d args.acl_len %zu\n" , - __func__, buf, buflen, npages, args.acl_len); - ret =nfs4_call_sync (NFS_SERVER (inode)->client,NFS_SERVER (inode), +dprintk ("%s args.acl_len %zu\n" , + __func__, args.acl_len); + err =nfs4_call_sync (NFS_SERVER (inode)->client,NFS_SERVER (inode), &msg, &args.seq_args, &res.seq_res,0 ); -if (ret) +if (err) goto out_free; -/* Handle the case where the passed-in buffer is too short */ -if (res.acl_flags &NFS4_ACL_TRUNC ) { -/* Did the user only issue a request for the acl length? */ -if (buf ==NULL ) - goto out_ok; - ret = -ERANGE ; - goto out_free; - } -nfs4_write_cached_acl (inode, pages, res.acl_data_offset, res.acl_len); -if (buf) { -if (res.acl_len > buflen) { - ret = -ERANGE ; - goto out_free; - } -_copy_from_pages (buf, pages, res.acl_data_offset, res.acl_len); - } -out_ok: - ret = res.acl_len; +richacl_compute_max_masks (res.acl); +/* FIXME: Set inode->i_mode from res->mode? */ +set_cached_richacl (inode, res.acl); + err =0 ; + out_free: -for (i =0 ; i < npages; i++) -if (pages[i]) -__free_page (pages[i]); +if (err) { +richacl_put (res.acl); + res.acl =ERR_PTR (err); + } +for (i =0 ; i <ARRAY_SIZE (pages) && pages[i]; i++) +__free_page (pages[i]);if (res.acl_scratch)__free_page (res.acl_scratch); -return ret; +return res.acl; } -static ssize_t nfs4_get_acl_uncached (struct inode *inode,void *buf,size_t buflen) +static struct richacl *nfs4_get_acl_uncached (struct inode *inode) {struct nfs4_exception exception = { }; -ssize_t ret; +struct richacl *acl;do { - ret =__nfs4_get_acl_uncached (inode, buf, buflen); -trace_nfs4_get_acl (inode, ret); -if (ret >=0 ) + acl =__nfs4_get_acl_uncached (inode); +trace_nfs4_get_acl (inode,IS_ERR (acl) ?PTR_ERR (acl) :0 ); +if (!IS_ERR (acl))break ; - ret =nfs4_handle_exception (NFS_SERVER (inode), ret, &exception); + acl =ERR_PTR (nfs4_handle_exception (NFS_SERVER (inode), +PTR_ERR (acl), &exception)); }while (exception.retry); -return ret; +return acl; } -static ssize_t nfs4_proc_get_acl (struct inode *inode,void *buf,size_t buflen) +static struct richacl *nfs4_proc_get_acl (struct inode *inode) {struct nfs_server *server =NFS_SERVER (inode); +struct richacl *acl;int ret; -if (!nfs4_server_supports_acls (server)) -return -EOPNOTSUPP ; +if (!(server->caps & (NFS_CAP_ALLOW_ACLS |NFS_CAP_DENY_ACLS ))) +return ERR_PTR (-EOPNOTSUPP ); ret =nfs_revalidate_inode (server, inode);if (ret <0 ) -return ret; +return ERR_PTR (ret);if (NFS_I (inode)->cache_validity &NFS_INO_INVALID_ACL )nfs_zap_acl_cache (inode); - ret =nfs4_read_cached_acl (inode, buf, buflen); -if (ret != -ENOENT ) -/* -ENOENT is returned if there is no ACL or if there is an ACL -* but no cached acl data, just the acl length */ -return ret; -return nfs4_get_acl_uncached (inode, buf, buflen); + acl =get_cached_richacl (inode); +if (acl !=ACL_NOT_CACHED ) +return acl; +return nfs4_get_acl_uncached (inode); +} + +static int +richacl_supported (struct nfs_server *server,struct richacl *acl) +{ +struct richace *ace; + +if (!(server->caps & (NFS_CAP_ALLOW_ACLS |NFS_CAP_DENY_ACLS ))) +return -EOPNOTSUPP ; + +richacl_for_each_entry (ace, acl) { +if (richace_is_allow (ace)) { +if (!(server->caps &NFS_CAP_ALLOW_ACLS )) +return -EINVAL ; + }else if (richace_is_deny (ace)) { +if (!(server->caps &NFS_CAP_DENY_ACLS )) +return -EINVAL ; + }else +return -EINVAL ; + } +return 0 ; } -static int __nfs4_proc_set_acl (struct inode *inode,const void *buf,size_t buflen) +static int +nfs4_encode_user (struct xdr_stream *xdr,const struct nfs_server *server, +kuid_t uid) +{ +char name[IDMAP_NAMESZ ]; +int len; +__be32 *p; + + len =nfs_map_uid_to_name (server, uid, name,IDMAP_NAMESZ ); +if (len <0 ) { +dprintk ("nfs: couldn't resolve uid %d to string\n" , +from_kuid (&init_user_ns, uid)); +return -ENOENT ; + } + p =xdr_reserve_space (xdr,4 + len); +if (!p) +return -EIO ; + p =xdr_encode_opaque (p, name, len); +return 0 ; +} + +static int +nfs4_encode_group (struct xdr_stream *xdr,const struct nfs_server *server, +kgid_t gid) +{ +char name[IDMAP_NAMESZ ]; +int len; +__be32 *p; + + len =nfs_map_gid_to_group (server, gid, name,IDMAP_NAMESZ ); +if (len <0 ) { +dprintk ("nfs: couldn't resolve gid %d to string\n" , +from_kgid (&init_user_ns, gid)); +return -ENOENT ; + } + p =xdr_reserve_space (xdr,4 + len); +if (!p) +return -EIO ; + p =xdr_encode_opaque (p, name, len); +return 0 ; +} + +static unsigned int +nfs4_ace_mask (int minorversion) +{ +return minorversion ==0 ?NFS40_ACE_MASK_ALL :NFS4_ACE_MASK_ALL ; +} + +static int +nfs4_encode_ace_who (struct xdr_stream *xdr,const struct nfs_server *server, +struct richace *ace,struct richacl *acl) +{ +const char *who; +__be32 *p; + +if (ace->e_flags &RICHACE_SPECIAL_WHO ) { +unsigned int special_id = ace->e_id.special; +const char *who; +unsigned int len; + +if (!nfs4acl_special_id_to_who (special_id, &who, &len)) { +WARN_ON_ONCE (1 ); +return -EIO ; + } + p =xdr_reserve_space (xdr,4 + len); +if (!p) +return -EIO ; +xdr_encode_opaque (p, who, len); +return 0 ; + }else { + who =richace_unmapped_identifier (ace, acl); +if (who) { +unsigned int len =strlen (who); + + p =xdr_reserve_space (xdr,4 + len); +if (!p) +return -EIO ; +xdr_encode_opaque (p, who, len); +return 0 ; + }else if (ace->e_flags &RICHACE_IDENTIFIER_GROUP ) +return nfs4_encode_group (xdr, server, ace->e_id.gid); +else +return nfs4_encode_user (xdr, server, ace->e_id.uid); + } +} + +static int +nfs4_encode_acl (struct page **pages,unsigned int len,struct richacl *acl, +const struct nfs_server *server) +{ +int minorversion = server->nfs_client->cl_minorversion; +unsigned int ace_mask =nfs4_ace_mask (minorversion); +struct xdr_stream xdr; +struct xdr_buf buf; +__be32 *p; +struct richace *ace; + +/* Reject acls not understood by the server */ +if (server->attr_bitmask[1 ] &FATTR4_WORD1_DACL ) { +BUILD_BUG_ON (NFS4_ACE_MASK_ALL !=RICHACE_VALID_MASK ); + }else { +if (acl->a_flags) +return -EINVAL ; +richacl_for_each_entry (ace, acl) { +if (ace->e_flags &RICHACE_INHERITED_ACE ) +return -EINVAL ; + } + } +richacl_for_each_entry (ace, acl) { +if (ace->e_mask & ~ace_mask) +return -EINVAL ; + } + +xdr_init_encode_pages (&xdr, &buf, pages, len); + +if (server->attr_bitmask[1 ] &FATTR4_WORD1_DACL ) { + p =xdr_reserve_space (&xdr,4 ); +if (!p) + goto fail; + *p =cpu_to_be32 (acl ? acl->a_flags :0 ); + } + + p =xdr_reserve_space (&xdr,4 ); +if (!p) + goto fail; +if (!acl) { + *p++ =cpu_to_be32 (0 ); +return buf.len; + } + *p++ =cpu_to_be32 (acl->a_count); + +richacl_for_each_entry (ace, acl) { + p =xdr_reserve_space (&xdr,4 *3 ); +if (!p) + goto fail; + *p++ =cpu_to_be32 (ace->e_type); + *p++ =cpu_to_be32 (ace->e_flags & + ~(RICHACE_SPECIAL_WHO |RICHACE_UNMAPPED_WHO )); + *p++ =cpu_to_be32 (ace->e_mask &NFS4_ACE_MASK_ALL ); +if (nfs4_encode_ace_who (&xdr, server, ace, acl) !=0 ) + goto fail; + } + +return buf.len; + +fail: +return -ENOMEM ; +} + +static int __nfs4_proc_set_acl (struct inode *inode,struct richacl *acl) {struct nfs_server *server =NFS_SERVER (inode); -struct page *pages[NFS4ACL_MAXPAGES ]; +struct page *pages[DIV_ROUND_UP (NFS4ACL_SIZE_MAX ,PAGE_SIZE ) +1 /* scratch */ ] = {};struct nfs_setaclargs arg = { + .server = server, .fh =NFS_FH (inode), .acl_pages = pages, - .acl_len = buflen, };struct nfs_setaclres res;struct rpc_message msg = {@@ -4758,16 +4821,20 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl .rpc_argp = &arg, .rpc_resp = &res, }; -unsigned int npages =DIV_ROUND_UP (buflen,PAGE_SIZE );int ret, i; -if (!nfs4_server_supports_acls (server)) -return -EOPNOTSUPP ; -if (npages >ARRAY_SIZE (pages)) -return -ERANGE ; - i =buf_to_pages_noslab (buf, buflen, arg.acl_pages); -if (i <0 ) -return i; + ret =richacl_supported (server, acl); +if (ret) +return ret; + + ret =nfs4_encode_acl (pages,NFS4ACL_SIZE_MAX , acl, server); +if (ret <0 ) { +for (i =0 ; i <ARRAY_SIZE (pages) && pages[i]; i++) +put_page (pages[i]); +return ret; + } + arg.acl_len = ret; +nfs4_inode_return_delegation (inode); ret =nfs4_call_sync (server->client, server, &msg, &arg.seq_args, &res.seq_res,1 );@@ -4775,8 +4842,8 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl* Free each page after tx, so the only ref left is * held by the network stack */ -for (; i >0 ; i--) -put_page (pages[i-1 ]); +for (i =0 ; i <ARRAY_SIZE (pages) && pages[i]; i++) +put_page (pages[i]);/* * Acl update can result in inode attribute update. @@ -4790,12 +4857,12 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflreturn ret; } -static int nfs4_proc_set_acl (struct inode *inode,const void *buf,size_t buflen) +static int nfs4_proc_set_acl (struct inode *inode,struct richacl *acl) {struct nfs4_exception exception = { };int err; do { - err = __nfs4_proc_set_acl(inode, buf, buflen); + err = __nfs4_proc_set_acl(inode, acl); trace_nfs4_set_acl(inode, err); err = nfs4_handle_exception(NFS_SERVER(inode), err, &exception);@@ -6257,34 +6324,283 @@ nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp)rpc_call_async (server->client, &msg,0 , &nfs4_release_lockowner_ops, data); } +static int nfs4_xattr_set_richacl (struct dentry *dentry,const char *key, +const void *buf,size_t buflen, +int flags,int handler_flags) +{ +struct inode *inode =d_inode (dentry); +struct richacl *acl; +int error; + +if (strcmp (key,"" ) !=0 ) +return -EINVAL ; + +if (buf) { + acl =richacl_from_xattr (&init_user_ns, buf, buflen); +if (IS_ERR (acl)) +return PTR_ERR (acl); + error =richacl_apply_masks (&acl, inode->i_uid); + }else { +/* +* "Remove the acl"; only permissions granted by the mode +* remain. We are using the cached mode here which could be +* outdated; should we do a GETATTR first to narrow down the +* race window? +*/ + acl =richacl_from_mode (inode->i_mode); + error =0 ; + } + +if (!error) + error =nfs4_proc_set_acl (inode, acl); +richacl_put (acl); +return error; +} + +static int nfs4_xattr_get_richacl (struct dentry *dentry,const char *key, +void *buf,size_t buflen,int handler_flags) +{ +struct inode *inode =d_inode (dentry); +struct richacl *acl; +int error; +umode_t mode = inode->i_mode &S_IFMT ; + +if (strcmp (key,"" ) !=0 ) +return -EINVAL ; + + acl =nfs4_proc_get_acl (inode); +if (IS_ERR (acl)) +return PTR_ERR (acl); +if (acl ==NULL ) +return -ENODATA ; + error = -ENODATA ; +if (richacl_equiv_mode (acl, &mode) ==0 && + ((mode ^ inode->i_mode) &S_IRWXUGO ) ==0 ) + goto out; + error =richacl_to_xattr (&init_user_ns, acl, buf, buflen); +out: +richacl_put (acl); +return error; +} + +static size_t nfs4_xattr_list_richacl (struct dentry *dentry,char *list, +size_t list_len,const char *name, +size_t name_len,int handler_flags) +{ +struct nfs_server *server =NFS_SERVER (d_inode (dentry)); +size_t len =sizeof (XATTR_NAME_RICHACL ); + +if (!(server->caps & (NFS_CAP_ALLOW_ACLS |NFS_CAP_DENY_ACLS ))) +return 0 ; + +if (list && len <= list_len) +memcpy (list,XATTR_NAME_RICHACL , len); +return len; +} +#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" +static int richacl_to_nfs4_acl (struct nfs_server *server, +const struct richacl *acl, +void *buf,size_t buflen) +{ +const struct richace *ace; +__be32 *p = buf; +size_t size =0 ; + + size +=sizeof (*p); +if (buflen >= size) + *p++ =cpu_to_be32 (acl->a_count); + +richacl_for_each_entry (ace, acl) { +char who_buf[IDMAP_NAMESZ ]; +const char *who = who_buf; +int who_len; + + size +=3 *sizeof (*p); +if (buflen >= size) { + *p++ =cpu_to_be32 (ace->e_type); + *p++ =cpu_to_be32 (ace->e_flags & + ~(RICHACE_INHERITED_ACE | +RICHACE_UNMAPPED_WHO | +RICHACE_SPECIAL_WHO )); + *p++ =cpu_to_be32 (ace->e_mask); + } + +if (richace_is_unix_user (ace)) { + who_len =nfs_map_uid_to_name (server, ace->e_id.uid, + who_buf,sizeof (who_buf)); +if (who_len <0 ) +return -EIO ; + }else if (richace_is_unix_group (ace)) { + who_len =nfs_map_gid_to_group (server, ace->e_id.gid, + who_buf,sizeof (who_buf)); +if (who_len <0 ) +return -EIO ; + }else if (ace->e_flags &RICHACE_SPECIAL_WHO ) { +if (!nfs4acl_special_id_to_who (ace->e_id.special, + &who, &who_len)) +return -EIO ; + }else { + who =richace_unmapped_identifier (ace, acl); +if (who) + who_len =strlen (who); +else +return -EIO ; + } + + size +=sizeof (*p) +ALIGN (who_len,sizeof (*p)); +if (buflen >= size) { +unsigned int padding = -who_len & (sizeof (*p) -1 ); + + *p++ =cpu_to_be32 (who_len); +memcpy (p, who, who_len); +memset ((char *)p + who_len,0 , padding); + p +=DIV_ROUND_UP (who_len,sizeof (*p)); + } + } +if (buflen && buflen < size) +return -ERANGE ; +return size; +} + +static struct richacl *richacl_from_nfs4_acl (struct nfs_server *server, +const void *buf,size_t buflen) +{ +struct richacl *acl =NULL ; +struct richace *ace; +const __be32 *p = buf; +int count, err; + +if (buflen <sizeof (*p)) +return ERR_PTR (-EINVAL ); + count =be32_to_cpu (*p++); +if (count >RICHACL_XATTR_MAX_COUNT ) +return ERR_PTR (-EINVAL ); + buflen -=sizeof (*p); + acl =richacl_alloc (count,GFP_NOFS ); +if (!acl) +return ERR_PTR (-ENOMEM ); +richacl_for_each_entry (ace, acl) { +u32 who_len, size; +int special_id; +char *who; + + err = -EINVAL ; +if (buflen <4 *sizeof (*p)) + goto out; + ace->e_type =be32_to_cpu (*p++); + ace->e_flags =be32_to_cpu (*p++); +if (ace->e_flags & (RICHACE_SPECIAL_WHO |RICHACE_UNMAPPED_WHO )) + goto out; + ace->e_mask =be32_to_cpu (*p++); + who_len =be32_to_cpu (*p++); + buflen -=4 *sizeof (*p); + size =ALIGN (who_len,4 ); +if (buflen < size || size ==0 ) + goto out; + who = (char *)p; + special_id =nfs4acl_who_to_special_id (who, who_len); +if (special_id >=0 ) { + ace->e_flags |=RICHACE_SPECIAL_WHO ; + ace->e_id.special = special_id; + }else { +bool unmappable; + +if (ace->e_flags &RICHACE_IDENTIFIER_GROUP ) { + err =nfs_map_group_to_gid (server, who, who_len, + &ace->e_id.gid); +if (err) { +dprintk ("%s: nfs_map_group_to_gid " +"failed!\n" , __func__); + goto out; + } +/* FIXME: nfsidmap doesn't distinguish between +group nobody and unmappable groups! */ + unmappable =gid_eq (ace->e_id.gid, +make_kgid (&init_user_ns,99 )); + }else { + err =nfs_map_name_to_uid (server, who, who_len, + &ace->e_id.uid); +if (err) { +dprintk ("%s: nfs_map_name_to_gid " +"failed!\n" , __func__); + goto out; + } +/* FIXME: nfsidmap doesn't distinguish between +user nobody and unmappable users! */ + unmappable =uid_eq (ace->e_id.uid, +make_kuid (&init_user_ns,99 )); + } +if (unmappable) { + err = -ENOMEM ; +if (richacl_add_unmapped_identifier (&acl, &ace, + who, who_len,GFP_NOFS )) + goto out; + } + } + p += size /sizeof (*p); + buflen -= size; + } + err = -EINVAL ; +if (buflen !=0 )
fs/nfs/nfs4proc.c nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) · line 6556
Quoted 10 lines
fs/nfs/nfs4proc.c +10
-0+ goto out; + err =0 ; + +out: +if (err) { +richacl_put (acl); + acl =ERR_PTR (err); + } +return acl; +}
I'm not a fan of the "one giant function" approach. Is there any way to split richacl_from_nfs4_acl() into several smaller functions?
Thanks,
Anna
Quoted 392 lines
fs/nfs/nfs4proc.c +34
-5+static int nfs4_xattr_set_nfs4_acl (struct dentry *dentry,const char *key,const void *buf,size_t buflen,int flags,int type) { -if (strcmp (key,"" ) !=0 ) +struct inode *inode =d_inode (dentry); +struct richacl *acl; +int error; + +if (!buf ||strcmp (key,"" ) !=0 )return -EINVAL ; -return nfs4_proc_set_acl (d_inode (dentry), buf, buflen); + acl =richacl_from_nfs4_acl (NFS_SERVER (inode), (void *)buf, buflen); +if (IS_ERR (acl)) +return PTR_ERR (acl); + error =nfs4_proc_set_acl (inode, acl); +richacl_put (acl); +return error; }static int nfs4_xattr_get_nfs4_acl (struct dentry *dentry,const char *key,void *buf,size_t buflen,int type) { +struct inode *inode =d_inode (dentry); +struct richacl *acl; +int error; +if (strcmp (key,"" ) !=0 )return -EINVAL ; - -return nfs4_proc_get_acl (d_inode (dentry), buf, buflen); + acl =nfs4_proc_get_acl (inode); +if (IS_ERR (acl)) +return PTR_ERR (acl); +if (acl ==NULL ) +return -ENODATA ; + error =richacl_to_nfs4_acl (NFS_SERVER (inode), acl, buf, buflen); +richacl_put (acl); +return error; }static size_t nfs4_xattr_list_nfs4_acl (struct dentry *dentry,char *list,size_t list_len,const char *name,size_t name_len,int type) { +struct nfs_server *server =NFS_SERVER (d_inode (dentry));size_t len =sizeof (XATTR_NAME_NFSV4_ACL ); -if (!nfs4_server_supports_acls (NFS_SERVER (d_inode (dentry)))) +if (!(server->caps & (NFS_CAP_ALLOW_ACLS |NFS_CAP_DENY_ACLS )))return 0 ;if (list && len <= list_len)@@ -8837,6 +9153,13 @@ const struct nfs_rpc_ops nfs_v4_clientops = { .clone_server = nfs_clone_server, }; +static const struct xattr_handler nfs4_xattr_richacl_handler = { + .prefix =XATTR_NAME_RICHACL , + .list = nfs4_xattr_list_richacl, + .get = nfs4_xattr_get_richacl, + .set = nfs4_xattr_set_richacl, +}; +static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { .prefix =XATTR_NAME_NFSV4_ACL , .list = nfs4_xattr_list_nfs4_acl,@@ -8845,6 +9168,7 @@ static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { };const struct xattr_handler *nfs4_xattr_handlers[] = { + &nfs4_xattr_richacl_handler, &nfs4_xattr_nfs4_acl_handler, #ifdef CONFIG_NFS_V4_SECURITY_LABEL &nfs4_xattr_nfs4_label_handler,fs/nfs/nfs4xdr.c +153
-26@@ -52,6 +52,10 @@#include <linux/nfs.h> #include <linux/nfs4.h> #include <linux/nfs_fs.h> +#include <linux/nfs_idmap.h> +#include <linux/richacl.h> +#include <linux/richacl_xattr.h> /* for RICHACL_XATTR_MAX_COUNT */ +#include <linux/nfs4acl.h> #include "nfs4_fs.h" #include "internal.h" @@ -1650,16 +1654,24 @@ encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)static void encode_setacl (struct xdr_stream *xdr,struct nfs_setaclargs *arg,struct compound_hdr *hdr) { -__be32 *p; +int attrlen_offset; +__be32 attrlen, *p;encode_op_hdr (xdr,OP_SETATTR , decode_setacl_maxsz, hdr);encode_nfs4_stateid (xdr, &zero_stateid); + +/* Encode attribute bitmap. */ p =reserve_space (xdr,2 *4 ); *p++ =cpu_to_be32 (1 ); *p =cpu_to_be32 (FATTR4_WORD0_ACL ); - p =reserve_space (xdr,4 ); - *p =cpu_to_be32 (arg->acl_len); + + attrlen_offset = xdr->buf->len; +xdr_reserve_space (xdr,4 );/* to be backfilled later */ +xdr_write_pages (xdr, arg->acl_pages,0 , arg->acl_len); + + attrlen =htonl (xdr->buf->len - attrlen_offset -4 ); +write_bytes_to_xdr_buf (xdr->buf, attrlen_offset, &attrlen,4 ); } static void@@ -2488,7 +2500,7 @@ static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,encode_sequence (xdr, &args->seq_args, &hdr);encode_putfh (xdr, args->fh, &hdr); replen = hdr.replen + op_decode_hdr_maxsz +1 ; -encode_getattr_two (xdr,FATTR4_WORD0_ACL ,0 , &hdr); +encode_getattr_two (xdr,FATTR4_WORD0_ACL ,FATTR4_WORD1_MODE , &hdr);xdr_inline_pages (&req->rq_rcv_buf, replen <<2 , args->acl_pages,0 , args->acl_len);@@ -5260,24 +5272,135 @@ decode_restorefh(struct xdr_stream *xdr)return decode_op_hdr (xdr,OP_RESTOREFH ); } +static int +nfs4_decode_ace_who (struct richace *ace, +const char **unmapped,unsigned int *unmapped_len, +const struct nfs_server *server, +struct xdr_stream *xdr) +{ +char *who; +u32 len; +int special_id; +__be32 *p; +int error; + + p =xdr_inline_decode (xdr,4 ); +if (!p) +return -ENOMEM ;/* acl truncated */ + len =be32_to_cpup (p++); +if (len >=XDR_MAX_NETOBJ ) { +dprintk ("%s: name too long (%u)!\n" , + __func__, len); +return -EIO ; + } + who = (char *)xdr_inline_decode (xdr, len); +if (!who) +return -ENOMEM ;/* acl truncated */ + + special_id =nfs4acl_who_to_special_id (who, len); +if (special_id >=0 ) { + ace->e_flags |=RICHACE_SPECIAL_WHO ; + ace->e_flags &= ~RICHACE_IDENTIFIER_GROUP ; + ace->e_id.special = special_id; +return 0 ; + } +if (ace->e_flags &RICHACE_IDENTIFIER_GROUP ) { + error =nfs_map_group_to_gid (server, who, len, &ace->e_id.gid); +if (error) { +dprintk ("%s: nfs_map_group_to_gid failed!\n" , + __func__); +return error; + } +/* FIXME: nfsidmap doesn't distinguish between group nobody and +unmappable groups! */ +if (gid_eq (ace->e_id.gid,make_kgid (&init_user_ns,99 ))) { + *unmapped = who; + *unmapped_len = len; + } + }else { + error =nfs_map_name_to_uid (server, who, len, &ace->e_id.uid); +if (error) { +dprintk ("%s: nfs_map_name_to_uid failed!\n" , + __func__); +return error; + } +/* FIXME: nfsidmap doesn't distinguish between user nobody and +unmappable users! */ +if (uid_eq (ace->e_id.uid,make_kuid (&init_user_ns,99 ))) { + *unmapped = who; + *unmapped_len = len; + } + } +return 0 ; +} + +static struct richacl * +decode_acl_entries (struct xdr_stream *xdr,const struct nfs_server *server) +{ +struct richacl *acl; +struct richace *ace; +uint32_t count; +__be32 *p; +int status; + + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) +return ERR_PTR (-ENOMEM );/* acl truncated */ + count =be32_to_cpup (p); +if (count >RICHACL_XATTR_MAX_COUNT ) +return ERR_PTR (-EIO ); + acl =richacl_alloc (count,GFP_NOFS ); +if (!acl) +return ERR_PTR (-ENOMEM ); +richacl_for_each_entry (ace, acl) { +const char *unmapped =NULL ; +unsigned int unmapped_len; + + p =xdr_inline_decode (xdr,4 *3 ); + status = -ENOMEM ; +if (unlikely (!p)) + goto out;/* acl truncated */ + ace->e_type =be32_to_cpup (p++); + ace->e_flags =be32_to_cpup (p++); + status = -EIO ; +if (ace->e_flags & + (RICHACE_SPECIAL_WHO |RICHACE_UNMAPPED_WHO )) + goto out; + ace->e_mask =be32_to_cpup (p++); + status =nfs4_decode_ace_who (ace, &unmapped, + &unmapped_len, server, + xdr); +if (status) + goto out; +if (unmapped) { + status = -ENOMEM ; +if (richacl_add_unmapped_identifier (&acl, &ace, + unmapped, unmapped_len, +GFP_NOFS )) + goto out; + } + } + status =0 ; + +out: +if (status) { +richacl_put (acl); + acl =ERR_PTR (status); + } +return acl; +} +static int decode_getacl (struct xdr_stream *xdr,struct rpc_rqst *req,struct nfs_getaclres *res) {unsigned int savep;uint32_t attrlen, bitmap[3 ] = {0 }; +struct richacl *acl =NULL ;int status; -unsigned int pg_offset; - res->acl_len =0 ;if ((status =decode_op_hdr (xdr,OP_GETATTR )) !=0 ) goto out; - -xdr_enter_page (xdr, xdr->buf->page_len); - -/* Calculate the offset of the page data */ - pg_offset = xdr->buf->head[0 ].iov_len; -if ((status =decode_attr_bitmap (xdr, bitmap)) !=0 ) goto out;if ((status =decode_attr_length (xdr, &attrlen, &savep)) !=0 )@@ -5286,24 +5409,28 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,if (unlikely (bitmap[0 ] & (FATTR4_WORD0_ACL -1U )))return -EIO ;if (likely (bitmap[0 ] &FATTR4_WORD0_ACL )) { - -/* The bitmap (xdr len + bitmaps) and the attr xdr len words -* are stored with the acl data to handle the problem of -* variable length bitmaps.*/ - res->acl_data_offset =xdr_stream_pos (xdr) - pg_offset; - res->acl_len = attrlen; - -/* Check for receive buffer overflow */ -if (res->acl_len > (xdr->nwords <<2 ) || - res->acl_len + res->acl_data_offset > xdr->buf->page_len) { - res->acl_flags |=NFS4_ACL_TRUNC ; -dprintk ("NFS: acl reply: attrlen %u > page_len %u\n" , - attrlen, xdr->nwords <<2 ); - } + acl =decode_acl_entries (xdr, res->server); + status =PTR_ERR (acl); +if (IS_ERR (acl)) + goto out; + bitmap[0 ] &= ~FATTR4_WORD0_ACL ; }else status = -EOPNOTSUPP ; + status = -EIO ; +if (unlikely (bitmap[0 ])) + goto out; + + status =decode_attr_mode (xdr, bitmap, &res->mode); +if (status <0 ) + goto out; + status =0 ; + out: +if (status ==0 ) + res->acl = acl; +else +richacl_put (acl);return status; }fs/nfs/super.c +2
-2@@ -2319,7 +2319,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 ; }@@ -2346,7 +2346,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 +0
-1@@ -176,7 +176,6 @@ struct nfs_inode {wait_queue_head_t waitqueue;#if IS_ENABLED (CONFIG_NFS_V4 ) -struct nfs4_cached_acl *nfs4_acl;/* NFSv4 state */ struct list_head open_states;struct nfs_delegation __rcu *delegation;include/linux/nfs_fs_sb.h +2
-0@@ -243,5 +243,7 @@ struct nfs_server {#define NFS_CAP_ALLOCATE (1U << 20)#define NFS_CAP_DEALLOCATE (1U << 21)#define NFS_CAP_LAYOUTSTATS (1U << 22) +#define NFS_CAP_ALLOW_ACLS (1U << 23) +#define NFS_CAP_DENY_ACLS (1U << 24)#endif include/linux/nfs_xdr.h +5
-4@@ -683,9 +683,10 @@ struct nfs_setattrargs {struct nfs_setaclargs {struct nfs4_sequence_args seq_args; +const struct nfs_server * server;struct nfs_fh * fh; -size_t acl_len;struct page ** acl_pages; +size_t acl_len; };struct nfs_setaclres {@@ -703,9 +704,9 @@ struct nfs_getaclargs {#define NFS4_ACL_TRUNC 0x0001/* ACL was truncated */ struct nfs_getaclres {struct nfs4_sequence_res seq_res; -size_t acl_len; -size_t acl_data_offset; -int acl_flags; +const struct nfs_server * server; +struct richacl * acl; +umode_t mode;struct page * acl_scratch; };
Re: [PATCH v10 44/46] nfs: Add richacl support
Anna,
Quoted 1 line · Anna Schumaker
I'm not a fan of the "one giant function" approach. Is there any way to split
richacl_from_nfs4_acl()into several smaller functions?
sure, parsing the usr/group identifier could be put in a separate function, for example.
That function cannot stay as it is right now anyway --- we really need idmapper to tell us when an identifier string cannot be mapped to a uid or gid so that we can preserve that identifier.
Thanks,
Andreas
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 45/46 nfs: Add support for the v4.1 dacl attribute
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
The dacl attribute includes Automatic Inheritance flags not supported by the acl attribute. it is only supported in NFS version 4.1 and higher. On systems where NFS version 4.0 is still the default, an additional mount option is needed:
mount -t nfs4 -o vers=4.1 [...]
--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 55 ++++++++++++++++++++++++++++++++++++++++++------- include/linux/nfs_xdr.h | 2 +- 3 files changed, 50 insertions(+), 9 deletions(-)
fs/nfs/nfs4proc.c +1 -1
@@ -4556,7 +4556,7 @@ static struct richacl *__nfs4_get_acl_uncached(struct inode *inode)struct nfs_server *server =NFS_SERVER (inode);struct page *pages[DIV_ROUND_UP (NFS4ACL_SIZE_MAX ,PAGE_SIZE )] = {};struct nfs_getaclargs args = { - .fh =NFS_FH (inode), + .inode = inode, .acl_pages = pages, .acl_len =ARRAY_SIZE (pages) *PAGE_SIZE , };
fs/nfs/nfs4xdr.c +48 -7
86 lines not on this page · raw message
include/linux/nfs_xdr.h +1 -1
@@ -695,7 +695,7 @@ struct nfs_setaclres {struct nfs_getaclargs {struct nfs4_sequence_args seq_args; -struct nfs_fh * fh; +struct inode * inode;size_t acl_len;struct page ** acl_pages; };
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v10 46/46 richacl: uapi header split
In reply to Andreas GruenbacherFrom: Andreas Gruenbacher <[email protected]>
--- include/linux/richacl.h | 119 +++++-------------------------------- include/linux/richacl_xattr.h | 17 +----- include/uapi/linux/Kbuild | 2 + include/uapi/linux/richacl.h | 111 ++++++++++++++++++++++++++++++++++ include/uapi/linux/richacl_xattr.h | 43 ++++++++++++++ 5 files changed, 173 insertions(+), 119 deletions(-) create mode 100644 include/uapi/linux/richacl.h create mode 100644 include/uapi/linux/richacl_xattr.h
include/linux/richacl.h +16 -103
@@ -17,9 +17,7 @@ #ifndef __RICHACL_H #define __RICHACL_H -#define RICHACE_OWNER_SPECIAL_ID 0 -#define RICHACE_GROUP_SPECIAL_ID 1 -#define RICHACE_EVERYONE_SPECIAL_ID 2 +#include <uapi/linux/richacl.h> struct richace { unsigned short e_type;
@@ -44,43 +42,12 @@ struct richacl {struct richace a_entries[0 ]; }; -#define richacl_for_each_entry (_ace, _acl) \ - for (_ace = (_acl)->a_entries; \ - _ace != (_acl)->a_entries + (_acl)->a_count; \ - _ace++) - -#define richacl_for_each_entry_reverse (_ace, _acl) \ - for (_ace = (_acl)->a_entries + (_acl)->a_count - 1; \ - _ace != (_acl)->a_entries - 1; \ - _ace--) - -/* a_flags values */ -#define RICHACL_AUTO_INHERIT 0x01 -#define RICHACL_PROTECTED 0x02 -#define RICHACL_DEFAULTED 0x04 -#define RICHACL_WRITE_THROUGH 0x40 -#define RICHACL_MASKED 0x80 -#define RICHACL_VALID_FLAGS ( \ - RICHACL_AUTO_INHERIT | \ - RICHACL_PROTECTED | \ - RICHACL_DEFAULTED | \ - RICHACL_WRITE_THROUGH | \ - RICHACL_MASKED) - -/* e_type values */ -#define RICHACE_ACCESS_ALLOWED_ACE_TYPE 0x0000 -#define RICHACE_ACCESS_DENIED_ACE_TYPE 0x0001 - -/* e_flags bitflags */ -#define RICHACE_FILE_INHERIT_ACE 0x0001 -#define RICHACE_DIRECTORY_INHERIT_ACE 0x0002 -#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_UNMAPPED_WHO 0x2000 -#define RICHACE_SPECIAL_WHO 0x4000 + RICHACL_AUTO_INHERIT | \ + RICHACL_PROTECTED | \ + RICHACL_DEFAULTED | \ + RICHACL_WRITE_THROUGH | \ + RICHACL_MASKED)#define RICHACE_VALID_FLAGS ( \ RICHACE_FILE_INHERIT_ACE | \
@@ -99,27 +66,6 @@ struct richacl { RICHACE_INHERIT_ONLY_ACE | \ RICHACE_INHERITED_ACE ) -/* e_mask bitflags */ -#define RICHACE_READ_DATA 0x00000001 -#define RICHACE_LIST_DIRECTORY 0x00000001 -#define RICHACE_WRITE_DATA 0x00000002 -#define RICHACE_ADD_FILE 0x00000002 -#define RICHACE_APPEND_DATA 0x00000004 -#define RICHACE_ADD_SUBDIRECTORY 0x00000004 -#define RICHACE_READ_NAMED_ATTRS 0x00000008 -#define RICHACE_WRITE_NAMED_ATTRS 0x00000010 -#define RICHACE_EXECUTE 0x00000020 -#define RICHACE_DELETE_CHILD 0x00000040 -#define RICHACE_READ_ATTRIBUTES 0x00000080 -#define RICHACE_WRITE_ATTRIBUTES 0x00000100 -#define RICHACE_WRITE_RETENTION 0x00000200 -#define RICHACE_WRITE_RETENTION_HOLD 0x00000400 -#define RICHACE_DELETE 0x00010000 -#define RICHACE_READ_ACL 0x00020000 -#define RICHACE_WRITE_ACL 0x00040000 -#define RICHACE_WRITE_OWNER 0x00080000 -#define RICHACE_SYNCHRONIZE 0x00100000 -/* Valid RICHACE_* flags for directories and non-directories */ #define RICHACE_VALID_MASK ( \ RICHACE_READ_DATA | RICHACE_LIST_DIRECTORY | \
@@ -139,49 +85,16 @@ struct richacl { RICHACE_WRITE_OWNER | \ RICHACE_SYNCHRONIZE) -/* -* The POSIX permissions are supersets of the following NFSv4 permissions: -* -* - MAY_READ maps to READ_DATA or LIST_DIRECTORY, depending on the type -* of the file system object. -* -* - MAY_WRITE maps to WRITE_DATA or RICHACE_APPEND_DATA for files, and to -* ADD_FILE, RICHACE_ADD_SUBDIRECTORY, or RICHACE_DELETE_CHILD for directories. -* -* - MAY_EXECUTE maps to RICHACE_EXECUTE. -* -* (Some of these NFSv4 permissions have the same bit values.) -*/ -#define RICHACE_POSIX_MODE_READ ( \ - RICHACE_READ_DATA | \ - RICHACE_LIST_DIRECTORY) -#define RICHACE_POSIX_MODE_WRITE ( \ - RICHACE_WRITE_DATA | \ - RICHACE_ADD_FILE | \ - RICHACE_APPEND_DATA | \ - RICHACE_ADD_SUBDIRECTORY | \ - RICHACE_DELETE_CHILD) -#define RICHACE_POSIX_MODE_EXEC RICHACE_EXECUTE -#define RICHACE_POSIX_MODE_ALL ( \ - RICHACE_POSIX_MODE_READ | \ - RICHACE_POSIX_MODE_WRITE | \ - RICHACE_POSIX_MODE_EXEC) -/* -* These permissions are always allowed -* no matter what the acl says. -*/ -#define RICHACE_POSIX_ALWAYS_ALLOWED ( \ - RICHACE_SYNCHRONIZE | \ - RICHACE_READ_ATTRIBUTES | \ - RICHACE_READ_ACL) -/* -* The owner is implicitly granted -* these permissions under POSIX. -*/ -#define RICHACE_POSIX_OWNER_ALLOWED ( \ - RICHACE_WRITE_ATTRIBUTES | \ - RICHACE_WRITE_OWNER | \ - RICHACE_WRITE_ACL) +#define richacl_for_each_entry (_ace, _acl) \ + for (_ace = (_acl)->a_entries; \ + _ace != (_acl)->a_entries + (_acl)->a_count; \ + _ace++) + +#define richacl_for_each_entry_reverse (_ace, _acl) \ + for (_ace = (_acl)->a_entries + (_acl)->a_count - 1; \ + _ace != (_acl)->a_entries - 1; \ + _ace--) +/** * richacl_get - grab another reference to a richacl handle */
include/linux/richacl_xattr.h +1 -16
@@ -17,24 +17,9 @@#ifndef __RICHACL_XATTR_H#define __RICHACL_XATTR_H +#include <uapi/linux/richacl_xattr.h> #include <linux/richacl.h> -struct richace_xattr { -__le16 e_type; -__le16 e_flags; -__le32 e_mask; -__le32 e_id; -}; - -struct richacl_xattr { -unsigned char a_version; -unsigned char a_flags; -__le16 a_count; -__le32 a_owner_mask; -__le32 a_group_mask; -__le32 a_other_mask; -}; -#define RICHACL_XATTR_VERSION 0#define RICHACL_XATTR_MAX_COUNT \ ((XATTR_SIZE_MAX - sizeof(struct richacl_xattr)) / \
include/uapi/linux/Kbuild +2 -0
@@ -348,6 +348,8 @@ header-y += reboot.h header-y += reiserfs_fs.h header-y += reiserfs_xattr.h header-y += resource.h +header-y += richacl.h +header-y += richacl_xattr.h header-y += rfkill.h header-y += romfs_fs.h header-y += rose.h
include/uapi/linux/richacl.h new file +111 -0
111 lines not on this page · raw message
include/uapi/linux/richacl_xattr.h new file +43 -0
43 lines not on this page · raw message
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs