acl: add vfs posix acl api
Subsystems (33)
Christian Brauner
maintainerv2 cover acl: add vfs posix acl api
From: "Christian Brauner (Microsoft)" <[email protected]>
Hey everyone,
/* v2 */
This fixes various things pointed out during review. The individual commits contain more details were appropriate.
As we discussed and seen multiple times the current state of how posix acls are handled isn't nice and comes with a lot of problems. For a long and detailed explanation for just some of the issues [1] provides a good summary.
The current way of handling posix acls via the generic xattr api is error prone, hard to maintain, and type unsafe for the vfs until we call into the filesystem's dedicated get and set inode operations.
It is already the case that posix acls are special-cased to death all the way through the vfs. There are an uncounted number of hacks that operate on the uapi posix acl struct instead of the dedicated vfs struct posix_acl. And the vfs must be involved in order to interpret and fixup posix acls before storing them to the backing store, caching them, reporting them to userspace, or for permission checking.
Currently a range of hacks and duct tape exist to make this work. As with most things this is really no ones fault it's just something that happened over time. But the code is hard to understand and difficult to maintain and one is constantly at risk of introducing bugs and regressions when having to touch it.
Instead of continuing to hack posix acls through the xattr handlers this series builds a dedicated posix acl api solely around the get and set inode operations. Going forward, the vfs_get_acl(), vfs_remove_acl(), and vfs_set_acl() helpers must be used in order to interact with posix acls. They operate directly on the vfs internal struct posix_acl instead of abusing the uapi posix acl struct as we currently do. In the end this removes all of the hackiness, makes the codepaths easier to maintain, and gets us type safety.
This series passes the LTP and xfstests suites without any regressions. For xfstests the following combinations were tested:
* xfs
* ext4
* btrfs
* overlayfs
* overlayfs on top of idmapped mounts
For people wanting to run their own xfstests I'd recommend to shorten their test runs via:
./check -g acl,attr,cap,idmapped,io_uring,perms,subvol,unlink
I would appreciate if the 9p and cifs folks could run any posix acl related tests as I have no setup to really do this without causing me a lot of pain.
Very likely there's a lot more simplifications for posix acls that we can make in the future if the basic api has made it.
A few implementation details:
* The series makes sure to retain exactly the same security and integrity module permission checks. See [2] for annotated callchains. Especially for the integrity modules this api is a win because right now they convert the uapi posix acl struct passed to them via a void pointer into the vfs struct posix_acl format to perform permission checking on the mode.
There's a new dedicated security hook for setting posix acls which passes the vfs struct posix_acl not a void pointer. Basing checking on the posix acl stored in the uapi format is really unreliable. The vfs currently hacks around directly in the uapi struct storing values that frankly the security and integrity modules can't correctly interpret as evidenced by bugs we reported and fixed in this area. It's not necessarily even their fault it's just that the format we provide to them is sub optimal.
* Some filesystems like 9p and cifs need access to the dentry in order to get and set posix acls which is why they either only partially or not even at all implement get and set inode operations. For example, cifs allows setxattr() and getxattr() operations but doesn't allow permission checking based on posix acls because it can't implement a get acl inode operation.
Thus, this patch series updates the set acl inode operation to take a dentry instead of an inode argument. However, for the get acl inode operation we can't do this as the old get acl method is called in e.g., generic_permission() and inode_permission(). These helpers in turn are called in various filesystem's permission inode operation. So passing a dentry argument to the old get acl inode operation would amount to passing a dentry to the permission inode operation which we shouldn't and probably can't do.
So instead of extending the existing inode operation Christoph suggested to add a new one. He also requested to ensure that the get and set acl inode operation taking a dentry are consistently named. So for this version the old get acl operation is renamed to ->get_inode_acl() and a new ->get_acl() inode operation taking a dentry is added. With this we can give both 9p and cifs get and set acl inode operations and in turn remove their complex custom posix xattr handlers.
* I've done a full audit of every codepaths using variant of the current generic xattr api to get and set posix acls and surprisingly it isn't that many places. There's of course always a chance that I might have missed some and I'm sure we'll find them soon enough.
The crucial codepaths to be converted are obviously stacking filesystems such as ecryptfs and overlayfs.
For a list of all callers currently using generic xattr api helpers see [2] including comments whether they support posix acls or not.
* The old vfs generic posix acl infrastructure doesn't obey the create and replace semantics promised on the setxattr(2) manpage. This patch series doesn't address this. It really is something we should revisit later though.
The patch series is roughly organized as follows:
// intended to be a non-functional change
1. Change existing set acl inode operation to take a dentry argument.
// intended to be a non-functional change
2. Rename existing get acl method.
// intended to be a non-functional change
3. Implement get and set acl inode operations for filesystems that couldn't implement one before because of the missing dentry. That's mostly 9p and cifs.
// intended to be a non-functional change
4. Build posix acl api, i.e., add vfs_get_acl(), vfs_remove_acl(), and vfs_set_acl() including security and integrity hooks.
// intended to be a non-functional change
5. Implement get and set acl inode operations for stacking filesystems.
// semantical change
6. Switch posix acl handling in stacking filesystems to new posix acl api now that all filesystems it can stack upon support it.
// semantical change
7. Switch vfs to new posix acl api
8. Remove all now unused helpers
The series can be pulled from:
https://gitlab.com/brauner/linux/-/commits/fs.acl.rework
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping.git/log/?h=fs.acl.rework
The series contains a few preliminary patches which are scheduled for the next merge window. It was just easier to base the series on top of them. But if you pull this branch you'll get them included.
I've been working on this for a while and before going any further it'd be nice to get some reviews. I think that it should be fine to have get and set acl inode operations that operate on the dentry at least nothing stuck out immediately that would prevent this. But obviously having other people point out issues with that would be helpful.
Thanks to Seth for a lot of good discussion around this and encouragement and input from Christoph.
[1]: https://lore.kernel.org/all/[email protected]
[2]: https://gist.github.com/brauner/12c795b93a05dc3b3056b1982549a633
v1: https://lore.kernel.org/linux-cifs/[email protected]
Thanks!
Christian
Christian Brauner (30):
orangefs: rework posix acl handling when creating new filesystem
objects
fs: pass dentry to set acl method
fs: rename current get acl method
fs: add new get acl method
cifs: implement get acl method
cifs: implement set acl method
9p: implement get acl method
9p: implement set acl method
acl: add vfs_set_acl()
security: add set acl hook
selinux: implement set acl hook
smack: implement set acl hook
evm: implement set acl hook
acl: use set acl hook
evm: add post set acl hook
acl: add vfs_get_acl()
acl: add vfs_remove_acl()
evm: simplify evm_xattr_acl_change()
ksmbd: use vfs_remove_acl()
ecryptfs: implement get acl method
ecryptfs: implement set acl method
ovl: implement get acl method
ovl: implement set acl method
ovl: use posix acl api
xattr: use posix acl api
ecryptfs: use stub posix acl handlers
ovl: use stub posix acl handlers
cifs: use stub posix acl handlers
9p: use stub posix acl handlers
acl: remove a slew of now unused helpers
Documentation/filesystems/locking.rst | 4 +- Documentation/filesystems/porting.rst | 4 +- Documentation/filesystems/vfs.rst | 3 +- fs/9p/acl.c | 295 +++++------ fs/9p/acl.h | 8 +- fs/9p/vfs_inode_dotl.c | 4 + fs/9p/xattr.c | 7 +- fs/9p/xattr.h | 2 - fs/bad_inode.c | 4 +- fs/btrfs/acl.c | 3 +- fs/btrfs/ctree.h | 2 +- fs/btrfs/inode.c | 8 +- fs/ceph/acl.c | 3 +- fs/ceph/dir.c | 2 +- fs/ceph/inode.c | 4 +- fs/ceph/super.h | 2 +- fs/cifs/cifsacl.c | 141 ++++++ fs/cifs/cifsfs.c | 4 + fs/cifs/cifsproto.h | 20 +- fs/cifs/cifssmb.c | 206 +++++--- fs/cifs/xattr.c | 68 +-- fs/ecryptfs/inode.c | 32 ++ fs/erofs/inode.c | 6 +- fs/erofs/namei.c | 2 +- fs/ext2/acl.c | 3 +- fs/ext2/acl.h | 2 +- fs/ext2/file.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext2/namei.c | 4 +- fs/ext4/acl.c | 3 +- fs/ext4/acl.h | 2 +- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 2 +- fs/ext4/namei.c | 4 +- fs/f2fs/acl.c | 4 +- fs/f2fs/acl.h | 2 +- fs/f2fs/file.c | 4 +- fs/f2fs/namei.c | 4 +- fs/fuse/acl.c | 3 +- fs/fuse/dir.c | 4 +- fs/fuse/fuse_i.h | 2 +- fs/gfs2/acl.c | 3 +- fs/gfs2/acl.h | 2 +- fs/gfs2/inode.c | 6 +- fs/internal.h | 1 + fs/jffs2/acl.c | 3 +- fs/jffs2/acl.h | 2 +- fs/jffs2/dir.c | 2 +- fs/jffs2/file.c | 2 +- fs/jffs2/fs.c | 2 +- fs/jfs/acl.c | 3 +- fs/jfs/file.c | 4 +- fs/jfs/jfs_acl.h | 2 +- fs/jfs/namei.c | 2 +- fs/ksmbd/smb2pdu.c | 4 +- fs/ksmbd/smbacl.c | 4 +- fs/ksmbd/vfs.c | 17 +- fs/ksmbd/vfs.h | 4 +- fs/namei.c | 2 +- fs/nfs/nfs3_fs.h | 2 +- fs/nfs/nfs3acl.c | 3 +- fs/nfs/nfs3proc.c | 4 +- fs/nfsd/nfs2acl.c | 4 +- fs/nfsd/nfs3acl.c | 4 +- fs/nfsd/vfs.c | 4 +- fs/ntfs3/file.c | 4 +- fs/ntfs3/namei.c | 4 +- fs/ntfs3/ntfs_fs.h | 4 +- fs/ntfs3/xattr.c | 9 +- fs/ocfs2/acl.c | 3 +- fs/ocfs2/acl.h | 2 +- fs/ocfs2/file.c | 4 +- fs/ocfs2/namei.c | 2 +- fs/orangefs/acl.c | 47 +- fs/orangefs/inode.c | 47 +- fs/orangefs/namei.c | 2 +- fs/orangefs/orangefs-kernel.h | 9 +- fs/orangefs/orangefs-utils.c | 12 +- fs/overlayfs/copy_up.c | 38 ++ fs/overlayfs/dir.c | 22 +- fs/overlayfs/inode.c | 151 +++++- fs/overlayfs/overlayfs.h | 34 +- fs/overlayfs/super.c | 107 +--- fs/posix_acl.c | 681 +++++++++++++------------- fs/reiserfs/acl.h | 6 +- fs/reiserfs/file.c | 2 +- fs/reiserfs/inode.c | 2 +- fs/reiserfs/namei.c | 4 +- fs/reiserfs/xattr_acl.c | 9 +- fs/xattr.c | 78 ++- fs/xfs/xfs_acl.c | 3 +- fs/xfs/xfs_acl.h | 2 +- fs/xfs/xfs_iops.c | 16 +- include/linux/evm.h | 23 + include/linux/fs.h | 10 +- include/linux/lsm_hook_defs.h | 2 + include/linux/lsm_hooks.h | 4 + include/linux/posix_acl.h | 39 +- include/linux/posix_acl_xattr.h | 43 +- include/linux/security.h | 11 + include/linux/xattr.h | 8 + io_uring/xattr.c | 2 + mm/shmem.c | 2 +- security/integrity/evm/evm_main.c | 128 +++-- security/security.c | 16 + security/selinux/hooks.c | 8 + security/smack/smack_lsm.c | 24 + 107 files changed, 1550 insertions(+), 1043 deletions(-)
base-commit: 38e316398e4e6338b80223fb5f74415c0513718f
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 1/30 orangefs: rework posix acl handling when creating new filesystem objects
When creating new filesytem objects orangefs used to create posix acls after it had created and inserted a new inode. This made it necessary to all posix_acl_chmod() on the newly created inode in case the mode of the inode would be changed by the posix acls.
Instead of doing it this way calculate the correct mode directly before actually creating the inode. So we first create posix acls, then pass the mode that posix acls mandate into the orangefs getattr helper and calculate the correct mode. This is needed so we can simply change posix_acl_chmod() to take a dentry instead of an inode argument in the next patch.
---
Notes:
/* v2 */
Christoph Hellwig <[email protected]>
- Add separate patch for orangefs rework.
fs/orangefs/acl.c | 44 ++--------------------------------- fs/orangefs/inode.c | 44 ++++++++++++++++++++++++++++------- fs/orangefs/orangefs-kernel.h | 7 ++++-- fs/orangefs/orangefs-utils.c | 12 +++++++--- 4 files changed, 52 insertions(+), 55 deletions(-)
fs/orangefs/acl.c +2 -42
@@ -64,8 +64,7 @@ struct posix_acl *orangefs_get_acl(struct inode *inode, int type, bool rcu)return acl; } -static int __orangefs_set_acl (struct inode *inode,struct posix_acl *acl, -int type) +int __orangefs_set_acl (struct inode *inode,struct posix_acl *acl,int type) {int error =0 ;void *value =NULL ;
@@ -153,46 +152,7 @@ int orangefs_set_acl(struct user_namespace *mnt_userns, struct inode *inode, rc =__orangefs_set_acl (inode, acl, type);if (!rc && (iattr.ia_valid ==ATTR_MODE )) - rc =__orangefs_setattr (inode, &iattr); + rc =__orangefs_setattr_mode (inode, &iattr);return rc; } - -int orangefs_init_acl (struct inode *inode,struct inode *dir) -{ -struct posix_acl *default_acl, *acl; -umode_t mode = inode->i_mode; -struct iattr iattr; -int error =0 ; - - error =posix_acl_create (dir, &mode, &default_acl, &acl); -if (error) -return error; - -if (default_acl) { - error =__orangefs_set_acl (inode, default_acl, -ACL_TYPE_DEFAULT ); -posix_acl_release (default_acl); - }else { - inode->i_default_acl =NULL ; - } - -if (acl) { -if (!error) - error =__orangefs_set_acl (inode, acl,ACL_TYPE_ACCESS ); -posix_acl_release (acl); - }else { - inode->i_acl =NULL ; - } - -/* If mode of the inode was changed, then do a forcible ->setattr */ -if (mode != inode->i_mode) { -memset (&iattr,0 ,sizeof iattr); - inode->i_mode = mode; - iattr.ia_mode = mode; - iattr.ia_valid |=ATTR_MODE ; -__orangefs_setattr (inode, &iattr); - } - -return error; -}
fs/orangefs/inode.c +36 -8
92 lines not on this page · raw message
fs/orangefs/orangefs-kernel.h +5 -2
@@ -103,13 +103,14 @@ enum orangefs_vfs_op_states {#define ORANGEFS_CACHE_CREATE_FLAGS 0#endif -extern int orangefs_init_acl (struct inode *inode,struct inode *dir);extern const struct xattr_handler *orangefs_xattr_handlers[];extern struct posix_acl *orangefs_get_acl (struct inode *inode,int type,bool rcu);extern int orangefs_set_acl (struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl,int type); +extern int __orangefs_set_acl (struct inode *inode,struct posix_acl *acl, +int type);/* * orangefs data structures
@@ -356,11 +357,12 @@ void fsid_key_table_finalize(void);vm_fault_t orangefs_page_mkwrite (struct vm_fault *);struct inode *orangefs_new_inode (struct super_block *sb,struct inode *dir, -int mode, +umode_t mode,dev_t dev,struct orangefs_object_kref *ref);int __orangefs_setattr (struct inode *,struct iattr *); +int __orangefs_setattr_mode (struct inode *inode,struct iattr *iattr);int orangefs_setattr (struct user_namespace *,struct dentry *,struct iattr *); int orangefs_getattr(struct user_namespace *mnt_userns, const struct path *path,
@@ -422,6 +424,7 @@ int orangefs_inode_setxattr(struct inode *inode,#define ORANGEFS_GETATTR_SIZE 2int orangefs_inode_getattr (struct inode *,int ); +int __orangefs_inode_getattr (struct inode *inode,umode_t mode,int flags);int orangefs_inode_check_changed (struct inode *inode);
fs/orangefs/orangefs-utils.c +9 -3
@@ -233,7 +233,7 @@ static int orangefs_inode_is_stale(struct inode *inode,return 0 ; } -int orangefs_inode_getattr (struct inode *inode,int flags) +int __orangefs_inode_getattr (struct inode *inode,umode_t mode,int flags) {struct orangefs_inode_s *orangefs_inode =ORANGEFS_I (inode);struct orangefs_kernel_op_s *new_op;
@@ -368,8 +368,9 @@ int orangefs_inode_getattr(struct inode *inode, int flags) inode->i_ctime.tv_nsec =0 ;/* special case: mark the root inode as sticky */ - inode->i_mode = type | (is_root_handle (inode) ?S_ISVTX :0 ) | -orangefs_inode_perms (&new_op->downcall.resp.getattr.attributes); + inode->i_mode = type | (is_root_handle (inode) ?S_ISVTX :0 ) | mode | +orangefs_inode_perms (&new_op->downcall.resp.getattr.attributes) | + mode; orangefs_inode->getattr_time = jiffies + orangefs_getattr_timeout_msecs*HZ /1000 ;
@@ -381,6 +382,11 @@ int orangefs_inode_getattr(struct inode *inode, int flags)return ret; } +int orangefs_inode_getattr (struct inode *inode,int flags) +{ +return __orangefs_inode_getattr (inode,0 , flags); +} +int orangefs_inode_check_changed (struct inode *inode) {struct orangefs_inode_s *orangefs_inode =ORANGEFS_I (inode);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 3/30 fs: rename current get acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
The current inode operation for getting posix acls takes an inode argument but various filesystems (e.g., 9p, cifs, overlayfs) need access to the dentry. In contrast to the ->set_acl() inode operation we cannot simply extend ->get_acl() to take a dentry argument. The ->get_acl() inode operation is called from:
acl_permission_check()
-> check_acl()
-> get_acl()
which is part of generic_permission() which in turn is part of inode_permission(). Both generic_permission() and inode_permission() are called in the ->permission() handler of various filesystems (e.g., overlayfs). So simply passing a dentry argument to ->get_acl() would amount to also having to pass a dentry argument to ->permission(). We should avoid this unnecessary change.
So instead of extending the existing inode operation rename it from ->get_acl() to ->get_inode_acl() and add a ->get_acl() method later that passes a dentry argument and which filesystems that need access to the dentry can implement instead of ->get_inode_acl(). Filesystems like cifs which allow setting and getting posix acls but not using them for permission checking during lookup can simply not implement ->get_inode_acl().
This is intended to be a non-functional change.
Suggested-by/Inspired-by: Christoph Hellwig <[email protected]>
---
Notes:
/* v2 */
unchangedDocumentation/filesystems/locking.rst | 4 ++-- Documentation/filesystems/porting.rst | 4 ++-- Documentation/filesystems/vfs.rst | 2 +- fs/9p/vfs_inode_dotl.c | 4 ++-- fs/bad_inode.c | 2 +- fs/btrfs/inode.c | 6 +++--- fs/ceph/dir.c | 2 +- fs/ceph/inode.c | 2 +- fs/erofs/inode.c | 6 +++--- fs/erofs/namei.c | 2 +- fs/ext2/file.c | 2 +- fs/ext2/namei.c | 4 ++-- fs/ext4/file.c | 2 +- fs/ext4/namei.c | 4 ++-- fs/f2fs/file.c | 2 +- fs/f2fs/namei.c | 4 ++-- fs/fuse/dir.c | 4 ++-- fs/gfs2/inode.c | 4 ++-- fs/jffs2/dir.c | 2 +- fs/jffs2/file.c | 2 +- fs/jfs/file.c | 2 +- fs/jfs/namei.c | 2 +- fs/namei.c | 2 +- fs/nfs/nfs3proc.c | 4 ++-- fs/ntfs3/file.c | 2 +- fs/ntfs3/namei.c | 4 ++-- fs/ocfs2/file.c | 4 ++-- fs/ocfs2/namei.c | 2 +- fs/orangefs/inode.c | 2 +- fs/orangefs/namei.c | 2 +- fs/overlayfs/dir.c | 2 +- fs/overlayfs/inode.c | 4 ++-- fs/posix_acl.c | 27 ++++++++++++++------------- fs/reiserfs/file.c | 2 +- fs/reiserfs/namei.c | 4 ++-- fs/xfs/xfs_iops.c | 6 +++--- include/linux/fs.h | 6 +++--- 37 files changed, 71 insertions(+), 70 deletions(-)
Documentation/filesystems/locking.rst +2 -2
@@ -70,7 +70,7 @@ prototypes:: const char *(*get_link) (struct dentry *, struct inode *, struct delayed_call *); void (*truncate) (struct inode *); int (*permission) (struct inode *, int, unsigned int); - struct posix_acl * (*get_acl)(struct inode *, int, bool); + struct posix_acl * (*get_inode_acl)(struct inode *, int, bool); int (*setattr) (struct dentry *, struct iattr *); int (*getattr) (const struct path *, struct kstat *, u32, unsigned int); ssize_t (*listxattr) (struct dentry *, char *, size_t);
@@ -103,7 +103,7 @@ readlink: no get_link: no setattr: exclusive permission: no (may not block if called in rcu-walk mode) -get_acl: no +get_inode_acl: no getattr: no listxattr: no fiemap: no
Documentation/filesystems/porting.rst +2 -2
@@ -462,8 +462,8 @@ ERR_PTR(...). argument; instead of passing IPERM_FLAG_RCU we add MAY_NOT_BLOCK into mask. generic_permission() has also lost the check_acl argument; ACL checking -has been taken to VFS and filesystems need to provide a non-NULL ->i_op->get_acl -to read an ACL from disk. +has been taken to VFS and filesystems need to provide a non-NULL +->i_op->get_inode_acl to read an ACL from disk. ---
Documentation/filesystems/vfs.rst +1 -1
@@ -432,7 +432,7 @@ As of kernel 2.6.22, the following members are defined: const char *(*get_link) (struct dentry *, struct inode *, struct delayed_call *); int (*permission) (struct user_namespace *, struct inode *, int); - struct posix_acl * (*get_acl)(struct inode *, int, bool); + struct posix_acl * (*get_inode_acl)(struct inode *, int, bool); int (*setattr) (struct user_namespace *, struct dentry *, struct iattr *); int (*getattr) (struct user_namespace *, const struct path *, struct kstat *, u32, unsigned int); ssize_t (*listxattr) (struct dentry *, char *, size_t);
fs/9p/vfs_inode_dotl.c +2 -2
@@ -983,14 +983,14 @@ const struct inode_operations v9fs_dir_inode_operations_dotl = { .getattr = v9fs_vfs_getattr_dotl, .setattr = v9fs_vfs_setattr_dotl, .listxattr = v9fs_listxattr, - .get_acl = v9fs_iop_get_acl, + .get_inode_acl = v9fs_iop_get_acl, };const struct inode_operations v9fs_file_inode_operations_dotl = { .getattr = v9fs_vfs_getattr_dotl, .setattr = v9fs_vfs_setattr_dotl, .listxattr = v9fs_listxattr, - .get_acl = v9fs_iop_get_acl, + .get_inode_acl = v9fs_iop_get_acl, };const struct inode_operations v9fs_symlink_inode_operations_dotl = {
fs/bad_inode.c +1 -1
@@ -177,7 +177,7 @@ static const struct inode_operations bad_inode_ops = .setattr = bad_inode_setattr, .listxattr = bad_inode_listxattr, .get_link = bad_inode_get_link, - .get_acl = bad_inode_get_acl, + .get_inode_acl = bad_inode_get_acl, .fiemap = bad_inode_fiemap, .update_time = bad_inode_update_time, .atomic_open = bad_inode_atomic_open,
fs/btrfs/inode.c +3 -3
@@ -11441,7 +11441,7 @@ static const struct inode_operations btrfs_dir_inode_operations = { .mknod = btrfs_mknod, .listxattr = btrfs_listxattr, .permission = btrfs_permission, - .get_acl = btrfs_get_acl, + .get_inode_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, .update_time = btrfs_update_time, .tmpfile = btrfs_tmpfile,
@@ -11494,7 +11494,7 @@ static const struct inode_operations btrfs_file_inode_operations = { .listxattr = btrfs_listxattr, .permission = btrfs_permission, .fiemap = btrfs_fiemap, - .get_acl = btrfs_get_acl, + .get_inode_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, .update_time = btrfs_update_time, .fileattr_get = btrfs_fileattr_get,
@@ -11505,7 +11505,7 @@ static const struct inode_operations btrfs_special_inode_operations = { .setattr = btrfs_setattr, .permission = btrfs_permission, .listxattr = btrfs_listxattr, - .get_acl = btrfs_get_acl, + .get_inode_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, .update_time = btrfs_update_time, };
fs/ceph/dir.c +1 -1
@@ -2033,7 +2033,7 @@ const struct inode_operations ceph_dir_iops = { .getattr = ceph_getattr, .setattr = ceph_setattr, .listxattr = ceph_listxattr, - .get_acl = ceph_get_acl, + .get_inode_acl = ceph_get_acl, .set_acl = ceph_set_acl, .mknod = ceph_mknod, .symlink = ceph_symlink,
fs/ceph/inode.c +1 -1
@@ -126,7 +126,7 @@ const struct inode_operations ceph_file_iops = { .setattr = ceph_setattr, .getattr = ceph_getattr, .listxattr = ceph_listxattr, - .get_acl = ceph_get_acl, + .get_inode_acl = ceph_get_acl, .set_acl = ceph_set_acl, };
fs/erofs/inode.c +3 -3
@@ -379,7 +379,7 @@ int erofs_getattr(struct user_namespace *mnt_userns, const struct path *path,const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, .listxattr = erofs_listxattr, - .get_acl = erofs_get_acl, + .get_inode_acl = erofs_get_acl, .fiemap = erofs_fiemap, };
@@ -387,12 +387,12 @@ const struct inode_operations erofs_symlink_iops = { .get_link = page_get_link, .getattr = erofs_getattr, .listxattr = erofs_listxattr, - .get_acl = erofs_get_acl, + .get_inode_acl = erofs_get_acl, };const struct inode_operations erofs_fast_symlink_iops = { .get_link = simple_get_link, .getattr = erofs_getattr, .listxattr = erofs_listxattr, - .get_acl = erofs_get_acl, + .get_inode_acl = erofs_get_acl, };
fs/erofs/namei.c +1 -1
@@ -237,6 +237,6 @@ const struct inode_operations erofs_dir_iops = { .lookup = erofs_lookup, .getattr = erofs_getattr, .listxattr = erofs_listxattr, - .get_acl = erofs_get_acl, + .get_inode_acl = erofs_get_acl, .fiemap = erofs_fiemap, };
fs/ext2/file.c +1 -1
@@ -200,7 +200,7 @@ const struct inode_operations ext2_file_inode_operations = { .listxattr = ext2_listxattr, .getattr = ext2_getattr, .setattr = ext2_setattr, - .get_acl = ext2_get_acl, + .get_inode_acl = ext2_get_acl, .set_acl = ext2_set_acl, .fiemap = ext2_fiemap, .fileattr_get = ext2_fileattr_get,
fs/ext2/namei.c +2 -2
@@ -427,7 +427,7 @@ const struct inode_operations ext2_dir_inode_operations = { .listxattr = ext2_listxattr, .getattr = ext2_getattr, .setattr = ext2_setattr, - .get_acl = ext2_get_acl, + .get_inode_acl = ext2_get_acl, .set_acl = ext2_set_acl, .tmpfile = ext2_tmpfile, .fileattr_get = ext2_fileattr_get,
@@ -438,6 +438,6 @@ const struct inode_operations ext2_special_inode_operations = { .listxattr = ext2_listxattr, .getattr = ext2_getattr, .setattr = ext2_setattr, - .get_acl = ext2_get_acl, + .get_inode_acl = ext2_get_acl, .set_acl = ext2_set_acl, };
fs/ext4/file.c +1 -1
@@ -934,7 +934,7 @@ const struct inode_operations ext4_file_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_file_getattr, .listxattr = ext4_listxattr, - .get_acl = ext4_get_acl, + .get_inode_acl = ext4_get_acl, .set_acl = ext4_set_acl, .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get,
fs/ext4/namei.c +2 -2
@@ -4181,7 +4181,7 @@ const struct inode_operations ext4_dir_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, - .get_acl = ext4_get_acl, + .get_inode_acl = ext4_get_acl, .set_acl = ext4_set_acl, .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get,
@@ -4192,6 +4192,6 @@ const struct inode_operations ext4_special_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, - .get_acl = ext4_get_acl, + .get_inode_acl = ext4_get_acl, .set_acl = ext4_set_acl, };
fs/f2fs/file.c +1 -1
@@ -999,7 +999,7 @@ int f2fs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,const struct inode_operations f2fs_file_inode_operations = { .getattr = f2fs_getattr, .setattr = f2fs_setattr, - .get_acl = f2fs_get_acl, + .get_inode_acl = f2fs_get_acl, .set_acl = f2fs_set_acl, .listxattr = f2fs_listxattr, .fiemap = f2fs_fiemap,
fs/f2fs/namei.c +2 -2
@@ -1376,7 +1376,7 @@ const struct inode_operations f2fs_dir_inode_operations = { .tmpfile = f2fs_tmpfile, .getattr = f2fs_getattr, .setattr = f2fs_setattr, - .get_acl = f2fs_get_acl, + .get_inode_acl = f2fs_get_acl, .set_acl = f2fs_set_acl, .listxattr = f2fs_listxattr, .fiemap = f2fs_fiemap,
@@ -1394,7 +1394,7 @@ const struct inode_operations f2fs_symlink_inode_operations = {const struct inode_operations f2fs_special_inode_operations = { .getattr = f2fs_getattr, .setattr = f2fs_setattr, - .get_acl = f2fs_get_acl, + .get_inode_acl = f2fs_get_acl, .set_acl = f2fs_set_acl, .listxattr = f2fs_listxattr, };
fs/fuse/dir.c +2 -2
@@ -1917,7 +1917,7 @@ static const struct inode_operations fuse_dir_inode_operations = { .permission = fuse_permission, .getattr = fuse_getattr, .listxattr = fuse_listxattr, - .get_acl = fuse_get_acl, + .get_inode_acl = fuse_get_acl, .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set,
@@ -1939,7 +1939,7 @@ static const struct inode_operations fuse_common_inode_operations = { .permission = fuse_permission, .getattr = fuse_getattr, .listxattr = fuse_listxattr, - .get_acl = fuse_get_acl, + .get_inode_acl = fuse_get_acl, .set_acl = fuse_set_acl, .fileattr_get = fuse_fileattr_get, .fileattr_set = fuse_fileattr_set,
fs/gfs2/inode.c +2 -2
@@ -2142,7 +2142,7 @@ static const struct inode_operations gfs2_file_iops = { .getattr = gfs2_getattr, .listxattr = gfs2_listxattr, .fiemap = gfs2_fiemap, - .get_acl = gfs2_get_acl, + .get_inode_acl = gfs2_get_acl, .set_acl = gfs2_set_acl, .update_time = gfs2_update_time, .fileattr_get = gfs2_fileattr_get,
@@ -2164,7 +2164,7 @@ static const struct inode_operations gfs2_dir_iops = { .getattr = gfs2_getattr, .listxattr = gfs2_listxattr, .fiemap = gfs2_fiemap, - .get_acl = gfs2_get_acl, + .get_inode_acl = gfs2_get_acl, .set_acl = gfs2_set_acl, .update_time = gfs2_update_time, .atomic_open = gfs2_atomic_open,
fs/jffs2/dir.c +1 -1
@@ -62,7 +62,7 @@ const struct inode_operations jffs2_dir_inode_operations = .rmdir = jffs2_rmdir, .mknod = jffs2_mknod, .rename = jffs2_rename, - .get_acl = jffs2_get_acl, + .get_inode_acl = jffs2_get_acl, .set_acl = jffs2_set_acl, .setattr = jffs2_setattr, .listxattr = jffs2_listxattr,
fs/jffs2/file.c +1 -1
@@ -64,7 +64,7 @@ const struct file_operations jffs2_file_operations =const struct inode_operations jffs2_file_inode_operations = { - .get_acl = jffs2_get_acl, + .get_inode_acl = jffs2_get_acl, .set_acl = jffs2_set_acl, .setattr = jffs2_setattr, .listxattr = jffs2_listxattr,
fs/jfs/file.c +1 -1
@@ -133,7 +133,7 @@ const struct inode_operations jfs_file_inode_operations = { .fileattr_get = jfs_fileattr_get, .fileattr_set = jfs_fileattr_set, #ifdef CONFIG_JFS_POSIX_ACL - .get_acl = jfs_get_acl, + .get_inode_acl = jfs_get_acl, .set_acl = jfs_set_acl,#endif };
fs/jfs/namei.c +1 -1
@@ -1525,7 +1525,7 @@ const struct inode_operations jfs_dir_inode_operations = { .fileattr_get = jfs_fileattr_get, .fileattr_set = jfs_fileattr_set, #ifdef CONFIG_JFS_POSIX_ACL - .get_acl = jfs_get_acl, + .get_inode_acl = jfs_get_acl, .set_acl = jfs_set_acl,#endif };
fs/namei.c +1 -1
@@ -297,7 +297,7 @@ static int check_acl(struct user_namespace *mnt_userns, acl =get_cached_acl_rcu (inode,ACL_TYPE_ACCESS );if (!acl)return -EAGAIN ; -/* no ->get_acl() calls in RCU mode... */ +/* no ->get_inode_acl() calls in RCU mode... */ if (is_uncached_acl (acl))return -ECHILD ;return posix_acl_permission (mnt_userns, inode, acl, mask);
fs/nfs/nfs3proc.c +2 -2
@@ -997,7 +997,7 @@ static const struct inode_operations nfs3_dir_inode_operations = { .setattr = nfs_setattr, #ifdef CONFIG_NFS_V3_ACL .listxattr = nfs3_listxattr, - .get_acl = nfs3_get_acl, + .get_inode_acl = nfs3_get_acl, .set_acl = nfs3_set_acl, #endif };
@@ -1008,7 +1008,7 @@ static const struct inode_operations nfs3_file_inode_operations = { .setattr = nfs_setattr, #ifdef CONFIG_NFS_V3_ACL .listxattr = nfs3_listxattr, - .get_acl = nfs3_get_acl, + .get_inode_acl = nfs3_get_acl, .set_acl = nfs3_set_acl, #endif };
fs/ntfs3/file.c +1 -1
@@ -1255,7 +1255,7 @@ const struct inode_operations ntfs_file_inode_operations = { .setattr = ntfs3_setattr, .listxattr = ntfs_listxattr, .permission = ntfs_permission, - .get_acl = ntfs_get_acl, + .get_inode_acl = ntfs_get_acl, .set_acl = ntfs_set_acl, .fiemap = ntfs_fiemap, };
fs/ntfs3/namei.c +2 -2
@@ -367,7 +367,7 @@ const struct inode_operations ntfs_dir_inode_operations = { .mknod = ntfs_mknod, .rename = ntfs_rename, .permission = ntfs_permission, - .get_acl = ntfs_get_acl, + .get_inode_acl = ntfs_get_acl, .set_acl = ntfs_set_acl, .setattr = ntfs3_setattr, .getattr = ntfs_getattr,
@@ -379,7 +379,7 @@ const struct inode_operations ntfs_special_inode_operations = { .setattr = ntfs3_setattr, .getattr = ntfs_getattr, .listxattr = ntfs_listxattr, - .get_acl = ntfs_get_acl, + .get_inode_acl = ntfs_get_acl, .set_acl = ntfs_set_acl, };// clang-format on
fs/ocfs2/file.c +2 -2
@@ -2712,7 +2712,7 @@ const struct inode_operations ocfs2_file_iops = { .permission = ocfs2_permission, .listxattr = ocfs2_listxattr, .fiemap = ocfs2_fiemap, - .get_acl = ocfs2_iop_get_acl, + .get_inode_acl = ocfs2_iop_get_acl, .set_acl = ocfs2_iop_set_acl, .fileattr_get = ocfs2_fileattr_get, .fileattr_set = ocfs2_fileattr_set,
@@ -2722,7 +2722,7 @@ const struct inode_operations ocfs2_special_file_iops = { .setattr = ocfs2_setattr, .getattr = ocfs2_getattr, .permission = ocfs2_permission, - .get_acl = ocfs2_iop_get_acl, + .get_inode_acl = ocfs2_iop_get_acl, .set_acl = ocfs2_iop_set_acl, };
fs/ocfs2/namei.c +1 -1
@@ -2916,7 +2916,7 @@ const struct inode_operations ocfs2_dir_iops = { .permission = ocfs2_permission, .listxattr = ocfs2_listxattr, .fiemap = ocfs2_fiemap, - .get_acl = ocfs2_iop_get_acl, + .get_inode_acl = ocfs2_iop_get_acl, .set_acl = ocfs2_iop_set_acl, .fileattr_get = ocfs2_fileattr_get, .fileattr_set = ocfs2_fileattr_set,
fs/orangefs/inode.c +1 -1
@@ -975,7 +975,7 @@ static int orangefs_fileattr_set(struct user_namespace *mnt_userns,/* ORANGEFS2 implementation of VFS inode operations for files */ static const struct inode_operations orangefs_file_inode_operations = { - .get_acl = orangefs_get_acl, + .get_inode_acl = orangefs_get_acl, .set_acl = orangefs_set_acl, .setattr = orangefs_setattr, .getattr = orangefs_getattr,
fs/orangefs/namei.c +1 -1
@@ -430,7 +430,7 @@ static int orangefs_rename(struct user_namespace *mnt_userns,/* ORANGEFS implementation of VFS inode operations for directories */ const struct inode_operations orangefs_dir_inode_operations = { .lookup = orangefs_lookup, - .get_acl = orangefs_get_acl, + .get_inode_acl = orangefs_get_acl, .set_acl = orangefs_set_acl, .create = orangefs_create, .unlink = orangefs_unlink,
fs/overlayfs/dir.c +1 -1
@@ -1311,7 +1311,7 @@ const struct inode_operations ovl_dir_inode_operations = { .permission = ovl_permission, .getattr = ovl_getattr, .listxattr = ovl_listxattr, - .get_acl = ovl_get_acl, + .get_inode_acl = ovl_get_acl, .update_time = ovl_update_time, .fileattr_get = ovl_fileattr_get, .fileattr_set = ovl_fileattr_set,
fs/overlayfs/inode.c +2 -2
@@ -721,7 +721,7 @@ static const struct inode_operations ovl_file_inode_operations = { .permission = ovl_permission, .getattr = ovl_getattr, .listxattr = ovl_listxattr, - .get_acl = ovl_get_acl, + .get_inode_acl = ovl_get_acl, .update_time = ovl_update_time, .fiemap = ovl_fiemap, .fileattr_get = ovl_fileattr_get,
@@ -741,7 +741,7 @@ static const struct inode_operations ovl_special_inode_operations = { .permission = ovl_permission, .getattr = ovl_getattr, .listxattr = ovl_listxattr, - .get_acl = ovl_get_acl, + .get_inode_acl = ovl_get_acl, .update_time = ovl_update_time, };
fs/posix_acl.c +14 -13
@@ -63,7 +63,7 @@ struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type)if (acl ==ACL_DONT_CACHE ) {struct posix_acl *ret; - ret = inode->i_op->get_acl (inode, type,LOOKUP_RCU ); + ret = inode->i_op->get_inode_acl (inode, type,LOOKUP_RCU );if (!IS_ERR (ret)) acl = ret; }
@@ -132,24 +132,24 @@ struct posix_acl *get_acl(struct inode *inode, int type)* current value of the ACL will not be ACL_NOT_CACHED and so our own * sentinel will not be set; another task will update the cache. We * could wait for that other task to complete its job, but it's easier -* to just call ->get_acl to fetch the ACL ourself. (This is going to -* be an unlikely race.) +* to just call ->get_inode_acl to fetch the ACL ourself. (This is +* going to be an unlikely race.) */ cmpxchg (p,ACL_NOT_CACHED , sentinel);/* -* Normally, the ACL returned by ->get_acl will be cached. +* Normally, the ACL returned by ->get_inode_acl will be cached. * A filesystem can prevent that by calling -* forget_cached_acl(inode, type) in ->get_acl. +* forget_cached_acl(inode, type) in ->get_inode_acl. * * If the filesystem doesn't have a get_acl() function at all, we'll * just create the negative cache entry. */ -if (!inode->i_op->get_acl) { +if (!inode->i_op->get_inode_acl) {set_cached_acl (inode, type,NULL );return NULL ; } - acl = inode->i_op->get_acl (inode, type, false); + acl = inode->i_op->get_inode_acl (inode, type, false);if (IS_ERR (acl)) {/*
@@ -1044,7 +1044,8 @@ posix_acl_from_xattr_kgid(struct user_namespace *mnt_userns,* Filesystems that store POSIX ACLs in the unaltered uapi format should use * posix_acl_from_xattr() when reading them from the backing store and * converting them into the struct posix_acl VFS format. The helper is -* specifically intended to be called from the ->get_acl() inode operation. +* specifically intended to be called from the ->get_inode_acl() inode +* operation. * * The posix_acl_from_xattr() function will map the raw {g,u}id values stored * in ACL_{GROUP,USER} entries into the filesystem idmapping in @fs_userns. The
@@ -1052,11 +1053,11 @@ posix_acl_from_xattr_kgid(struct user_namespace *mnt_userns,* correct k{g,u}id_t. The returned struct posix_acl can be cached. * * Note that posix_acl_from_xattr() does not take idmapped mounts into account. -* If it did it calling is from the ->get_acl() inode operation would return -* POSIX ACLs mapped according to an idmapped mount which would mean that the -* value couldn't be cached for the filesystem. Idmapped mounts are taken into -* account on the fly during permission checking or right at the VFS - -* userspace boundary before reporting them to the user. +* If it did it calling is from the ->get_inode_acl() inode operation would +* return POSIX ACLs mapped according to an idmapped mount which would mean +* that the value couldn't be cached for the filesystem. Idmapped mounts are +* taken into account on the fly during permission checking or right at the VFS +* - userspace boundary before reporting them to the user. * * Return: Allocated struct posix_acl on success, NULL for a valid header but * without actual POSIX ACL entries, or ERR_PTR() encoded error code.
fs/reiserfs/file.c +1 -1
@@ -256,7 +256,7 @@ const struct inode_operations reiserfs_file_inode_operations = { .setattr = reiserfs_setattr, .listxattr = reiserfs_listxattr, .permission = reiserfs_permission, - .get_acl = reiserfs_get_acl, + .get_inode_acl = reiserfs_get_acl, .set_acl = reiserfs_set_acl, .fileattr_get = reiserfs_fileattr_get, .fileattr_set = reiserfs_fileattr_set,
fs/reiserfs/namei.c +2 -2
@@ -1659,7 +1659,7 @@ const struct inode_operations reiserfs_dir_inode_operations = { .setattr = reiserfs_setattr, .listxattr = reiserfs_listxattr, .permission = reiserfs_permission, - .get_acl = reiserfs_get_acl, + .get_inode_acl = reiserfs_get_acl, .set_acl = reiserfs_set_acl, .fileattr_get = reiserfs_fileattr_get, .fileattr_set = reiserfs_fileattr_set,
@@ -1683,6 +1683,6 @@ const struct inode_operations reiserfs_special_inode_operations = { .setattr = reiserfs_setattr, .listxattr = reiserfs_listxattr, .permission = reiserfs_permission, - .get_acl = reiserfs_get_acl, + .get_inode_acl = reiserfs_get_acl, .set_acl = reiserfs_set_acl, };
fs/xfs/xfs_iops.c +3 -3
@@ -1089,7 +1089,7 @@ xfs_vn_tmpfile( }static const struct inode_operations xfs_inode_operations = { - .get_acl = xfs_get_acl, + .get_inode_acl = xfs_get_acl, .set_acl = xfs_set_acl, .getattr = xfs_vn_getattr, .setattr = xfs_vn_setattr,
@@ -1116,7 +1116,7 @@ static const struct inode_operations xfs_dir_inode_operations = { .rmdir = xfs_vn_unlink, .mknod = xfs_vn_mknod, .rename = xfs_vn_rename, - .get_acl = xfs_get_acl, + .get_inode_acl = xfs_get_acl, .set_acl = xfs_set_acl, .getattr = xfs_vn_getattr, .setattr = xfs_vn_setattr,
@@ -1143,7 +1143,7 @@ static const struct inode_operations xfs_dir_ci_inode_operations = { .rmdir = xfs_vn_unlink, .mknod = xfs_vn_mknod, .rename = xfs_vn_rename, - .get_acl = xfs_get_acl, + .get_inode_acl = xfs_get_acl, .set_acl = xfs_set_acl, .getattr = xfs_vn_getattr, .setattr = xfs_vn_setattr,
include/linux/fs.h +3 -3
@@ -560,8 +560,8 @@ struct posix_acl;#define ACL_NOT_CACHED ((void *)(-1))/* * ACL_DONT_CACHE is for stacked filesystems, that rely on underlying fs to -* cache the ACL. This also means that ->get_acl() can be called in RCU mode -* with the LOOKUP_RCU flag. +* cache the ACL. This also means that ->get_inode_acl() can be called in RCU +* mode with the LOOKUP_RCU flag. */ #define ACL_DONT_CACHE ((void *)(-3))
@@ -2138,7 +2138,7 @@ struct inode_operations {struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int );const char * (*get_link) (struct dentry *,struct inode *,struct delayed_call *);int (*permission) (struct user_namespace *,struct inode *,int ); -struct posix_acl * (*get_acl)(struct inode *,int ,bool ); +struct posix_acl * (*get_inode_acl)(struct inode *,int ,bool );int (*readlink) (struct dentry *,char __user *,int );
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 4/30 fs: add new get acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
Since some filesystem rely on the dentry being available to them when setting posix acls (e.g., 9p and cifs) they cannot rely on the old get acl inode operation to retrieve posix acl and need to implement their own custom handlers because of that.
In a previous patch we renamed the old get acl inode operation to ->get_inode_acl(). We decided to rename it and implement a new one since ->get_inode_acl() is called generic_permission() and inode_permission() both of which can be called during an filesystem's ->permission() handler. So simply passing a dentry argument to ->get_acl() would have amounted to also having to pass a dentry argument to ->permission(). We avoided that change.
This adds a new ->get_acl() inode operations which takes a dentry argument which filesystems such as 9p, cifs, and overlayfs can implement to get posix acls.
---
Notes:
/* v2 */
unchangedDocumentation/filesystems/locking.rst | 2 ++ Documentation/filesystems/vfs.rst | 1 + include/linux/fs.h | 2 ++ 3 files changed, 5 insertions(+)
Documentation/filesystems/locking.rst +2 -0
@@ -83,6 +83,7 @@ prototypes:: int (*fileattr_set)(struct user_namespace *mnt_userns, struct dentry *dentry, struct fileattr *fa); int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa); + struct posix_acl * (*get_acl)(struct user_namespace *, struct dentry *, int); locking rules: all may block
@@ -104,6 +105,7 @@ get_link: no setattr: exclusive permission: no (may not block if called in rcu-walk mode) get_inode_acl: no +get_acl: no getattr: no listxattr: no fiemap: no
Documentation/filesystems/vfs.rst +1 -0
@@ -440,6 +440,7 @@ As of kernel 2.6.22, the following members are defined: int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode); int (*tmpfile) (struct user_namespace *, struct inode *, struct dentry *, umode_t); + struct posix_acl * (*get_acl)(struct user_namespace *, struct dentry *, int); int (*set_acl)(struct user_namespace *, struct inode *, struct posix_acl *, int); int (*fileattr_set)(struct user_namespace *mnt_userns, struct dentry *dentry, struct fileattr *fa);
include/linux/fs.h +2 -0
@@ -2168,6 +2168,8 @@ struct inode_operations { umode_t create_mode);int (*tmpfile) (struct user_namespace *,struct inode *,struct dentry *,umode_t ); +struct posix_acl *(*get_acl)(struct user_namespace *,struct dentry *, +int );int (*set_acl)(struct user_namespace *,struct dentry *,struct posix_acl *,int ); int (*fileattr_set)(struct user_namespace *mnt_userns,
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 20/30 ecryptfs: implement get acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
So far ecryptfs didn't implement get and set acl inode operations because it wanted easy access to the dentry. Now that we extended the set acl inode operation to take a dentry argument and added a new get acl inode operation that takes a dentry argument we can let ecryptfs implement get and set acl inode operations.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
unchangedfs/ecryptfs/inode.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/ecryptfs/inode.c +11 -0
@@ -18,6 +18,8 @@#include <linux/fs_stack.h> #include <linux/slab.h> #include <linux/xattr.h> +#include <linux/posix_acl.h> +#include <linux/posix_acl_xattr.h> #include <linux/fileattr.h> #include <asm/unaligned.h> #include "ecryptfs_kernel.h"
@@ -1120,6 +1122,13 @@ static int ecryptfs_fileattr_set(struct user_namespace *mnt_userns,return rc; } +static struct posix_acl *ecryptfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,int type) +{ +return vfs_get_acl (mnt_userns,ecryptfs_dentry_to_lower (dentry), +posix_acl_xattr_name (type)); +} +const struct inode_operations ecryptfs_symlink_iops = { .get_link = ecryptfs_get_link, .permission = ecryptfs_permission,
@@ -1143,6 +1152,7 @@ const struct inode_operations ecryptfs_dir_iops = { .listxattr = ecryptfs_listxattr, .fileattr_get = ecryptfs_fileattr_get, .fileattr_set = ecryptfs_fileattr_set, + .get_acl = ecryptfs_get_acl, };const struct inode_operations ecryptfs_main_iops = {
@@ -1152,6 +1162,7 @@ const struct inode_operations ecryptfs_main_iops = { .listxattr = ecryptfs_listxattr, .fileattr_get = ecryptfs_fileattr_get, .fileattr_set = ecryptfs_fileattr_set, + .get_acl = ecryptfs_get_acl, }; static int ecryptfs_xattr_get(const struct xattr_handler *handler,
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 21/30 ecryptfs: implement set acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
So far ecryptfs didn't implement get and set acl inode operations because it wanted easy access to the dentry. Now that we extended the set acl inode operation to take a dentry argument and added a new get acl inode operation that takes a dentry argument we can let ecryptfs implement get and set acl inode operations.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
unchangedfs/ecryptfs/inode.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/ecryptfs/inode.c +17 -0
@@ -1129,6 +1129,21 @@ static struct posix_acl *ecryptfs_get_acl(struct user_namespace *mnt_userns, posix_acl_xattr_name(type)); } +static int ecryptfs_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,struct posix_acl *acl, +int type) +{ +int rc; +struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry); +struct inode *lower_inode =d_inode (lower_dentry); + + rc =vfs_set_acl (&init_user_ns, lower_dentry, +posix_acl_xattr_name (type), acl); +if (!rc) +fsstack_copy_attr_all (d_inode (dentry), lower_inode); +return rc; +} +const struct inode_operations ecryptfs_symlink_iops = { .get_link = ecryptfs_get_link, .permission = ecryptfs_permission,
@@ -1153,6 +1168,7 @@ const struct inode_operations ecryptfs_dir_iops = { .fileattr_get = ecryptfs_fileattr_get, .fileattr_set = ecryptfs_fileattr_set, .get_acl = ecryptfs_get_acl, + .set_acl = ecryptfs_set_acl, };const struct inode_operations ecryptfs_main_iops = {
@@ -1163,6 +1179,7 @@ const struct inode_operations ecryptfs_main_iops = { .fileattr_get = ecryptfs_fileattr_get, .fileattr_set = ecryptfs_fileattr_set, .get_acl = ecryptfs_get_acl, + .set_acl = ecryptfs_set_acl, }; static int ecryptfs_xattr_get(const struct xattr_handler *handler,
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 26/30 ecryptfs: use stub posix acl handlers
In reply to Christian BraunerNow that ecryptfs supports the get and set acl inode operations and the vfs has been switched to the new posi api, ecryptfs can simply rely on the stub posix acl handlers.
---
Notes:
/* v2 */
unchangedfs/ecryptfs/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ecryptfs/inode.c +4 -0
@@ -1210,6 +1210,10 @@ static const struct xattr_handler ecryptfs_xattr_handler = { };const struct xattr_handler *ecryptfs_xattr_handlers[] = { +#ifdef CONFIG_XFS_POSIX_ACL + &posix_acl_access_xattr_handler, + &posix_acl_default_xattr_handler, +#endif &ecryptfs_xattr_handler,NULL };
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 6/30 cifs: implement set acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
So far cifs wasn't able to implement get and set acl inode operations because it needs access to the dentry. Now that we extended the set acl inode operation to take a dentry argument and added a new get acl inode operation that takes a dentry argument we can let cifs implement get and set acl inode operations.
This is mostly a copy and paste of the codepaths currently used in cifs' posix acl xattr handler. After we have fully implemented the posix acl api and switched the vfs over to it, the cifs specific posix acl xattr handler and associated code will be removed and the code duplication will go away.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
unchangedfs/cifs/cifsacl.c | 74 ++++++++++++++++++++ fs/cifs/cifsfs.c | 2 + fs/cifs/cifsproto.h | 6 ++ fs/cifs/cifssmb.c | 160 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 242 insertions(+)
fs/cifs/cifsacl.c +74 -0
@@ -14,6 +14,8 @@#include <linux/keyctl.h> #include <linux/key-type.h> #include <uapi/linux/posix_acl.h> +#include <linux/posix_acl.h> +#include <linux/posix_acl_xattr.h> #include <keys/user-type.h> #include "cifspdu.h" #include "cifsglob.h"
@@ -1735,3 +1737,75 @@ struct posix_acl *cifs_get_acl(struct user_namespace *mnt_userns,return ERR_PTR (-EOPNOTSUPP );#endif } + +int cifs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +struct posix_acl *acl,int type) +{ +int rc = -EOPNOTSUPP ; +unsigned int xid; +struct super_block *sb = dentry->d_sb; +struct cifs_sb_info *cifs_sb =CIFS_SB (sb); +struct tcon_link *tlink; +struct cifs_tcon *pTcon; +const char *full_path; +void *page; + + tlink =cifs_sb_tlink (cifs_sb); +if (IS_ERR (tlink)) +return PTR_ERR (tlink); + pTcon =tlink_tcon (tlink); + + xid =get_xid (); + page =alloc_dentry_path (); + + full_path =build_path_from_dentry (dentry, page); +if (IS_ERR (full_path)) { + rc =PTR_ERR (full_path); + goto out; + } +/* return dos attributes as pseudo xattr */ +/* return alt name if available as pseudo attr */ + +/* if proc/fs/cifs/streamstoxattr is set then +search server for EAs or streams to +returns as xattrs */ +if (posix_acl_xattr_size (acl->a_count) > CIFSMaxBufSize) { +cifs_dbg (FYI ,"size of EA value too large\n" ); + rc = -EOPNOTSUPP ; + goto out; + } + +switch (type) { +#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY +case ACL_TYPE_ACCESS : +#ifdef CONFIG_CIFS_POSIX +if (!acl) + goto out; +if (sb->s_flags &SB_POSIXACL ) + rc =cifs_do_set_acl (xid, pTcon, full_path, acl, +ACL_TYPE_ACCESS , + cifs_sb->local_nls, +cifs_remap (cifs_sb)); +#endif /* CONFIG_CIFS_POSIX */ +break ; + +case ACL_TYPE_DEFAULT : +#ifdef CONFIG_CIFS_POSIX +if (!acl) + goto out; +if (sb->s_flags &SB_POSIXACL ) + rc =cifs_do_set_acl (xid, pTcon, full_path, acl, +ACL_TYPE_DEFAULT , + cifs_sb->local_nls, +cifs_remap (cifs_sb)); +#endif /* CONFIG_CIFS_POSIX */ +break ; +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ + } + +out: +free_dentry_path (page); +free_xid (xid); +cifs_put_tlink (tlink); +return rc; +}
fs/cifs/cifsfs.c +2 -0
@@ -1129,6 +1129,7 @@ const struct inode_operations cifs_dir_inode_ops = { .mknod = cifs_mknod, .listxattr = cifs_listxattr, .get_acl = cifs_get_acl, + .set_acl = cifs_set_acl, };const struct inode_operations cifs_file_inode_ops = {
@@ -1138,6 +1139,7 @@ const struct inode_operations cifs_file_inode_ops = { .listxattr = cifs_listxattr, .fiemap = cifs_fiemap, .get_acl = cifs_get_acl, + .set_acl = cifs_set_acl, };const struct inode_operations cifs_symlink_inode_ops = {
fs/cifs/cifsproto.h +6 -0
@@ -227,6 +227,8 @@ extern struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *, const struct cifs_fid *, u32 *, u32);extern struct posix_acl *cifs_get_acl (struct user_namespace *mnt_userns,struct dentry *dentry,int type); +extern int cifs_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,struct posix_acl *acl,int type);extern int set_cifs_acl (struct cifs_ntsd *,__u32 ,struct inode *,const char *,int );extern unsigned int setup_authusers_ACE (struct cifs_ace *pace);
@@ -552,6 +554,10 @@ extern int CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon,const unsigned char *fileName, const char *local_acl, const int buflen, const int acl_type, const struct nls_table *nls_codepage, int remap_special_chars); +extern int cifs_do_set_acl (const unsigned int xid,struct cifs_tcon *tcon, +const unsigned char *fileName, +const struct posix_acl *acl,const int acl_type, +const struct nls_table *nls_codepage,int remap);extern int CIFSGetExtAttr (const unsigned int xid,struct cifs_tcon *tcon,const int netfid,__u64 *pExtAttrBits,__u64 *pMask);#endif /* CIFS_ALLOW_INSECURE_LEGACY */
fs/cifs/cifssmb.c +160 -0
178 lines not on this page · raw message
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 10/30 security: add set acl hook
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
In the next patches we implement the hooks for the few security modules that do actually have restrictions on posix acls.
---
Notes:
/* v2 */
unchangedinclude/linux/lsm_hook_defs.h | 2 ++ include/linux/lsm_hooks.h | 4 ++++ include/linux/security.h | 11 +++++++++++ security/security.c | 9 +++++++++ 4 files changed, 26 insertions(+)
include/linux/lsm_hook_defs.h +2 -0
@@ -145,6 +145,8 @@ LSM_HOOK(int, 0, inode_getxattr, struct dentry *dentry, const char *name) LSM_HOOK(int, 0, inode_listxattr, struct dentry *dentry) LSM_HOOK(int, 0, inode_removexattr, struct user_namespace *mnt_userns, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_set_acl, struct user_namespace *mnt_userns, + struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(int, 0, inode_need_killpriv, struct dentry *dentry) LSM_HOOK(int, 0, inode_killpriv, struct user_namespace *mnt_userns, struct dentry *dentry)
include/linux/lsm_hooks.h +4 -0
@@ -435,6 +435,10 @@* Check permission before removing the extended attribute * identified by @name for @dentry. * Return 0 if permission is granted. +* @inode_set_acl: +* Check permission before setting the posix acls +* The posix acls in @kacl are identified by @acl_name. +* Return 0 if permission is granted. * @inode_getsecurity: * Retrieve a copy of the extended attribute representation of the * security label associated with @name for @inode via @buffer. Note that
include/linux/security.h +11 -0
@@ -359,6 +359,9 @@ int security_inode_getattr(const struct path *path);int security_inode_setxattr (struct user_namespace *mnt_userns,struct dentry *dentry,const char *name,const void *value,size_t size,int flags); +int security_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl);void security_inode_post_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags);int security_inode_getxattr (struct dentry *dentry,const char *name);
@@ -869,6 +872,14 @@ static inline int security_inode_setxattr(struct user_namespace *mnt_userns,return cap_inode_setxattr (dentry, name, value, size, flags); } +static inline int security_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry, +const char *acl_name, +struct posix_acl *kacl) +{ +return 0 ; +} +static inline void security_inode_post_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags) { }
security/security.c +9 -0
@@ -1370,6 +1370,15 @@ int security_inode_setxattr(struct user_namespace *mnt_userns,return evm_inode_setxattr (mnt_userns, dentry, name, value, size); } +int security_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl) +{ +if (unlikely (IS_PRIVATE (d_backing_inode (dentry)))) +return 0 ; +return call_int_hook (inode_set_acl,0 , mnt_userns, dentry, acl_name, kacl); +} +void security_inode_post_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags) {
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 5/30 cifs: implement get acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
So far cifs wasn't able to implement get and set acl inode operations because it needs access to the dentry. Now that we extended the set acl inode operation to take a dentry argument and added a new get acl inode operation that takes a dentry argument we can let cifs implement get and set acl inode operations.
This is mostly a copy and paste of the codepaths currently used in cifs' posix acl xattr handler. After we have fully implemented the posix acl api and switched the vfs over to it, the cifs specific posix acl xattr handler and associated code will be removed and the code duplication will go away.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
Christian Brauner (Microsoft) <[email protected]>:
- Surface acl error in all cases.
fs/cifs/cifsacl.c | 67 +++++++++++++++ fs/cifs/cifsfs.c | 2 + fs/cifs/cifsproto.h | 6 ++ fs/cifs/cifssmb.c | 196 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 271 insertions(+)
fs/cifs/cifsacl.c +67 -0
@@ -13,6 +13,7 @@#include <linux/string.h> #include <linux/keyctl.h> #include <linux/key-type.h> +#include <uapi/linux/posix_acl.h> #include <keys/user-type.h> #include "cifspdu.h" #include "cifsglob.h"
@@ -20,6 +21,8 @@#include "cifsproto.h" #include "cifs_debug.h" #include "fs_context.h" +#include "cifs_fs_sb.h" +#include "cifs_unicode.h" /* security id for everyone/world system group */ static const struct cifs_sid sid_everyone = {
@@ -1668,3 +1671,67 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,kfree (pntsd);return rc; } + +struct posix_acl *cifs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,int type) +{ +#if defined(CONFIG_CIFS_ALLOW_INSECURE_LEGACY ) && defined(CONFIG_CIFS_POSIX ) +struct posix_acl *acl =NULL ; +ssize_t rc = -EOPNOTSUPP ; +unsigned int xid; +struct super_block *sb = dentry->d_sb; +struct cifs_sb_info *cifs_sb =CIFS_SB (sb); +struct tcon_link *tlink; +struct cifs_tcon *pTcon; +const char *full_path; +void *page; + + tlink =cifs_sb_tlink (cifs_sb); +if (IS_ERR (tlink)) +return ERR_CAST (tlink); + pTcon =tlink_tcon (tlink); + + xid =get_xid (); + page =alloc_dentry_path (); + + full_path =build_path_from_dentry (dentry, page); +if (IS_ERR (full_path)) { + acl =ERR_CAST (full_path); + goto out; + } + +/* return alt name if available as pseudo attr */ +switch (type) { +case ACL_TYPE_ACCESS : +if (sb->s_flags &SB_POSIXACL ) + rc =cifs_do_get_acl (xid, pTcon, full_path, &acl, +ACL_TYPE_ACCESS , + cifs_sb->local_nls, +cifs_remap (cifs_sb)); +break ; + +case ACL_TYPE_DEFAULT : +if (sb->s_flags &SB_POSIXACL ) + rc =cifs_do_get_acl (xid, pTcon, full_path, &acl, +ACL_TYPE_DEFAULT , + cifs_sb->local_nls, +cifs_remap (cifs_sb)); +break ; + } + +if (rc <0 ) { +if (rc == -EINVAL ) + acl =ERR_PTR (-EOPNOTSUPP ); +else + acl =ERR_PTR (rc); + } + +out: +free_dentry_path (page); +free_xid (xid); +cifs_put_tlink (tlink); +return acl; +#else +return ERR_PTR (-EOPNOTSUPP ); +#endif +}
fs/cifs/cifsfs.c +2 -0
@@ -1128,6 +1128,7 @@ const struct inode_operations cifs_dir_inode_ops = { .symlink = cifs_symlink, .mknod = cifs_mknod, .listxattr = cifs_listxattr, + .get_acl = cifs_get_acl, };const struct inode_operations cifs_file_inode_ops = {
@@ -1136,6 +1137,7 @@ const struct inode_operations cifs_file_inode_ops = { .permission = cifs_permission, .listxattr = cifs_listxattr, .fiemap = cifs_fiemap, + .get_acl = cifs_get_acl, };const struct inode_operations cifs_symlink_inode_ops = {
fs/cifs/cifsproto.h +6 -0
@@ -225,6 +225,8 @@ extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *, const char *, u32 *, u32);extern struct cifs_ntsd *get_cifs_acl_by_fid (struct cifs_sb_info *,const struct cifs_fid *,u32 *,u32 ); +extern struct posix_acl *cifs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,int type);extern int set_cifs_acl (struct cifs_ntsd *,__u32 ,struct inode *,const char *,int );extern unsigned int setup_authusers_ACE (struct cifs_ace *pace);
@@ -542,6 +544,10 @@ extern int CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon,const unsigned char *searchName, char *acl_inf, const int buflen, const int acl_type, const struct nls_table *nls_codepage, int remap_special_chars); +extern int cifs_do_get_acl (const unsigned int xid,struct cifs_tcon *tcon, +const unsigned char *searchName, +struct posix_acl **acl,const int acl_type, +const struct nls_table *nls_codepage,int remap); extern int CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, const unsigned char *fileName, const char *local_acl, const int buflen, const int acl_type,
fs/cifs/cifssmb.c +196 -0
202 lines not on this page · raw message
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 9/30 acl: add vfs_set_acl()
In reply to Christian BraunerIn previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new vfs_set_acl() api that can be used to set posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.
After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
---
Notes:
/* v2 */
unchangedfs/posix_acl.c | 107 ++++++++++++++++++++++++++++++++++++++ fs/xattr.c | 5 +- include/linux/posix_acl.h | 10 ++++ include/linux/xattr.h | 2 + 4 files changed, 121 insertions(+), 3 deletions(-)
fs/posix_acl.c +107 -0
@@ -24,6 +24,7 @@#include <linux/user_namespace.h> #include <linux/namei.h> #include <linux/mnt_idmapping.h> +#include <linux/fsnotify.h> static struct posix_acl **acl_by_type (struct inode *inode,int type) {
@@ -1254,3 +1255,109 @@ int simple_acl_create(struct inode *dir, struct inode *inode)posix_acl_release (acl);return 0 ; } + +static inline int posix_acl_type (const char *name) +{ +if (strcmp (name,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) +return ACL_TYPE_ACCESS ; +else if (strcmp (name,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 ) +return ACL_TYPE_DEFAULT ; + +return -1 ; +} + +static int vfs_set_acl_idmapped_mnt (struct user_namespace *mnt_userns, +struct user_namespace *fs_userns, +struct posix_acl *acl) +{ +for (int n =0 ; n < acl->a_count; n++) { +struct posix_acl_entry *acl_e = &acl->a_entries[n]; + +switch (acl_e->e_tag) { +case ACL_USER : + acl_e->e_uid =from_vfsuid (mnt_userns, fs_userns, +VFSUIDT_INIT (acl_e->e_uid)); +break ; +case ACL_GROUP : + acl_e->e_gid =from_vfsgid (mnt_userns, fs_userns, +VFSGIDT_INIT (acl_e->e_gid)); +break ; + } + } + +return 0 ; +} + +/** +* vfs_set_acl - set posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to set the posix acls +* @acl_name: the name of the posix acl +* @kacl: the posix acls in the appropriate VFS format +* +* This function sets @kacl. The caller must all posix_acl_release() on @kacl +* afterwards. +* +* Return: On success 0, on error negative errno. +*/ +int vfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +const char *acl_name,struct posix_acl *kacl) +{ +int acl_type; +int error; +struct inode *inode =d_inode (dentry); +struct inode *delegated_inode =NULL ; + + acl_type =posix_acl_type (acl_name); +if (acl_type <0 ) +return -EINVAL ; + +if (kacl) { +/* +* If we're on an idmapped mount translate from mount specific +* vfs{g,u}id_t into global filesystem k{g,u}id_t. +* Afterwards we can cache the POSIX ACLs filesystem wide and - +* if this is a filesystem with a backing store - ultimately +* translate them to backing store values. +*/ + error =vfs_set_acl_idmapped_mnt (mnt_userns,i_user_ns (inode), kacl); +if (error) +return error; + } + +retry_deleg: +inode_lock (inode); + +/* +* We only care about restrictions the inode struct itself places upon +* us otherwise POSIX ACLs aren't subject to any VFS restrictions. +*/ + error =xattr_permission (mnt_userns, inode, acl_name,MAY_WRITE ); +if (error) + goto out_inode_unlock; + + error =try_break_deleg (inode, &delegated_inode); +if (error) + goto out_inode_unlock; + +if (inode->i_opflags &IOP_XATTR ) + error =set_posix_acl (mnt_userns, dentry, acl_type, kacl); +else if (unlikely (is_bad_inode (inode))) + error = -EIO ; +else + error = -EOPNOTSUPP ; +if (!error) +fsnotify_xattr (dentry); + +out_inode_unlock: +inode_unlock (inode); + +if (delegated_inode) { + error =break_deleg_wait (&delegated_inode); +if (!error) + goto retry_deleg; + } + +return error; +} +EXPORT_SYMBOL (vfs_set_acl);
fs/xattr.c +2 -3
@@ -84,9 +84,8 @@ xattr_resolve_name(struct inode *inode, const char **name)* Check permissions for extended attribute access. This is a bit complicated * because different namespaces have very different rules. */ -static int -xattr_permission (struct user_namespace *mnt_userns,struct inode *inode, -const char *name,int mask) +int xattr_permission (struct user_namespace *mnt_userns,struct inode *inode, +const char *name,int mask) {/* * We can never set or remove an extended attribute on a read-only
include/linux/posix_acl.h +10 -0
@@ -99,6 +99,9 @@ static inline void cache_no_acl(struct inode *inode) inode->i_acl =NULL ; inode->i_default_acl = NULL; } + +int vfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +const char *acl_name,struct posix_acl *kacl);#else static inline int posix_acl_chmod (struct user_namespace *mnt_userns,struct dentry *dentry,umode_t mode)
@@ -126,6 +129,13 @@ static inline int posix_acl_create(struct inode *inode, umode_t *mode,static inline void forget_all_cached_acls (struct inode *inode) { } + +static inline int vfs_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name, +struct posix_acl *acl) +{ +return 0 ; +}#endif /* CONFIG_FS_POSIX_ACL */ struct posix_acl *get_acl (struct inode *inode,int type);
include/linux/xattr.h +2 -0
@@ -73,6 +73,8 @@ ssize_t vfs_getxattr_alloc(struct user_namespace *mnt_userns, char **xattr_value, size_t size, gfp_t flags);int xattr_supported_namespace (struct inode *inode,const char *prefix); +int xattr_permission (struct user_namespace *mnt_userns,struct inode *inode, +const char *name,int mask);static inline const char *xattr_prefix (const struct xattr_handler *handler) {
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 12/30 smack: implement set acl hook
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
I spent considerate time in the security module infrastructure and audited all codepaths. Smack has no restrictions based on the posix acl values passed through it. The capability hook doesn't need to be called either because it only has restrictions on security.* xattrs. So this all becomes a very simple hook for smack.
---
Notes:
/* v2 */
unchangedsecurity/smack/smack_lsm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
security/smack/smack_lsm.c +24 -0
@@ -1393,6 +1393,29 @@ static int smack_inode_removexattr(struct user_namespace *mnt_userns,return 0 ; } +/** +* smack_inode_set_acl - Smack check for setting posix acls +* @mnt_userns: the userns attached to the mnt this request came from +* @dentry: the object +* @acl_name: name of the posix acl +* @kacl: the posix acls +* +* Returns 0 if access is permitted, an error code otherwise +*/ +static int smack_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl) +{ +struct smk_audit_info ad; +int rc; + +smk_ad_init (&ad, __func__,LSM_AUDIT_DATA_DENTRY ); +smk_ad_setfield_u_fs_path_dentry (&ad, dentry); + rc =smk_curacc (smk_of_inode (d_backing_inode (dentry)),MAY_WRITE , &ad); + rc =smk_bu_inode (d_backing_inode (dentry),MAY_WRITE , rc); +return rc; +} +/** * smack_inode_getsecurity - get smack xattrs * @mnt_userns: active user namespace
@@ -4772,6 +4795,7 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (inode_post_setxattr, smack_inode_post_setxattr),LSM_HOOK_INIT (inode_getxattr, smack_inode_getxattr),LSM_HOOK_INIT (inode_removexattr, smack_inode_removexattr), +LSM_HOOK_INIT (inode_set_acl, smack_inode_set_acl),LSM_HOOK_INIT (inode_getsecurity, smack_inode_getsecurity),LSM_HOOK_INIT (inode_setsecurity, smack_inode_setsecurity), LSM_HOOK_INIT(inode_listsecurity, smack_inode_listsecurity),
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 11/30 selinux: implement set acl hook
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
I spent considerate time in the security module infrastructure and audited all codepaths. SELinux has no restrictions based on the posix acl values passed through it. The capability hook doesn't need to be called either because it only has restrictions on security.* xattrs. So this all becomes a very simple hook for SELinux.
---
Notes:
/* v2 */
unchangedsecurity/selinux/hooks.c | 8 ++++++++ 1 file changed, 8 insertions(+)
security/selinux/hooks.c +8 -0
@@ -3239,6 +3239,13 @@ static int selinux_inode_setxattr(struct user_namespace *mnt_userns, &ad); } +static int selinux_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl) +{ +return dentry_has_perm (current_cred (), dentry,FILE__SETATTR ); +} +static void selinux_inode_post_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags)
@@ -7063,6 +7070,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (inode_getxattr, selinux_inode_getxattr),LSM_HOOK_INIT (inode_listxattr, selinux_inode_listxattr),LSM_HOOK_INIT (inode_removexattr, selinux_inode_removexattr), +LSM_HOOK_INIT (inode_set_acl, selinux_inode_set_acl),LSM_HOOK_INIT (inode_getsecurity, selinux_inode_getsecurity),LSM_HOOK_INIT (inode_setsecurity, selinux_inode_setsecurity), LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity),
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 13/30 evm: implement set acl hook
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
I spent considerate time in the security module and integrity infrastructure and audited all codepaths. EVM is the only part that really has restrictions based on the actual posix acl values passed through it. Before this dedicated hook EVM used to translate from the uapi posix acl format sent to it in the form of a void pointer into the vfs format. This is not a good thing. Instead of hacking around in the uapi struct give EVM the posix acls in the appropriate vfs format and perform sane permissions checks that mirror what it used to to in the generic xattr hook.
---
Notes:
/* v2 */
unchangedinclude/linux/evm.h | 10 +++++ security/integrity/evm/evm_main.c | 66 ++++++++++++++++++++++++++++++- security/security.c | 9 ++++- 3 files changed, 83 insertions(+), 2 deletions(-)
include/linux/evm.h +10 -0
@@ -35,6 +35,9 @@ extern int evm_inode_removexattr(struct user_namespace *mnt_userns, struct dentry *dentry, const char *xattr_name);extern void evm_inode_post_removexattr (struct dentry *dentry,const char *xattr_name); +extern int evm_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl);extern int evm_inode_init_security (struct inode *inode,const struct xattr *xattr_array,struct xattr *evm);
@@ -108,6 +111,13 @@ static inline void evm_inode_post_removexattr(struct dentry *dentry,return ; } +static inline int evm_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl) +{ +return 0 ; +} +static inline int evm_inode_init_security (struct inode *inode,const struct xattr *xattr_array,struct xattr *evm)
security/integrity/evm/evm_main.c +65 -1
78 lines not on this page · raw message
security/security.c +8 -1
@@ -1374,9 +1374,16 @@ int security_inode_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) { + int ret; +if (unlikely (IS_PRIVATE (d_backing_inode (dentry))))return 0 ; - return call_int_hook(inode_set_acl, 0, mnt_userns, dentry, acl_name, kacl); + + ret =call_int_hook (inode_set_acl,0 , mnt_userns, dentry, acl_name, kacl); +if (ret) +return ret; + +return evm_inode_set_acl (mnt_userns, dentry, acl_name, kacl); } void security_inode_post_setxattr(struct dentry *dentry, const char *name,
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 8/30 9p: implement set acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
So far 9p implemented a ->get_inode_acl() operation that didn't require access to the dentry in order to allow (limited) permission checking via posix acls in the vfs. Now that we have get and set acl inode operations that take a dentry argument we can give 9p get and set acl inode operations.
This is mostly a light refactoring of the codepaths currently used in 9p posix acl xattr handler. After we have fully implemented the posix acl api and switched the vfs over to it, the 9p specific posix acl xattr handler and associated code will be removed.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
Al Viro <[email protected]>:
- Fix leak due to early return instead of goto.
Christian Brauner (Microsoft) <[email protected]>:
- Fix leak and call kfree() when we skip setting posix acls because acl can be represented by mode bits.
fs/9p/acl.c | 94 ++++++++++++++++++++++++++++++++++++++++++ fs/9p/acl.h | 3 ++ fs/9p/vfs_inode_dotl.c | 2 + 3 files changed, 99 insertions(+)
fs/9p/acl.c +94 -0
@@ -151,6 +151,100 @@ struct posix_acl *v9fs_iop_get_acl(struct user_namespace *mnt_userns,return v9fs_get_cached_acl (d_inode (dentry), type); } +int v9fs_iop_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +struct posix_acl *acl,int type) +{ +int retval; +size_t size =0 ; +void *value =NULL ; +const char *acl_name; +struct v9fs_session_info *v9ses; +struct inode *inode =d_inode (dentry); + +if (acl) { + retval =posix_acl_valid (inode->i_sb->s_user_ns, acl); +if (retval) + goto err_out; + + size =posix_acl_xattr_size (acl->a_count); + + value =kzalloc (size,GFP_NOFS ); +if (!value) { + retval = -ENOMEM ; + goto err_out; + } + + retval =posix_acl_to_xattr (&init_user_ns, acl, value, size); +if (retval <0 ) + goto err_out; + } + +/* +* set the attribute on the remote. Without even looking at the +* xattr value. We leave it to the server to validate +*/ + acl_name =posix_acl_xattr_name (type); + v9ses =v9fs_dentry2v9ses (dentry); +if ((v9ses->flags &V9FS_ACCESS_MASK ) !=V9FS_ACCESS_CLIENT ) { + retval =v9fs_xattr_set (dentry, acl_name, value, size,0 ); + goto err_out; + } + +if (S_ISLNK (inode->i_mode)) { + retval = -EOPNOTSUPP ; + goto err_out; + } + +if (!inode_owner_or_capable (&init_user_ns, inode)) { + retval = -EPERM ; + goto err_out; + } + +switch (type) { +case ACL_TYPE_ACCESS : +if (acl) { +struct iattr iattr = {}; +struct posix_acl *acl_mode = acl; + + retval =posix_acl_update_mode (&init_user_ns, inode, + &iattr.ia_mode, + &acl_mode); +if (retval) + goto err_out; +if (!acl_mode) { +/* +* ACL can be represented by the mode bits. +* So don't update ACL below. +*/ +kfree (value); + value =NULL ; + size =0 ; + } + iattr.ia_valid =ATTR_MODE ; +/* +* FIXME should we update ctime ? +* What is the following setxattr update the mode ? +*/ +v9fs_vfs_setattr_dotl (&init_user_ns, dentry, &iattr); + } +break ; +case ACL_TYPE_DEFAULT : +if (!S_ISDIR (inode->i_mode)) { + retval = acl ? -EINVAL :0 ; + goto err_out; + } +break ; + } + + retval =v9fs_xattr_set (dentry, acl_name, value, size,0 ); +if (!retval) +set_cached_acl (inode, type, acl); + +err_out: +kfree (value); +return retval; +} +static int v9fs_set_acl (struct p9_fid *fid,int type,struct posix_acl *acl) {int retval;
fs/9p/acl.h +3 -0
@@ -12,6 +12,8 @@ struct posix_acl *v9fs_iop_get_inode_acl(struct inode *inode, int type, bool rcu);struct posix_acl *v9fs_iop_get_acl (struct user_namespace *mnt_userns,struct dentry *dentry,int type); +int v9fs_iop_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +struct posix_acl *acl,int type);int v9fs_acl_chmod (struct inode *inode,struct p9_fid *fid);int v9fs_set_create_acl (struct inode *inode,struct p9_fid *fid,struct posix_acl *dacl,struct posix_acl *acl);
@@ -21,6 +23,7 @@ void v9fs_put_acl(struct posix_acl *dacl, struct posix_acl *acl);#else #define v9fs_iop_get_inode_acl NULL#define v9fs_iop_get_acl NULL +#define v9fs_iop_set_acl NULLstatic inline int v9fs_get_acl (struct inode *inode,struct p9_fid *fid) {return 0 ;
fs/9p/vfs_inode_dotl.c +2 -0
@@ -985,6 +985,7 @@ const struct inode_operations v9fs_dir_inode_operations_dotl = { .listxattr = v9fs_listxattr, .get_inode_acl = v9fs_iop_get_inode_acl, .get_acl = v9fs_iop_get_acl, + .set_acl = v9fs_iop_set_acl, };const struct inode_operations v9fs_file_inode_operations_dotl = {
@@ -993,6 +994,7 @@ const struct inode_operations v9fs_file_inode_operations_dotl = { .listxattr = v9fs_listxattr, .get_inode_acl = v9fs_iop_get_inode_acl, .get_acl = v9fs_iop_get_acl, + .set_acl = v9fs_iop_set_acl, };const struct inode_operations v9fs_symlink_inode_operations_dotl = {
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 14/30 acl: use set acl hook
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs.
Now that we have a proper security hook for setting posix acls that passes down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format make use of it in the new posix acl api.
---
Notes:
/* v2 */
unchangedfs/posix_acl.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/posix_acl.c +5 -0
@@ -24,6 +24,7 @@#include <linux/user_namespace.h> #include <linux/namei.h> #include <linux/mnt_idmapping.h> +#include <linux/security.h> #include <linux/fsnotify.h> static struct posix_acl **acl_by_type (struct inode *inode,int type)
@@ -1336,6 +1337,10 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,if (error) goto out_inode_unlock; + error =security_inode_set_acl (mnt_userns, dentry, acl_name, kacl); +if (error) + goto out_inode_unlock; + error =try_break_deleg (inode, &delegated_inode);if (error) goto out_inode_unlock;
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 15/30 evm: add post set acl hook
In reply to Christian BraunerThe security_inode_post_setxattr() hook is used by security modules to update their own security.* xattrs. Consequently none of the security modules operate on posix acls. So we don't need an additional security hook when post setting posix acls.
However, the integrity subsystem wants to be informed about posix acl changes and specifically evm to update their hashes when the xattrs change. The callchain for evm_inode_post_setxattr() is:
-> evm_inode_post_setxattr()
-> evm_update_evmxattr()
-> evm_calc_hmac()
-> evm_calc_hmac_or_hash()and evm_cacl_hmac_or_hash() walks the global list of protected xattr names evm_config_xattrnames. This global list can be modified via /sys/security/integrity/evm/evm_xattrs. The write to "evm_xattrs" is restricted to security.* xattrs and the default xattrs in evm_config_xattrnames only contains security.* xattrs as well.
So the actual value for posix acls is currently completely irrelevant for evm during evm_inode_post_setxattr() and frankly it should stay that way in the future to not cause the vfs any more headaches. But if the actual posix acl values matter then evm shouldn't operate on the binary void blob and try to hack around in the uapi struct anyway. Instead it should then in the future add a dedicated hook which takes a struct posix_acl argument passing the posix acls in the proper vfs format.
For now it is sufficient to make evm_inode_post_set_acl() a wrapper around evm_inode_post_setxattr() not passing any actual values down. This will still cause the hashes to be updated as before.
---
Notes:
/* v2 */
unchangedfs/posix_acl.c | 5 ++++- include/linux/evm.h | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
fs/posix_acl.c +4 -1
@@ -25,6 +25,7 @@#include <linux/namei.h> #include <linux/mnt_idmapping.h> #include <linux/security.h> +#include <linux/evm.h> #include <linux/fsnotify.h> static struct posix_acl **acl_by_type (struct inode *inode,int type)
@@ -1351,8 +1352,10 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, error = -EIO ; else error = -EOPNOTSUPP ; -if (!error) +if (!error) {fsnotify_xattr (dentry); +evm_inode_post_set_acl (dentry, acl_name, kacl); + } out_inode_unlock:inode_unlock (inode);
include/linux/evm.h +13 -0
@@ -38,6 +38,12 @@ extern void evm_inode_post_removexattr(struct dentry *dentry,extern int evm_inode_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,const char *acl_name,struct posix_acl *kacl); +static inline void evm_inode_post_set_acl (struct dentry *dentry, +const char *acl_name, +struct posix_acl *kacl) +{ +return evm_inode_post_setxattr (dentry, acl_name,NULL ,0 ); +}extern int evm_inode_init_security (struct inode *inode,const struct xattr *xattr_array,struct xattr *evm);
@@ -118,6 +124,13 @@ static inline int evm_inode_set_acl(struct user_namespace *mnt_userns,return 0 ; } +static inline void evm_inode_post_set_acl (struct dentry *dentry, +const char *acl_name, +struct posix_acl *kacl) +{ +return ; +} +static inline int evm_inode_init_security (struct inode *inode,const struct xattr *xattr_array,struct xattr *evm)
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 2/30 fs: pass dentry to set acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
Since some filesystem rely on the dentry being available to them when setting posix acls (e.g., 9p and cifs) they cannot rely on set acl inode operation. But since ->set_acl() is required in order to use the generic posix acl xattr handlers filesystems that do not implement this inode operation cannot use the handler and need to implement their own dedicated posix acl handlers.
Update the ->set_acl() inode method to take a dentry argument. This allows all filesystems to rely on ->set_acl().
As far as I can tell all codepaths can be switched to rely on the dentry instead of just the inode. Note that the original motivation for passing the dentry separate from the inode instead of just the dentry in the xattr handlers was because of security modules that call security_d_instantiate(). This hook is called during d_instantiate_new(), d_add(), __d_instantiate_anon(), and d_splice_alias() to initialize the inode's security context and possibly to set security.* xattrs. Since this only affects security.* xattrs this is completely irrelevant for posix acls.
---
Notes:
/* v2 */
Christoph Hellwig <[email protected]>:
- Split orangefs into a preparatory patch.
fs/bad_inode.c | 2 +- fs/btrfs/acl.c | 3 ++- fs/btrfs/ctree.h | 2 +- fs/btrfs/inode.c | 2 +- fs/ceph/acl.c | 3 ++- fs/ceph/inode.c | 2 +- fs/ceph/super.h | 2 +- fs/ext2/acl.c | 3 ++- fs/ext2/acl.h | 2 +- fs/ext2/inode.c | 2 +- fs/ext4/acl.c | 3 ++- fs/ext4/acl.h | 2 +- fs/ext4/inode.c | 2 +- fs/f2fs/acl.c | 4 +++- fs/f2fs/acl.h | 2 +- fs/f2fs/file.c | 2 +- fs/fuse/acl.c | 3 ++- fs/fuse/fuse_i.h | 2 +- fs/gfs2/acl.c | 3 ++- fs/gfs2/acl.h | 2 +- fs/gfs2/inode.c | 2 +- fs/jffs2/acl.c | 3 ++- fs/jffs2/acl.h | 2 +- fs/jffs2/fs.c | 2 +- fs/jfs/acl.c | 3 ++- fs/jfs/file.c | 2 +- fs/jfs/jfs_acl.h | 2 +- fs/ksmbd/smb2pdu.c | 4 ++-- fs/ksmbd/smbacl.c | 4 ++-- fs/ksmbd/vfs.c | 15 ++++++++------- fs/ksmbd/vfs.h | 4 ++-- fs/nfs/nfs3_fs.h | 2 +- fs/nfs/nfs3acl.c | 3 ++- fs/nfsd/nfs2acl.c | 4 ++-- fs/nfsd/nfs3acl.c | 4 ++-- fs/nfsd/vfs.c | 4 ++-- fs/ntfs3/file.c | 2 +- fs/ntfs3/ntfs_fs.h | 4 ++-- fs/ntfs3/xattr.c | 9 +++++---- fs/ocfs2/acl.c | 3 ++- fs/ocfs2/acl.h | 2 +- fs/orangefs/acl.c | 5 +++-- fs/orangefs/inode.c | 7 ++++--- fs/orangefs/orangefs-kernel.h | 4 ++-- fs/posix_acl.c | 18 +++++++++++------- fs/reiserfs/acl.h | 6 +++--- fs/reiserfs/inode.c | 2 +- fs/reiserfs/xattr_acl.c | 9 ++++++--- fs/xfs/xfs_acl.c | 3 ++- fs/xfs/xfs_acl.h | 2 +- fs/xfs/xfs_iops.c | 10 ++++++---- include/linux/fs.h | 2 +- include/linux/posix_acl.h | 12 ++++++------ mm/shmem.c | 2 +- 54 files changed, 118 insertions(+), 92 deletions(-)
fs/bad_inode.c +1 -1
@@ -154,7 +154,7 @@ static int bad_inode_tmpfile(struct user_namespace *mnt_userns, }static int bad_inode_set_acl (struct user_namespace *mnt_userns, -struct inode *inode,struct posix_acl *acl, +struct dentry *dentry,struct posix_acl *acl,int type) {return -EIO ;
fs/btrfs/acl.c +2 -1
@@ -110,10 +110,11 @@ int __btrfs_set_acl(struct btrfs_trans_handle *trans, struct inode *inode,return ret; } -int btrfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int btrfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int ret; +struct inode *inode =d_inode (dentry);umode_t old_mode = inode->i_mode;if (type ==ACL_TYPE_ACCESS && acl) {
fs/btrfs/ctree.h +1 -1
@@ -3941,7 +3941,7 @@ static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)/* acl.c */ #ifdef CONFIG_BTRFS_FS_POSIX_ACL struct posix_acl *btrfs_get_acl (struct inode *inode,int type,bool rcu); -int btrfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int btrfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);int __btrfs_set_acl (struct btrfs_trans_handle *trans,struct inode *inode,struct posix_acl *acl,int type);
fs/btrfs/inode.c +1 -1
@@ -5262,7 +5262,7 @@ static int btrfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentr err =btrfs_dirty_inode (inode);if (!err && attr->ia_valid &ATTR_MODE ) - err =posix_acl_chmod (mnt_userns, inode, inode->i_mode); + err =posix_acl_chmod (mnt_userns, dentry, inode->i_mode); }return err;
fs/ceph/acl.c +2 -1
@@ -85,13 +85,14 @@ struct posix_acl *ceph_get_acl(struct inode *inode, int type, bool rcu)return acl; } -int ceph_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int ceph_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int ret =0 , size =0 ;const char *name =NULL ;char *value =NULL ;struct iattr newattrs; +struct inode *inode =d_inode (dentry);struct timespec64 old_ctime = inode->i_ctime;umode_t new_mode = inode->i_mode, old_mode = inode->i_mode;
fs/ceph/inode.c +1 -1
@@ -2254,7 +2254,7 @@ int ceph_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, err =__ceph_setattr (inode, attr);if (err >=0 && (attr->ia_valid &ATTR_MODE )) - err =posix_acl_chmod (&init_user_ns, inode, attr->ia_mode); + err =posix_acl_chmod (&init_user_ns, dentry, attr->ia_mode);return err; }
fs/ceph/super.h +1 -1
@@ -1117,7 +1117,7 @@ void ceph_release_acl_sec_ctx(struct ceph_acl_sec_ctx *as_ctx);struct posix_acl *ceph_get_acl (struct inode *,int ,bool );int ceph_set_acl (struct user_namespace *mnt_userns, -struct inode *inode,struct posix_acl *acl,int type); +struct dentry *dentry,struct posix_acl *acl,int type);int ceph_pre_init_acls (struct inode *dir,umode_t *mode,struct ceph_acl_sec_ctx *as_ctx); void ceph_init_inode_acls(struct inode *inode,
fs/ext2/acl.c +2 -1
@@ -219,11 +219,12 @@ __ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)* inode->i_mutex: down */ int -ext2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +ext2_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int error;int update_mode =0 ; +struct inode *inode =d_inode (dentry);umode_t mode = inode->i_mode;if (type ==ACL_TYPE_ACCESS && acl) {
fs/ext2/acl.h +1 -1
@@ -56,7 +56,7 @@ static inline int ext2_acl_count(size_t size)/* acl.c */ extern struct posix_acl *ext2_get_acl (struct inode *inode,int type,bool rcu); -extern int ext2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +extern int ext2_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);extern int ext2_init_acl (struct inode *,struct inode *);
fs/ext2/inode.c +1 -1
@@ -1652,7 +1652,7 @@ int ext2_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, }setattr_copy (&init_user_ns, inode, iattr);if (iattr->ia_valid &ATTR_MODE ) - error =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); + error =posix_acl_chmod (&init_user_ns, dentry, inode->i_mode);mark_inode_dirty (inode);return error;
fs/ext4/acl.c +2 -1
@@ -225,12 +225,13 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type, }int -ext4_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +ext4_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {handle_t *handle;int error, credits, retries =0 ;size_t acl_size = acl ?ext4_acl_size (acl->a_count) :0 ; +struct inode *inode =d_inode (dentry);umode_t mode = inode->i_mode;int update_mode =0 ;
fs/ext4/acl.h +1 -1
@@ -56,7 +56,7 @@ static inline int ext4_acl_count(size_t size)/* acl.c */ struct posix_acl *ext4_get_acl (struct inode *inode,int type,bool rcu); -int ext4_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int ext4_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);extern int ext4_init_acl (handle_t *,struct inode *,struct inode *);
fs/ext4/inode.c +1 -1
@@ -5540,7 +5540,7 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,ext4_orphan_del (NULL , inode);if (!error && (ia_valid &ATTR_MODE )) - rc =posix_acl_chmod (mnt_userns, inode, inode->i_mode); + rc =posix_acl_chmod (mnt_userns, dentry, inode->i_mode); err_out:if (error)
fs/f2fs/acl.c +3 -1
@@ -276,9 +276,11 @@ static int __f2fs_set_acl(struct user_namespace *mnt_userns,return error; } -int f2fs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int f2fs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) { +struct inode *inode =d_inode (dentry); +if (unlikely (f2fs_cp_error (F2FS_I_SB (inode))))return -EIO ;
fs/f2fs/acl.h +1 -1
@@ -34,7 +34,7 @@ struct f2fs_acl_header {#ifdef CONFIG_F2FS_FS_POSIX_ACL extern struct posix_acl *f2fs_get_acl (struct inode *,int ,bool ); -extern int f2fs_set_acl (struct user_namespace *,struct inode *, +extern int f2fs_set_acl (struct user_namespace *,struct dentry *,struct posix_acl *,int );extern int f2fs_init_acl (struct inode *,struct inode *,struct page *,struct page *);
fs/f2fs/file.c +1 -1
@@ -978,7 +978,7 @@ int f2fs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,__setattr_copy (mnt_userns, inode, attr);if (attr->ia_valid &ATTR_MODE ) { - err =posix_acl_chmod (mnt_userns, inode,f2fs_get_inode_mode (inode)); + err =posix_acl_chmod (mnt_userns, dentry,f2fs_get_inode_mode (inode));if (is_inode_flag_set (inode,FI_ACL_MODE )) {if (!err)
fs/fuse/acl.c +2 -1
@@ -53,9 +53,10 @@ struct posix_acl *fuse_get_acl(struct inode *inode, int type, bool rcu)return acl; } -int fuse_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int fuse_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) { +struct inode *inode =d_inode (dentry);struct fuse_conn *fc =get_fuse_conn (inode);const char *name;int ret;
fs/fuse/fuse_i.h +1 -1
@@ -1266,7 +1266,7 @@ extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];struct posix_acl ;struct posix_acl *fuse_get_acl (struct inode *inode,int type,bool rcu); -int fuse_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int fuse_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);/* readdir.c */
fs/gfs2/acl.c +2 -1
@@ -109,9 +109,10 @@ int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)return error; } -int gfs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int gfs2_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) { +struct inode *inode =d_inode (dentry);struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_holder gh;bool need_unlock = false;
fs/gfs2/acl.h +1 -1
@@ -13,7 +13,7 @@extern struct posix_acl *gfs2_get_acl (struct inode *inode,int type,bool rcu);extern int __gfs2_set_acl (struct inode *inode,struct posix_acl *acl,int type); -extern int gfs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +extern int gfs2_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);#endif /* __ACL_DOT_H__ */
fs/gfs2/inode.c +1 -1
@@ -1990,7 +1990,7 @@ static int gfs2_setattr(struct user_namespace *mnt_userns,else { error =gfs2_setattr_simple (inode, attr);if (!error && attr->ia_valid &ATTR_MODE ) - error =posix_acl_chmod (&init_user_ns, inode, + error =posix_acl_chmod (&init_user_ns, dentry, inode->i_mode); }
fs/jffs2/acl.c +2 -1
@@ -229,10 +229,11 @@ static int __jffs2_set_acl(struct inode *inode, int xprefix, struct posix_acl *areturn rc; } -int jffs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int jffs2_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int rc, xprefix; +struct inode *inode =d_inode (dentry);switch (type) {case ACL_TYPE_ACCESS :
fs/jffs2/acl.h +1 -1
@@ -28,7 +28,7 @@ struct jffs2_acl_header {#ifdef CONFIG_JFFS2_FS_POSIX_ACL struct posix_acl *jffs2_get_acl (struct inode *inode,int type,bool rcu); -int jffs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int jffs2_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);extern int jffs2_init_acl_pre (struct inode *,struct inode *,umode_t *);extern int jffs2_init_acl_post (struct inode *);
fs/jffs2/fs.c +1 -1
@@ -202,7 +202,7 @@ int jffs2_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, rc =jffs2_do_setattr (inode, iattr);if (!rc && (iattr->ia_valid &ATTR_MODE )) - rc =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); + rc =posix_acl_chmod (&init_user_ns, dentry, inode->i_mode);return rc; }
fs/jfs/acl.c +2 -1
@@ -94,12 +94,13 @@ static int __jfs_set_acl(tid_t tid, struct inode *inode, int type,return rc; } -int jfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int jfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int rc;tid_t tid;int update_mode =0 ; +struct inode *inode =d_inode (dentry);umode_t mode = inode->i_mode; tid =txBegin (inode->i_sb,0 );
fs/jfs/file.c +1 -1
@@ -123,7 +123,7 @@ int jfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,mark_inode_dirty (inode);if (iattr->ia_valid &ATTR_MODE ) - rc =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); + rc =posix_acl_chmod (&init_user_ns, dentry, inode->i_mode);return rc; }
fs/jfs/jfs_acl.h +1 -1
@@ -8,7 +8,7 @@#ifdef CONFIG_JFS_POSIX_ACL struct posix_acl *jfs_get_acl (struct inode *inode,int type,bool rcu); -int jfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int jfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);int jfs_init_acl (tid_t ,struct inode *,struct inode *);
fs/ksmbd/smb2pdu.c +2 -2
@@ -2952,7 +2952,7 @@ int smb2_open(struct ksmbd_work *work)struct inode *inode =d_inode (path.dentry); posix_acl_rc =ksmbd_vfs_inherit_posix_acl (user_ns, - inode, + path.dentry,d_inode (path.dentry->d_parent));if (posix_acl_rc)ksmbd_debug (SMB ,"inherit posix acl failed : %d\n" , posix_acl_rc);
@@ -2968,7 +2968,7 @@ int smb2_open(struct ksmbd_work *work)if (rc) {if (posix_acl_rc)ksmbd_vfs_set_init_posix_acl (user_ns, - inode); + path.dentry);if (test_share_config_flag (work->tcon->share_conf,KSMBD_SHARE_FLAG_ACL_XATTR )) {
fs/ksmbd/smbacl.c +2 -2
@@ -1384,14 +1384,14 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,ksmbd_vfs_remove_acl_xattrs (user_ns, path->dentry);/* Update posix acls */ if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && fattr.cf_dacls) { - rc =set_posix_acl (user_ns, inode, + rc =set_posix_acl (user_ns, path->dentry,ACL_TYPE_ACCESS , fattr.cf_acls);if (rc <0 )ksmbd_debug (SMB ,"Set posix acl(ACL_TYPE_ACCESS) failed, rc : %d\n" , rc);if (S_ISDIR (inode->i_mode) && fattr.cf_dacls) { - rc =set_posix_acl (user_ns, inode, + rc =set_posix_acl (user_ns, path->dentry,ACL_TYPE_DEFAULT , fattr.cf_dacls);if (rc) ksmbd_debug(SMB,
fs/ksmbd/vfs.c +8 -7
@@ -1814,10 +1814,11 @@ void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock) }int ksmbd_vfs_set_init_posix_acl (struct user_namespace *user_ns, -struct inode *inode) +struct dentry *dentry) {struct posix_acl_state acl_state;struct posix_acl *acls; +struct inode *inode =d_inode (dentry);int rc;if (!IS_ENABLED (CONFIG_FS_POSIX_ACL ))
@@ -1846,14 +1847,13 @@ int ksmbd_vfs_set_init_posix_acl(struct user_namespace *user_ns,return -ENOMEM ; }posix_state_to_acl (&acl_state, acls->a_entries); - rc =set_posix_acl (user_ns, inode,ACL_TYPE_ACCESS , acls); + rc =set_posix_acl (user_ns, dentry,ACL_TYPE_ACCESS , acls);if (rc <0 )ksmbd_debug (SMB ,"Set posix acl(ACL_TYPE_ACCESS) failed, rc : %d\n" , rc);else if (S_ISDIR (inode->i_mode)) {posix_state_to_acl (&acl_state, acls->a_entries); - rc =set_posix_acl (user_ns, inode,ACL_TYPE_DEFAULT , - acls); + rc =set_posix_acl (user_ns, dentry,ACL_TYPE_DEFAULT , acls);if (rc <0 )ksmbd_debug (SMB ,"Set posix acl(ACL_TYPE_DEFAULT) failed, rc : %d\n" , rc);
@@ -1864,10 +1864,11 @@ int ksmbd_vfs_set_init_posix_acl(struct user_namespace *user_ns, }int ksmbd_vfs_inherit_posix_acl (struct user_namespace *user_ns, -struct inode *inode,struct inode *parent_inode) +struct dentry *dentry,struct inode *parent_inode) {struct posix_acl *acls;struct posix_acl_entry *pace; +struct inode *inode =d_inode (dentry);int rc, i;if (!IS_ENABLED (CONFIG_FS_POSIX_ACL ))
@@ -1885,12 +1886,12 @@ int ksmbd_vfs_inherit_posix_acl(struct user_namespace *user_ns, } } - rc =set_posix_acl (user_ns, inode,ACL_TYPE_ACCESS , acls); + rc =set_posix_acl (user_ns, dentry,ACL_TYPE_ACCESS , acls);if (rc <0 )ksmbd_debug (SMB ,"Set posix acl(ACL_TYPE_ACCESS) failed, rc : %d\n" , rc);if (S_ISDIR (inode->i_mode)) { - rc =set_posix_acl (user_ns, inode,ACL_TYPE_DEFAULT , + rc =set_posix_acl (user_ns, dentry,ACL_TYPE_DEFAULT , acls);if (rc <0 ) ksmbd_debug(SMB, "Set posix acl(ACL_TYPE_DEFAULT) failed, rc : %d\n",
fs/ksmbd/vfs.h +2 -2
@@ -158,8 +158,8 @@ int ksmbd_vfs_get_dos_attrib_xattr(struct user_namespace *user_ns,struct dentry *dentry, struct xattr_dos_attrib *da);int ksmbd_vfs_set_init_posix_acl (struct user_namespace *user_ns, -struct inode *inode); +struct dentry *dentry);int ksmbd_vfs_inherit_posix_acl (struct user_namespace *user_ns, -struct inode *inode, +struct dentry *dentry,struct inode *parent_inode);#endif /* __KSMBD_VFS_H__ */
fs/nfs/nfs3_fs.h +1 -1
@@ -12,7 +12,7 @@*/ #ifdef CONFIG_NFS_V3_ACL extern struct posix_acl *nfs3_get_acl (struct inode *inode,int type,bool rcu); -extern int nfs3_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +extern int nfs3_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);extern int nfs3_proc_setacls (struct inode *inode,struct posix_acl *acl,struct posix_acl *dfacl);
fs/nfs/nfs3acl.c +2 -1
@@ -255,10 +255,11 @@ int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl, } -int nfs3_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int nfs3_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {struct posix_acl *orig = acl, *dfacl =NULL , *alloc; +struct inode *inode =d_inode (dentry);int status;if (S_ISDIR (inode->i_mode)) {
fs/nfsd/nfs2acl.c +2 -2
@@ -113,11 +113,11 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)inode_lock (inode); - error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_ACCESS , + error =set_posix_acl (&init_user_ns, fh->fh_dentry,ACL_TYPE_ACCESS , argp->acl_access);if (error) goto out_drop_lock; - error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_DEFAULT , + error =set_posix_acl (&init_user_ns, fh->fh_dentry,ACL_TYPE_DEFAULT , argp->acl_default);if (error) goto out_drop_lock;
fs/nfsd/nfs3acl.c +2 -2
@@ -103,11 +103,11 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)inode_lock (inode); - error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_ACCESS , + error =set_posix_acl (&init_user_ns, fh->fh_dentry,ACL_TYPE_ACCESS , argp->acl_access);if (error) goto out_drop_lock; - error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_DEFAULT , + error =set_posix_acl (&init_user_ns, fh->fh_dentry,ACL_TYPE_DEFAULT , argp->acl_default); out_drop_lock:
fs/nfsd/vfs.c +2 -2
@@ -457,12 +457,12 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, attr->na_seclabel->data, attr->na_seclabel->len);if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && attr->na_pacl) attr->na_aclerr =set_posix_acl (&init_user_ns, - inode,ACL_TYPE_ACCESS , + dentry,ACL_TYPE_ACCESS , attr->na_pacl);if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && !attr->na_aclerr && attr->na_dpacl &&S_ISDIR (inode->i_mode)) attr->na_aclerr =set_posix_acl (&init_user_ns, - inode,ACL_TYPE_DEFAULT , + dentry,ACL_TYPE_DEFAULT , attr->na_dpacl);inode_unlock (inode);if (size_change)
fs/ntfs3/file.c +1 -1
@@ -802,7 +802,7 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,setattr_copy (mnt_userns, inode, attr);if (mode != inode->i_mode) { - err =ntfs_acl_chmod (mnt_userns, inode); + err =ntfs_acl_chmod (mnt_userns, dentry);if (err) goto out;
fs/ntfs3/ntfs_fs.h +2 -2
@@ -843,7 +843,7 @@ int ntfs_cmp_names_cpu(const struct cpu_str *uni1, const struct le_str *uni2,/* globals from xattr.c */ #ifdef CONFIG_NTFS3_FS_POSIX_ACL struct posix_acl *ntfs_get_acl (struct inode *inode,int type,bool rcu); -int ntfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int ntfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);int ntfs_init_acl (struct user_namespace *mnt_userns,struct inode *inode,struct inode *dir);
@@ -852,7 +852,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,#define ntfs_set_acl NULL#endif -int ntfs_acl_chmod (struct user_namespace *mnt_userns,struct inode *inode); +int ntfs_acl_chmod (struct user_namespace *mnt_userns,struct dentry *dentry);int ntfs_permission (struct user_namespace *mnt_userns,struct inode *inode,int mask);ssize_t ntfs_listxattr (struct dentry *dentry,char *buffer,size_t size);
fs/ntfs3/xattr.c +5 -4
@@ -619,10 +619,10 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,/* * ntfs_set_acl - inode_operations::set_acl */ -int ntfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int ntfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) { -return ntfs_set_acl_ex (mnt_userns, inode, acl, type, false); +return ntfs_set_acl_ex (mnt_userns,d_inode (dentry), acl, type, false); }/*
@@ -664,8 +664,9 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,/* * ntfs_acl_chmod - Helper for ntfs3_setattr(). */ -int ntfs_acl_chmod (struct user_namespace *mnt_userns,struct inode *inode) +int ntfs_acl_chmod (struct user_namespace *mnt_userns,struct dentry *dentry) { +struct inode *inode =d_inode (dentry);struct super_block *sb = inode->i_sb;if (!(sb->s_flags &SB_POSIXACL ))
@@ -674,7 +675,7 @@ int ntfs_acl_chmod(struct user_namespace *mnt_userns, struct inode *inode)if (S_ISLNK (inode->i_mode))return -EOPNOTSUPP ; -return posix_acl_chmod (mnt_userns, inode, inode->i_mode); +return posix_acl_chmod (mnt_userns, dentry, inode->i_mode); }/*
fs/ocfs2/acl.c +2 -1
@@ -260,12 +260,13 @@ static int ocfs2_set_acl(handle_t *handle,return ret; } -int ocfs2_iop_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int ocfs2_iop_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {struct buffer_head *bh =NULL ;int status, had_lock;struct ocfs2_lock_holder oh; +struct inode *inode =d_inode (dentry); had_lock =ocfs2_inode_lock_tracker (inode, &bh,1 , &oh);if (had_lock <0 )
fs/ocfs2/acl.h +1 -1
@@ -17,7 +17,7 @@ struct ocfs2_acl_entry { };struct posix_acl *ocfs2_iop_get_acl (struct inode *inode,int type,bool rcu); -int ocfs2_iop_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int ocfs2_iop_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);extern int ocfs2_acl_chmod (struct inode *,struct buffer_head *); extern int ocfs2_init_acl(handle_t *, struct inode *, struct inode *,
fs/orangefs/acl.c +3 -2
@@ -118,12 +118,13 @@ int __orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)return error; } -int orangefs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int orangefs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int error;struct iattr iattr;int rc; +struct inode *inode =d_inode (dentry);memset (&iattr,0 ,sizeof iattr);
@@ -152,7 +153,7 @@ int orangefs_set_acl(struct user_namespace *mnt_userns, struct inode *inode, rc =__orangefs_set_acl (inode, acl, type);if (!rc && (iattr.ia_valid ==ATTR_MODE )) - rc =__orangefs_setattr_mode (inode, &iattr); + rc =__orangefs_setattr_mode (dentry, &iattr);return rc; }
fs/orangefs/inode.c +4 -3
@@ -833,14 +833,15 @@ int __orangefs_setattr(struct inode *inode, struct iattr *iattr)return ret; } -int __orangefs_setattr_mode (struct inode *inode,struct iattr *iattr) +int __orangefs_setattr_mode (struct dentry *dentry,struct iattr *iattr) {int ret; +struct inode *inode =d_inode (dentry); ret =__orangefs_setattr (inode, iattr);/* change mode on a file that has ACLs */ if (!ret && (iattr->ia_valid &ATTR_MODE )) - ret =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); + ret =posix_acl_chmod (&init_user_ns, dentry, inode->i_mode);return ret; }
@@ -856,7 +857,7 @@ int orangefs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, ret =setattr_prepare (&init_user_ns, dentry, iattr);if (ret) goto out; - ret =__orangefs_setattr_mode (d_inode (dentry), iattr); + ret =__orangefs_setattr_mode (dentry, iattr);sync_inode_metadata (d_inode (dentry),1 ); out: gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_setattr: returning %d\n",
fs/orangefs/orangefs-kernel.h +2 -2
@@ -107,7 +107,7 @@ extern const struct xattr_handler *orangefs_xattr_handlers[];extern struct posix_acl *orangefs_get_acl (struct inode *inode,int type,bool rcu);extern int orangefs_set_acl (struct user_namespace *mnt_userns, -struct inode *inode,struct posix_acl *acl, +struct dentry *dentry,struct posix_acl *acl,int type);extern int __orangefs_set_acl (struct inode *inode,struct posix_acl *acl,int type);
@@ -362,7 +362,7 @@ struct inode *orangefs_new_inode(struct super_block *sb, struct orangefs_object_kref *ref);int __orangefs_setattr (struct inode *,struct iattr *); -int __orangefs_setattr_mode (struct inode *inode,struct iattr *iattr); +int __orangefs_setattr_mode (struct dentry *dentry,struct iattr *iattr);int orangefs_setattr (struct user_namespace *,struct dentry *,struct iattr *); int orangefs_getattr(struct user_namespace *mnt_userns, const struct path *path,
fs/posix_acl.c +11 -7
@@ -587,9 +587,10 @@ EXPORT_SYMBOL(__posix_acl_chmod);* performed on the raw inode simply passs init_user_ns. */ int -posix_acl_chmod (struct user_namespace *mnt_userns,struct inode *inode, +posix_acl_chmod (struct user_namespace *mnt_userns,struct dentry *dentry,umode_t mode) { +struct inode *inode =d_inode (dentry);struct posix_acl *acl;int ret =0 ;
@@ -608,7 +609,7 @@ int ret =__posix_acl_chmod (&acl,GFP_KERNEL , mode);if (ret)return ret; - ret = inode->i_op->set_acl (mnt_userns, inode, acl,ACL_TYPE_ACCESS ); + ret = inode->i_op->set_acl (mnt_userns, dentry, acl,ACL_TYPE_ACCESS );posix_acl_release (acl);return ret; }
@@ -1138,9 +1139,11 @@ posix_acl_xattr_get(const struct xattr_handler *handler, }int -set_posix_acl (struct user_namespace *mnt_userns,struct inode *inode, +set_posix_acl (struct user_namespace *mnt_userns,struct dentry *dentry,int type,struct posix_acl *acl) { +struct inode *inode =d_inode (dentry); +if (!IS_POSIXACL (inode))return -EOPNOTSUPP ;if (!inode->i_op->set_acl)
@@ -1156,14 +1159,14 @@ set_posix_acl(struct user_namespace *mnt_userns, struct inode *inode,if (ret)return ret; } -return inode->i_op->set_acl (mnt_userns, inode, acl, type); +return inode->i_op->set_acl (mnt_userns, dentry, acl, type); }EXPORT_SYMBOL (set_posix_acl);static int posix_acl_xattr_set (const struct xattr_handler *handler,struct user_namespace *mnt_userns, -struct dentry *unused,struct inode *inode, +struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags) {
@@ -1185,7 +1188,7 @@ posix_acl_xattr_set(const struct xattr_handler *handler,if (IS_ERR (acl))return PTR_ERR (acl); } - ret =set_posix_acl (mnt_userns, inode, handler->flags, acl); + ret =set_posix_acl (mnt_userns, dentry, handler->flags, acl);posix_acl_release (acl);return ret; }
@@ -1214,10 +1217,11 @@ const struct xattr_handler posix_acl_default_xattr_handler = { };EXPORT_SYMBOL_GPL (posix_acl_default_xattr_handler); -int simple_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int simple_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int error; +struct inode *inode =d_inode (dentry);if (type ==ACL_TYPE_ACCESS ) { error = posix_acl_update_mode(mnt_userns, inode,
fs/reiserfs/acl.h +3 -3
@@ -49,9 +49,9 @@ static inline int reiserfs_acl_count(size_t size)#ifdef CONFIG_REISERFS_FS_POSIX_ACL struct posix_acl *reiserfs_get_acl (struct inode *inode,int type,bool rcu); -int reiserfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +int reiserfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type); -int reiserfs_acl_chmod (struct inode *inode); +int reiserfs_acl_chmod (struct dentry *dentry);int reiserfs_inherit_default_acl (struct reiserfs_transaction_handle *th,struct inode *dir,struct dentry *dentry,struct inode *inode);
@@ -63,7 +63,7 @@ int reiserfs_cache_default_acl(struct inode *dir);#define reiserfs_get_acl NULL#define reiserfs_set_acl NULL -static inline int reiserfs_acl_chmod (struct inode *inode) +static inline int reiserfs_acl_chmod (struct dentry *dentry) {return 0 ; }
fs/reiserfs/inode.c +1 -1
@@ -3404,7 +3404,7 @@ int reiserfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,if (!error &&reiserfs_posixacl (inode->i_sb)) {if (attr->ia_valid &ATTR_MODE ) - error =reiserfs_acl_chmod (inode); + error =reiserfs_acl_chmod (dentry); } out:
fs/reiserfs/xattr_acl.c +6 -3
@@ -18,7 +18,7 @@ static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,int -reiserfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +reiserfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {int error, error2;
@@ -26,6 +26,7 @@ reiserfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode,size_t jcreate_blocks;int size = acl ?posix_acl_xattr_size (acl->a_count) :0 ;int update_mode =0 ; +struct inode *inode =d_inode (dentry);umode_t mode = inode->i_mode;/*
@@ -396,13 +397,15 @@ int reiserfs_cache_default_acl(struct inode *inode)/* * Called under i_mutex */ -int reiserfs_acl_chmod (struct inode *inode) +int reiserfs_acl_chmod (struct dentry *dentry) { +struct inode *inode =d_inode (dentry); +if (IS_PRIVATE (inode))return 0 ;if (get_inode_sd_version (inode) ==STAT_DATA_V1 || !reiserfs_posixacl (inode->i_sb))return 0 ; -return posix_acl_chmod (&init_user_ns, inode, inode->i_mode); +return posix_acl_chmod (&init_user_ns, dentry, inode->i_mode); }
fs/xfs/xfs_acl.c +2 -1
@@ -242,12 +242,13 @@ xfs_acl_set_mode( }int -xfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +xfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type) {umode_t mode;bool set_mode = false;int error =0 ; +struct inode *inode =d_inode (dentry);if (!acl) goto set_acl;
fs/xfs/xfs_acl.h +1 -1
@@ -11,7 +11,7 @@ struct posix_acl;#ifdef CONFIG_XFS_POSIX_ACL extern struct posix_acl *xfs_get_acl (struct inode *inode,int type,bool rcu); -extern int xfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +extern int xfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,struct posix_acl *acl,int type);extern int __xfs_set_acl (struct inode *inode,struct posix_acl *acl,int type);void xfs_forget_acl (struct inode *inode,const char *name);
fs/xfs/xfs_iops.c +6 -4
@@ -639,6 +639,7 @@ xfs_vn_change_ok(static int xfs_setattr_nonsize (struct user_namespace *mnt_userns, +struct dentry *dentry,struct xfs_inode *ip,struct iattr *iattr) {
@@ -745,7 +746,7 @@ xfs_setattr_nonsize(* Posix ACL code seems to care about this issue either. */ if (mask &ATTR_MODE ) { - error =posix_acl_chmod (mnt_userns, inode, inode->i_mode); + error =posix_acl_chmod (mnt_userns, dentry, inode->i_mode);if (error)return error; }
@@ -767,6 +768,7 @@ xfs_setattr_nonsize( STATIC intxfs_setattr_size (struct user_namespace *mnt_userns, +struct dentry *dentry,struct xfs_inode *ip,struct iattr *iattr) {
@@ -798,7 +800,7 @@ xfs_setattr_size(* Use the regular setattr path to update the timestamps. */ iattr->ia_valid &= ~ATTR_SIZE ; -return xfs_setattr_nonsize (mnt_userns, ip, iattr); +return xfs_setattr_nonsize (mnt_userns, dentry, ip, iattr); }/*
@@ -975,7 +977,7 @@ xfs_vn_setattr_size( error =xfs_vn_change_ok (mnt_userns, dentry, iattr);if (error)return error; -return xfs_setattr_size (mnt_userns, ip, iattr); +return xfs_setattr_size (mnt_userns, dentry, ip, iattr); }STATIC int
@@ -1007,7 +1009,7 @@ xfs_vn_setattr( error =xfs_vn_change_ok (mnt_userns, dentry, iattr);if (!error) - error =xfs_setattr_nonsize (mnt_userns, ip, iattr); + error =xfs_setattr_nonsize (mnt_userns, dentry, ip, iattr); }return error;
include/linux/fs.h +1 -1
@@ -2168,7 +2168,7 @@ struct inode_operations { umode_t create_mode);int (*tmpfile) (struct user_namespace *,struct inode *,struct dentry *,umode_t ); -int (*set_acl)(struct user_namespace *,struct inode *, +int (*set_acl)(struct user_namespace *,struct dentry *,struct posix_acl *,int );int (*fileattr_set)(struct user_namespace *mnt_userns,struct dentry *dentry,struct fileattr *fa);
include/linux/posix_acl.h +6 -6
@@ -69,21 +69,21 @@ extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);extern int __posix_acl_chmod (struct posix_acl **,gfp_t ,umode_t );extern struct posix_acl *get_posix_acl (struct inode *,int ); -extern int set_posix_acl (struct user_namespace *,struct inode *,int , -struct posix_acl *); +int set_posix_acl (struct user_namespace *,struct dentry *,int , +struct posix_acl *);struct posix_acl *get_cached_acl_rcu (struct inode *inode,int type);struct posix_acl *posix_acl_clone (const struct posix_acl *acl,gfp_t flags);#ifdef CONFIG_FS_POSIX_ACL -int posix_acl_chmod (struct user_namespace *,struct inode *,umode_t ); +int posix_acl_chmod (struct user_namespace *,struct dentry *,umode_t );extern int posix_acl_create (struct inode *,umode_t *,struct posix_acl **,struct posix_acl **);int posix_acl_update_mode (struct user_namespace *,struct inode *,umode_t *,struct posix_acl **); -extern int simple_set_acl (struct user_namespace *,struct inode *, -struct posix_acl *,int ); +int simple_set_acl (struct user_namespace *,struct dentry *, +struct posix_acl *,int );extern int simple_acl_create (struct inode *,struct inode *);struct posix_acl *get_cached_acl (struct inode *inode,int type);
@@ -101,7 +101,7 @@ static inline void cache_no_acl(struct inode *inode) }#else static inline int posix_acl_chmod (struct user_namespace *mnt_userns, -struct inode *inode,umode_t mode) +struct dentry *dentry,umode_t mode) {return 0 ; }
mm/shmem.c +1 -1
@@ -1126,7 +1126,7 @@ static int shmem_setattr(struct user_namespace *mnt_userns,setattr_copy (&init_user_ns, inode, attr);if (attr->ia_valid &ATTR_MODE ) - error =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); + error =posix_acl_chmod (&init_user_ns, dentry, inode->i_mode);return error; }
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 7/30 9p: implement get acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
So far 9p implemented a ->get_inode_acl() operation that didn't require access to the dentry in order to allow (limited) permission checking via posix acls in the vfs. Now that we have get and set acl inode operations that take a dentry argument we can give 9p get and set acl inode operations.
This is mostly a refactoring of the codepaths currently used in 9p posix acl xattr handler. After we have fully implemented the posix acl api and switched the vfs over to it, the 9p specific posix acl xattr handler and associated code will be removed.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
Al Viro <[email protected]>:
- Simplify v9fs_iop_get_acl().
- Simplify v9fs_fid_get_acl() and associated callers.
fs/9p/acl.c | 80 +++++++++++++++++++++++++-------- fs/9p/acl.h | 5 ++- fs/9p/vfs_inode_dotl.c | 6 ++- include/linux/posix_acl_xattr.h | 11 +++++ 4 files changed, 80 insertions(+), 22 deletions(-)
fs/9p/acl.c +61 -19
@@ -17,34 +17,64 @@#include "v9fs_vfs.h" #include "fid.h" -static struct posix_acl *__v9fs_get_acl (struct p9_fid *fid,char *name) +static struct posix_acl *v9fs_fid_get_acl (struct p9_fid *fid,const char *name) {ssize_t size;void *value =NULL ;struct posix_acl *acl =NULL ; size =v9fs_fid_xattr_get (fid, name,NULL ,0 ); -if (size >0 ) { - value =kzalloc (size,GFP_NOFS ); -if (!value) -return ERR_PTR (-ENOMEM ); - size =v9fs_fid_xattr_get (fid, name, value, size); -if (size >0 ) { - acl =posix_acl_from_xattr (&init_user_ns, value, size); -if (IS_ERR (acl)) - goto err_out; - } - }else if (size == -ENODATA || size ==0 || - size == -ENOSYS || size == -EOPNOTSUPP ) { - acl =NULL ; - }else - acl =ERR_PTR (-EIO ); - -err_out: +if (size <0 ) +return ERR_PTR (size); +if (size ==0 ) +return ERR_PTR (-ENODATA ); + + value =kzalloc (size,GFP_NOFS ); +if (!value) +return ERR_PTR (-ENOMEM ); + + size =v9fs_fid_xattr_get (fid, name, value, size); +if (size <0 ) + acl =ERR_PTR (size); +else if (size ==0 ) + acl =ERR_PTR (-ENODATA ); +else + acl =posix_acl_from_xattr (&init_user_ns, value, size);kfree (value);return acl; } +static struct posix_acl *v9fs_acl_get (struct dentry *dentry,const char *name) +{ +struct p9_fid *fid; +struct posix_acl *acl =NULL ; + + fid =v9fs_fid_lookup (dentry); +if (IS_ERR (fid)) +return ERR_CAST (fid); + + acl =v9fs_fid_get_acl (fid, name); +p9_fid_put (fid); +return acl; +} + +static struct posix_acl *__v9fs_get_acl (struct p9_fid *fid,const char *name) +{ +int retval; +struct posix_acl *acl =NULL ; + + acl =v9fs_fid_get_acl (fid, name); +if (!IS_ERR (acl)) +return acl; + + retval =PTR_ERR (acl); +if (retval == -ENODATA || retval == -ENOSYS || retval == -EOPNOTSUPP ) +return NULL ; + +/* map everything else to -EIO */ +return ERR_PTR (-EIO ); +} +int v9fs_get_acl (struct inode *inode,struct p9_fid *fid) {int retval =0 ;
@@ -89,7 +119,7 @@ static struct posix_acl *v9fs_get_cached_acl(struct inode *inode, int type)return acl; } -struct posix_acl *v9fs_iop_get_acl (struct inode *inode,int type,bool rcu) +struct posix_acl *v9fs_iop_get_inode_acl (struct inode *inode,int type,bool rcu) {struct v9fs_session_info *v9ses;
@@ -109,6 +139,18 @@ struct posix_acl *v9fs_iop_get_acl(struct inode *inode, int type, bool rcu) } +struct posix_acl *v9fs_iop_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,int type) +{ +struct v9fs_session_info *v9ses; + + v9ses =v9fs_dentry2v9ses (dentry); +/* We allow set/get/list of acl when access=client is not specified. */ +if ((v9ses->flags &V9FS_ACCESS_MASK ) !=V9FS_ACCESS_CLIENT ) +return v9fs_acl_get (dentry,posix_acl_xattr_name (type)); +return v9fs_get_cached_acl (d_inode (dentry), type); +} +static int v9fs_set_acl (struct p9_fid *fid,int type,struct posix_acl *acl) {int retval;
fs/9p/acl.h +4 -1
@@ -8,8 +8,10 @@#ifdef CONFIG_9P_FS_POSIX_ACL int v9fs_get_acl (struct inode *inode,struct p9_fid *fid); -struct posix_acl *v9fs_iop_get_acl (struct inode *inode,int type, +struct posix_acl *v9fs_iop_get_inode_acl (struct inode *inode,int type,bool rcu); +struct posix_acl *v9fs_iop_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,int type);int v9fs_acl_chmod (struct inode *inode,struct p9_fid *fid);int v9fs_set_create_acl (struct inode *inode,struct p9_fid *fid,struct posix_acl *dacl,struct posix_acl *acl);
@@ -17,6 +19,7 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep, struct posix_acl **dpacl, struct posix_acl **pacl);void v9fs_put_acl (struct posix_acl *dacl,struct posix_acl *acl);#else +#define v9fs_iop_get_inode_acl NULL#define v9fs_iop_get_acl NULLstatic inline int v9fs_get_acl (struct inode *inode,struct p9_fid *fid) {
fs/9p/vfs_inode_dotl.c +4 -2
@@ -983,14 +983,16 @@ const struct inode_operations v9fs_dir_inode_operations_dotl = { .getattr = v9fs_vfs_getattr_dotl, .setattr = v9fs_vfs_setattr_dotl, .listxattr = v9fs_listxattr, - .get_inode_acl = v9fs_iop_get_acl, + .get_inode_acl = v9fs_iop_get_inode_acl, + .get_acl = v9fs_iop_get_acl, };const struct inode_operations v9fs_file_inode_operations_dotl = { .getattr = v9fs_vfs_getattr_dotl, .setattr = v9fs_vfs_setattr_dotl, .listxattr = v9fs_listxattr, - .get_inode_acl = v9fs_iop_get_acl, + .get_inode_acl = v9fs_iop_get_inode_acl, + .get_acl = v9fs_iop_get_acl, };const struct inode_operations v9fs_symlink_inode_operations_dotl = {
include/linux/posix_acl_xattr.h +11 -0
@@ -60,6 +60,17 @@ int posix_acl_to_xattr(struct user_namespace *user_ns,struct posix_acl *vfs_set_acl_prepare (struct user_namespace *mnt_userns,struct user_namespace *fs_userns,const void *value,size_t size); +static inline const char *posix_acl_xattr_name (int type) +{ +switch (type) { +case ACL_TYPE_ACCESS : +return XATTR_NAME_POSIX_ACL_ACCESS ; +case ACL_TYPE_DEFAULT : +return XATTR_NAME_POSIX_ACL_DEFAULT ; + } + +return "" ; +}extern const struct xattr_handler posix_acl_access_xattr_handler;extern const struct xattr_handler posix_acl_default_xattr_handler;
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 18/30 evm: simplify evm_xattr_acl_change()
In reply to Christian BraunerThe posix acl api provides a dedicated security and integrity hook for setting posix acls. This means that
evm_protect_xattr()
-> evm_xattr_change()
-> evm_xattr_acl_change()
is now only hit during vfs_remove_acl() at which point we are guaranteed that xattr_value and xattr_value_len are NULL and 0. In this case evm always used to return 1. Simplify this function to do just that.
---
Notes:
/* v2 */
unchangedsecurity/integrity/evm/evm_main.c | 62 +++++++------------------------ 1 file changed, 14 insertions(+), 48 deletions(-)
security/integrity/evm/evm_main.c +14 -48
@@ -436,62 +436,29 @@ static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)/* * evm_xattr_acl_change - check if passed ACL changes the inode mode -* @mnt_userns: user namespace of the idmapped mount -* @dentry: pointer to the affected dentry * @xattr_name: requested xattr * @xattr_value: requested xattr value * @xattr_value_len: requested xattr value length * -* Check if passed ACL changes the inode mode, which is protected by EVM. +* This is only hit during xattr removal at which point we always return 1. +* Splat a warning in case someone managed to pass data to this function. That +* should never happen. * * Returns 1 if passed ACL causes inode mode change, 0 otherwise. */ -static int evm_xattr_acl_change (struct user_namespace *mnt_userns, -struct dentry *dentry,const char *xattr_name, -const void *xattr_value,size_t xattr_value_len) +static int evm_xattr_acl_change (const void *xattr_value,size_t xattr_value_len) { -#ifdef CONFIG_FS_POSIX_ACL -umode_t mode; -struct posix_acl *acl =NULL , *acl_res; -struct inode *inode =d_backing_inode (dentry); -int rc; - -/* -* An earlier comment here mentioned that the idmappings for -* ACL_{GROUP,USER} don't matter since EVM is only interested in the -* mode stored as part of POSIX ACLs. Nonetheless, if it must translate -* from the uapi POSIX ACL representation to the VFS internal POSIX ACL -* representation it should do so correctly. There's no guarantee that -* we won't change POSIX ACLs in a way that ACL_{GROUP,USER} matters -* for the mode at some point and it's difficult to keep track of all -* the LSM and integrity modules and what they do to POSIX ACLs. -* -* Frankly, EVM shouldn't try to interpret the uapi struct for POSIX -* ACLs it received. It requires knowledge that only the VFS is -* guaranteed to have. -*/ - acl =vfs_set_acl_prepare (mnt_userns,i_user_ns (inode), - xattr_value, xattr_value_len); -if (IS_ERR_OR_NULL (acl)) -return 1 ; - - acl_res = acl; -/* -* Passing mnt_userns is necessary to correctly determine the GID in -* an idmapped mount, as the GID is used to clear the setgid bit in -* the inode mode. -*/ - rc =posix_acl_update_mode (mnt_userns, inode, &mode, &acl_res); - -posix_acl_release (acl); - -if (rc) -return 1 ; +int rc =0 ; -if (inode->i_mode != mode) -return 1 ; +#ifdef CONFIG_FS_POSIX_ACL +WARN_ONCE (xattr_value !=NULL , +"Passing xattr value for POSIX ACLs not supported\n" ); +WARN_ONCE (xattr_value_len !=0 , +"Passing non-zero length for POSIX ACLs not supported\n" ); + rc =1 ;#endif -return 0 ; + +return rc; }/*
@@ -514,8 +481,7 @@ static int evm_xattr_change(struct user_namespace *mnt_userns,int rc =0 ;if (posix_xattr_acl (xattr_name)) -return evm_xattr_acl_change (mnt_userns, dentry, xattr_name, - xattr_value, xattr_value_len); +return evm_xattr_acl_change (xattr_value, xattr_value_len); rc =vfs_getxattr_alloc (&init_user_ns, dentry, xattr_name, &xattr_data,0 ,GFP_NOFS );
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 19/30 ksmbd: use vfs_remove_acl()
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
Now that we've switched all filesystems that can serve as the lower filesystem for ksmbd we can switch ksmbd over to rely on the posix acl api. Note that this is orthogonal to switching the vfs itself over.
---
Notes:
/* v2 */
unchangedfs/ksmbd/vfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/vfs.c +1 -1
@@ -1311,7 +1311,7 @@ int ksmbd_vfs_remove_acl_xattrs(struct user_namespace *user_ns, sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1) || !strncmp(name, XATTR_NAME_POSIX_ACL_DEFAULT, sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1)) { - err =ksmbd_vfs_remove_xattr (user_ns, dentry, name); + err =vfs_remove_acl (user_ns, dentry, name);if (err)ksmbd_debug (SMB ,"remove acl xattr failed : %s\n" , name);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 16/30 acl: add vfs_get_acl()
In reply to Christian BraunerIn previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new vfs_get_acl() api that can be used to get posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.
After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
---
Notes:
/* v2 */
unchangedfs/posix_acl.c | 131 ++++++++++++++++++++++++++++++-- include/linux/posix_acl.h | 9 +++ include/linux/posix_acl_xattr.h | 10 +++ 3 files changed, 142 insertions(+), 8 deletions(-)
fs/posix_acl.c +123 -8
@@ -108,7 +108,9 @@ void forget_all_cached_acls(struct inode *inode) }EXPORT_SYMBOL (forget_all_cached_acls); -struct posix_acl *get_acl (struct inode *inode,int type) +struct posix_acl *__get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,struct inode *inode, +int type) {void *sentinel;struct posix_acl **p;
@@ -141,19 +143,21 @@ struct posix_acl *get_acl(struct inode *inode, int type)cmpxchg (p,ACL_NOT_CACHED , sentinel);/* -* Normally, the ACL returned by ->get_inode_acl will be cached. +* Normally, the ACL returned by ->get{_inode}_acl will be cached. * A filesystem can prevent that by calling -* forget_cached_acl(inode, type) in ->get_inode_acl. +* forget_cached_acl(inode, type) in ->get{_inode}_acl. * -* If the filesystem doesn't have a get_acl() function at all, we'll -* just create the negative cache entry. +* If the filesystem doesn't have a get{_inode}_ acl() function at all, +* we'll just create the negative cache entry. */ -if (!inode->i_op->get_inode_acl) { +if (dentry && inode->i_op->get_acl) { + acl = inode->i_op->get_acl (mnt_userns, dentry, type); + }else if (inode->i_op->get_inode_acl) { + acl = inode->i_op->get_inode_acl (inode, type, false); + }else {set_cached_acl (inode, type,NULL );return NULL ; } - acl = inode->i_op->get_inode_acl (inode, type, false); -if (IS_ERR (acl)) {/* * Remove our sentinel so that we don't block future attempts
@@ -171,6 +175,11 @@ struct posix_acl *get_acl(struct inode *inode, int type)posix_acl_release (acl);return acl; } + +struct posix_acl *get_acl (struct inode *inode,int type) +{ +return __get_acl (&init_user_ns,NULL , inode, type); +}EXPORT_SYMBOL (get_acl);/*
@@ -1117,6 +1126,67 @@ posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl, }EXPORT_SYMBOL (posix_acl_to_xattr); +/** +* vfs_posix_acl_to_xattr - convert from kernel to userspace representation +* @mnt_userns: user namespace of the mount +* @inode: inode the posix acls are set on +* @acl: the posix acls as represented by the vfs +* @buffer: the buffer into which to convert @acl +* @size: size of @buffer +* +* This converts @acl from the VFS representation in the filesystem idmapping +* to the uapi form reportable to userspace. And mount and caller idmappings +* are handled appropriately. +* +* Return: On success, the size of the stored uapi posix acls, on error a +* negative errno. +*/ +ssize_t vfs_posix_acl_to_xattr (struct user_namespace *mnt_userns, +struct inode *inode,const struct posix_acl *acl, +void *buffer,size_t size) + +{ +struct posix_acl_xattr_header *ext_acl = buffer; +struct posix_acl_xattr_entry *ext_entry; +struct user_namespace *fs_userns, *caller_userns; +ssize_t real_size, n; +vfsuid_t vfsuid; +vfsgid_t vfsgid; + + real_size =posix_acl_xattr_size (acl->a_count); +if (!buffer) +return real_size; +if (real_size > size) +return -ERANGE ; + + ext_entry = (void *)(ext_acl +1 ); + ext_acl->a_version =cpu_to_le32 (POSIX_ACL_XATTR_VERSION ); + + fs_userns =i_user_ns (inode); + caller_userns =current_user_ns (); +for (n=0 ; n < acl->a_count; n++, ext_entry++) { +const struct posix_acl_entry *acl_e = &acl->a_entries[n]; + ext_entry->e_tag =cpu_to_le16 (acl_e->e_tag); + ext_entry->e_perm =cpu_to_le16 (acl_e->e_perm); +switch (acl_e->e_tag) { +case ACL_USER : + vfsuid =make_vfsuid (mnt_userns, fs_userns, acl_e->e_uid); + ext_entry->e_id =cpu_to_le32 (from_kuid ( + caller_userns,vfsuid_into_kuid (vfsuid))); +break ; +case ACL_GROUP : + vfsgid =make_vfsgid (mnt_userns, fs_userns, acl_e->e_gid); + ext_entry->e_id =cpu_to_le32 (from_kgid ( + caller_userns,vfsgid_into_kgid (vfsgid))); +break ; +default : + ext_entry->e_id =cpu_to_le32 (ACL_UNDEFINED_ID ); +break ; + } + } +return real_size; +} + static int posix_acl_xattr_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode,
@@ -1369,3 +1439,48 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,return error; }EXPORT_SYMBOL (vfs_set_acl); + +/** +* vfs_get_acl - get posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function retrieves @kacl from the filesystem. The caller must all +* posix_acl_release() on @kacl. +* +* Return: On success POSIX ACLs in VFS format, on error negative errno. +*/ +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +struct inode *inode =d_inode (dentry); +struct posix_acl *acl; +int acl_type, error; + + acl_type =posix_acl_type (acl_name); +if (acl_type <0 ) +return ERR_PTR (-EINVAL ); + +/* +* The VFS has no restrictions on reading POSIX ACLs so calling +* something like xattr_permission() isn't needed. Only LSMs get a say. +*/ + error =security_inode_getxattr (dentry, acl_name); +if (error) +return ERR_PTR (error); + +if (!IS_POSIXACL (inode)) +return ERR_PTR (-EOPNOTSUPP ); +if (S_ISLNK (inode->i_mode)) +return ERR_PTR (-EOPNOTSUPP ); + + acl =__get_acl (mnt_userns, dentry, inode, acl_type); +if (IS_ERR (acl)) +return acl; +if (!acl) +return ERR_PTR (-ENODATA ); + +return acl; +} +EXPORT_SYMBOL (vfs_get_acl);
include/linux/posix_acl.h +9 -0
@@ -102,6 +102,8 @@ static inline void cache_no_acl(struct inode *inode)int vfs_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry,const char *acl_name,struct posix_acl *kacl); +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name);#else static inline int posix_acl_chmod (struct user_namespace *mnt_userns,struct dentry *dentry,umode_t mode)
@@ -136,6 +138,13 @@ static inline int vfs_set_acl(struct user_namespace *mnt_userns, {return 0 ; } + +static inline struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry, +const char *acl_name) +{ +return NULL ; +}#endif /* CONFIG_FS_POSIX_ACL */ struct posix_acl *get_acl (struct inode *inode,int type);
include/linux/posix_acl_xattr.h +10 -0
@@ -38,6 +38,9 @@ void posix_acl_fix_xattr_to_user(void *value, size_t size);void posix_acl_getxattr_idmapped_mnt (struct user_namespace *mnt_userns,const struct inode *inode,void *value,size_t size); +ssize_t vfs_posix_acl_to_xattr (struct user_namespace *mnt_userns, +struct inode *inode,const struct posix_acl *acl, +void *buffer,size_t size);#else static inline void posix_acl_fix_xattr_from_user (void *value,size_t size) {
@@ -51,6 +54,13 @@ posix_acl_getxattr_idmapped_mnt(struct user_namespace *mnt_userns, size_t size) { } +static inline ssize_t vfs_posix_acl_to_xattr (struct user_namespace *mnt_userns, +struct inode *inode, +const struct posix_acl *acl, +void *buffer,size_t size) +{ +return 0 ; +}#endif struct posix_acl *posix_acl_from_xattr(struct user_namespace *user_ns,
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 17/30 acl: add vfs_remove_acl()
In reply to Christian BraunerIn previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new vfs_remove_acl() api that can be used to set posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.
After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
---
Notes:
/* v2 */
unchangedfs/posix_acl.c | 65 +++++++++++++++++++++++++++++++++++++++ include/linux/posix_acl.h | 8 +++++ 2 files changed, 73 insertions(+)
fs/posix_acl.c +65 -0
@@ -1484,3 +1484,68 @@ struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns,return acl; }EXPORT_SYMBOL (vfs_get_acl); + +/** +* vfs_remove_acl - remove posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function removes posix acls. +* +* Return: On success 0, on error negative errno. +*/ +int vfs_remove_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +const char *acl_name) +{ +int acl_type; +int error; +struct inode *inode =d_inode (dentry); +struct inode *delegated_inode =NULL ; + + acl_type =posix_acl_type (acl_name); +if (acl_type <0 ) +return -EINVAL ; + +retry_deleg: +inode_lock (inode); + +/* +* We only care about restrictions the inode struct itself places upon +* us otherwise POSIX ACLs aren't subject to any VFS restrictions. +*/ + error =xattr_permission (mnt_userns, inode, acl_name,MAY_WRITE ); +if (error) + goto out_inode_unlock; + + error =security_inode_removexattr (mnt_userns, dentry, acl_name); +if (error) + goto out_inode_unlock; + + error =try_break_deleg (inode, &delegated_inode); +if (error) + goto out_inode_unlock; + +if (inode->i_opflags &IOP_XATTR ) + error =set_posix_acl (mnt_userns, dentry, acl_type,NULL ); +else if (unlikely (is_bad_inode (inode))) + error = -EIO ; +else + error = -EOPNOTSUPP ; +if (!error) { +fsnotify_xattr (dentry); +evm_inode_post_removexattr (dentry, acl_name); + } + +out_inode_unlock: +inode_unlock (inode); + +if (delegated_inode) { + error =break_deleg_wait (&delegated_inode); +if (!error) + goto retry_deleg; + } + +return error; +} +EXPORT_SYMBOL (vfs_remove_acl);
include/linux/posix_acl.h +8 -0
@@ -104,6 +104,8 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl);struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns,struct dentry *dentry,const char *acl_name); +int vfs_remove_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +const char *acl_name);#else static inline int posix_acl_chmod (struct user_namespace *mnt_userns,struct dentry *dentry,umode_t mode)
@@ -145,6 +147,12 @@ static inline struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns, {return NULL ; } + +static inline int vfs_remove_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +return 0 ; +}#endif /* CONFIG_FS_POSIX_ACL */ struct posix_acl *get_acl (struct inode *inode,int type);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 22/30 ovl: implement get acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
Now that we have added get and set acl inode operations that allow easy access to the dentry we give overlayfs it's own get and set acl inode operations.
Since overlayfs is a stacking filesystem it will use the newly added posix acl api when retrieving posix acls from the relevant layer.
Since overlayfs can also be mounted on top of idmapped layers. If idmapped layers are used overlayfs must take the layer's idmapping into account after it retrieved the posix acls from the relevant layer.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
Miklos Szeredi <[email protected]>
- Use IS_ERR_OR_NULL() macro.
fs/overlayfs/dir.c | 3 +- fs/overlayfs/inode.c | 61 ++++++++++++++++++++++++++++++++++++---- fs/overlayfs/overlayfs.h | 10 +++++-- 3 files changed, 65 insertions(+), 9 deletions(-)
fs/overlayfs/dir.c +2 -1
@@ -1311,7 +1311,8 @@ const struct inode_operations ovl_dir_inode_operations = { .permission = ovl_permission, .getattr = ovl_getattr, .listxattr = ovl_listxattr, - .get_inode_acl = ovl_get_acl, + .get_inode_acl = ovl_get_inode_acl, + .get_acl = ovl_get_acl, .update_time = ovl_update_time, .fileattr_get = ovl_fileattr_get, .fileattr_set = ovl_fileattr_set,
fs/overlayfs/inode.c +55 -6
97 lines not on this page · raw message
fs/overlayfs/overlayfs.h +8 -2
@@ -592,9 +592,15 @@ int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,ssize_t ovl_listxattr (struct dentry *dentry,char *list,size_t size);#ifdef CONFIG_FS_POSIX_ACL -struct posix_acl *ovl_get_acl (struct inode *inode,int type,bool rcu); +struct posix_acl *ovl_get_inode_acl (struct inode *inode,int type,bool rcu); +struct posix_acl *ovl_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,int type); +void ovl_idmap_posix_acl (struct inode *realinode, +struct user_namespace *mnt_userns, +struct posix_acl *acl);#else -#define ovl_get_acl NULL +#define ovl_get_inode_acl NULL +#define ovl_get_acl NULL#endif int ovl_update_time (struct inode *inode,struct timespec64 *ts,int flags);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 23/30 ovl: implement set acl method
In reply to Christian BraunerThe current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
In order to build a type safe posix api around get and set acl we need all filesystem to implement get and set acl.
Now that we have added get and set acl inode operations that allow easy access to the dentry we give overlayfs it's own get and set acl inode operations.
The set acl inode operation is duplicates most of the ovl posix acl xattr handler. The main difference being that the set acl inode operation relies on the new posix acl api. Once the vfs has been switched over the custom posix acl xattr handler will be removed completely.
Note, until the vfs has been switched to the new posix acl api this patch is a non-functional change.
---
Notes:
/* v2 */
Miklos Szeredi <[email protected]>:
- split ovl_set_acl() into two functions
- add comment about checking whether copy up is even necessary
fs/overlayfs/dir.c | 1 + fs/overlayfs/inode.c | 94 ++++++++++++++++++++++++++++++++++++++++ fs/overlayfs/overlayfs.h | 17 ++++++++ 3 files changed, 112 insertions(+)
fs/overlayfs/dir.c +1 -0
@@ -1313,6 +1313,7 @@ const struct inode_operations ovl_dir_inode_operations = { .listxattr = ovl_listxattr, .get_inode_acl = ovl_get_inode_acl, .get_acl = ovl_get_acl, + .set_acl = ovl_set_acl, .update_time = ovl_update_time, .fileattr_get = ovl_fileattr_get, .fileattr_set = ovl_fileattr_set,
fs/overlayfs/inode.c +94 -0
112 lines not on this page · raw message
fs/overlayfs/overlayfs.h +17 -0
@@ -8,6 +8,8 @@#include <linux/uuid.h> #include <linux/fs.h> #include <linux/namei.h> +#include <linux/posix_acl.h> +#include <linux/posix_acl_xattr.h> #include "ovl_entry.h" #undef pr_fmt
@@ -278,6 +280,18 @@ static inline int ovl_removexattr(struct ovl_fs *ofs, struct dentry *dentry,return ovl_do_removexattr (ofs, dentry,ovl_xattr (ofs, ox)); } +static inline int ovl_do_set_acl (struct ovl_fs *ofs,struct dentry *dentry, +const char *acl_name,struct posix_acl *acl) +{ +return vfs_set_acl (ovl_upper_mnt_userns (ofs), dentry, acl_name, acl); +} + +static inline int ovl_do_remove_acl (struct ovl_fs *ofs,struct dentry *dentry, +const char *acl_name) +{ +return vfs_remove_acl (ovl_upper_mnt_userns (ofs), dentry, acl_name); +} +static inline int ovl_do_rename (struct ovl_fs *ofs,struct inode *olddir,struct dentry *olddentry,struct inode *newdir,struct dentry *newdentry,unsigned int flags)
@@ -595,12 +609,15 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);struct posix_acl *ovl_get_inode_acl (struct inode *inode,int type,bool rcu);struct posix_acl *ovl_get_acl (struct user_namespace *mnt_userns,struct dentry *dentry,int type); +int ovl_set_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +struct posix_acl *acl,int type);void ovl_idmap_posix_acl (struct inode *realinode,struct user_namespace *mnt_userns,struct posix_acl *acl);#else #define ovl_get_inode_acl NULL#define ovl_get_acl NULL +#define ovl_set_acl NULL#endif int ovl_update_time (struct inode *inode,struct timespec64 *ts,int flags);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 24/30 ovl: use posix acl api
In reply to Christian BraunerNow that posix acls have a proper api us it to copy them.
All filesystems that can serve as lower or upper layers for overlayfs have gained support for the new posix acl api in previous patches. So switch all internal overlayfs codepaths for copying posix acls to the new posix acl api.
---
Notes:
/* v2 */
Miklos Szeredi <[email protected]>:
- Move ovl_copy_acl() from util.c to copy_up.c
- Unconditionally clone posix acls
fs/overlayfs/copy_up.c | 38 ++++++++++++++++++++++++++++++++++++++ fs/overlayfs/dir.c | 20 ++------------------ fs/overlayfs/inode.c | 4 ++-- fs/overlayfs/overlayfs.h | 7 +++++++ fs/overlayfs/super.c | 6 ++---- fs/xattr.c | 6 ------ include/linux/xattr.h | 6 ++++++ 7 files changed, 57 insertions(+), 30 deletions(-)
fs/overlayfs/copy_up.c +38 -0
@@ -44,6 +44,35 @@ static bool ovl_must_copy_xattr(const char *name) !strncmp (name,XATTR_SECURITY_PREFIX ,XATTR_SECURITY_PREFIX_LEN ); } +static int ovl_copy_acl (struct ovl_fs *ofs,const struct path *path, +struct dentry *dentry,const char *acl_name) +{ +int err; +struct posix_acl *clone, *real_acl =NULL ; + + real_acl =ovl_get_acl_path (path, acl_name); +if (!real_acl) +return 0 ; + +if (IS_ERR (real_acl)) { + err =PTR_ERR (real_acl); +if (err == -ENODATA || err == -EOPNOTSUPP ) +return 0 ; +return err; + } + + clone =posix_acl_clone (real_acl,GFP_KERNEL ); +posix_acl_release (real_acl);/* release original acl */ +if (!clone) +return -ENOMEM ; + + err =ovl_do_set_acl (ofs, dentry, acl_name, clone); + +/* release cloned acl */ +posix_acl_release (clone); +return err; +} +int ovl_copy_xattr (struct super_block *sb,struct path *oldpath,struct dentry *new) {struct dentry *old = oldpath->dentry;
@@ -93,6 +122,15 @@ int ovl_copy_xattr(struct super_block *sb, struct path *oldpath, struct dentry * error =0 ;continue ;/* Discard */ } + +if (is_posix_acl_xattr (name)) { + error =ovl_copy_acl (OVL_FS (sb), oldpath, new, name); +if (!error) +continue ; +/* POSIX ACLs must be copied. */ +break ; + } + retry: size =ovl_do_getxattr (oldpath, name, value, value_size);if (size == -ERANGE )
fs/overlayfs/dir.c +2 -18
@@ -435,28 +435,12 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry, }static int ovl_set_upper_acl (struct ovl_fs *ofs,struct dentry *upperdentry, -const char *name,const struct posix_acl *acl) +const char *acl_name,struct posix_acl *acl) { -void *buffer; -size_t size; -int err; -if (!IS_ENABLED (CONFIG_FS_POSIX_ACL ) || !acl)return 0 ; - size =posix_acl_xattr_size (acl->a_count); - buffer =kmalloc (size,GFP_KERNEL ); -if (!buffer) -return -ENOMEM ; - - err =posix_acl_to_xattr (&init_user_ns, acl, buffer, size); -if (err <0 ) - goto out_free; - - err =ovl_do_setxattr (ofs, upperdentry, name, buffer, size,XATTR_CREATE ); -out_free: -kfree (buffer); -return err; +return ovl_do_set_acl (ofs, upperdentry, acl_name, acl); } static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
fs/overlayfs/inode.c +2 -2
@@ -550,8 +550,8 @@ struct posix_acl *ovl_get_inode_acl(struct inode *inode, int type, bool rcu)return clone; } -static struct posix_acl *ovl_get_acl_path (const struct path *path, -const char *acl_name) +struct posix_acl *ovl_get_acl_path (const struct path *path, +const char *acl_name) {struct posix_acl *real_acl, *clone;struct user_namespace *mnt_userns;
fs/overlayfs/overlayfs.h +7 -0
@@ -614,10 +614,17 @@ int ovl_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,void ovl_idmap_posix_acl (struct inode *realinode,struct user_namespace *mnt_userns,struct posix_acl *acl); +struct posix_acl *ovl_get_acl_path (const struct path *path, +const char *acl_name);#else #define ovl_get_inode_acl NULL#define ovl_get_acl NULL#define ovl_set_acl NULL +static inline struct posix_acl *ovl_get_acl_path (const struct path *path, +const char *acl_name) +{ +return NULL ; +}#endif int ovl_update_time (struct inode *inode,struct timespec64 *ts,int flags);
fs/overlayfs/super.c +2 -4
@@ -812,13 +812,11 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,* allowed as upper are limited to "normal" ones, where checking * for the above two errors is sufficient. */ - err =ovl_do_removexattr (ofs, work, -XATTR_NAME_POSIX_ACL_DEFAULT ); + err =ovl_do_remove_acl (ofs, work,XATTR_NAME_POSIX_ACL_DEFAULT );if (err && err != -ENODATA && err != -EOPNOTSUPP ) goto out_dput; - err =ovl_do_removexattr (ofs, work, -XATTR_NAME_POSIX_ACL_ACCESS ); + err =ovl_do_remove_acl (ofs, work,XATTR_NAME_POSIX_ACL_ACCESS );if (err && err != -ENODATA && err != -EOPNOTSUPP ) goto out_dput;
fs/xattr.c +0 -6
@@ -281,12 +281,6 @@ __vfs_setxattr_locked(struct user_namespace *mnt_userns, struct dentry *dentry, }EXPORT_SYMBOL_GPL (__vfs_setxattr_locked); -static inline bool is_posix_acl_xattr (const char *name) -{ -return (strcmp (name,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) || - (strcmp (name,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 ); -} -int vfs_setxattr (struct user_namespace *mnt_userns,struct dentry *dentry,const char *name,const void *value,size_t size,int flags)
include/linux/xattr.h +6 -0
@@ -22,6 +22,12 @@struct inode ;struct dentry ; +static inline bool is_posix_acl_xattr (const char *name) +{ +return (strcmp (name,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) || + (strcmp (name,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 ); +} +/* * struct xattr_handler: When @name is set, match attributes with exactly that * name. When @prefix is set instead, match attributes with that prefix and
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 27/30 ovl: use stub posix acl handlers
In reply to Christian BraunerNow that ovl supports the get and set acl inode operations and the vfs has been switched to the new posi api, ovl can simply rely on the stub posix acl handlers. The custom xattr handlers and associated unused helpers can be removed.
---
Notes:
/* v2 */
unchangedfs/overlayfs/super.c | 101 ++----------------------------------------- 1 file changed, 4 insertions(+), 97 deletions(-)
fs/overlayfs/super.c +4 -97
@@ -998,83 +998,6 @@ static unsigned int ovl_split_lowerdirs(char *str)return ctr; } -static int __maybe_unused -ovl_posix_acl_xattr_get (const struct xattr_handler *handler, -struct dentry *dentry,struct inode *inode, -const char *name,void *buffer,size_t size) -{ -return ovl_xattr_get (dentry, inode, handler->name, buffer, size); -} - -static int __maybe_unused -ovl_posix_acl_xattr_set (const struct xattr_handler *handler, -struct user_namespace *mnt_userns, -struct dentry *dentry,struct inode *inode, -const char *name,const void *value, -size_t size,int flags) -{ -struct dentry *workdir =ovl_workdir (dentry); -struct inode *realinode =ovl_inode_real (inode); -struct posix_acl *acl =NULL ; -int err; - -/* Check that everything is OK before copy-up */ -if (value) { -/* The above comment can be understood in two ways: -* -* 1. We just want to check whether the basic POSIX ACL format -* is ok. For example, if the header is correct and the size -* is sane. -* 2. We want to know whether the ACL_{GROUP,USER} entries can -* be mapped according to the underlying filesystem. -* -* Currently, we only check 1. If we wanted to check 2. we -* would need to pass the mnt_userns and the fs_userns of the -* underlying filesystem. But frankly, I think checking 1. is -* enough to start the copy-up. -*/ - acl =vfs_set_acl_prepare (&init_user_ns, &init_user_ns, value, size); -if (IS_ERR (acl)) -return PTR_ERR (acl); - } - err = -EOPNOTSUPP ; -if (!IS_POSIXACL (d_inode (workdir))) - goto out_acl_release; -if (!realinode->i_op->set_acl) - goto out_acl_release; -if (handler->flags ==ACL_TYPE_DEFAULT && !S_ISDIR (inode->i_mode)) { - err = acl ? -EACCES :0 ; - goto out_acl_release; - } - err = -EPERM ; -if (!inode_owner_or_capable (&init_user_ns, inode)) - goto out_acl_release; - -posix_acl_release (acl); - -/* -* Check if sgid bit needs to be cleared (actual setacl operation will -* be done with mounter's capabilities and so that won't do it for us). -*/ -if (unlikely (inode->i_mode &S_ISGID ) && - handler->flags ==ACL_TYPE_ACCESS && - !in_group_p (inode->i_gid) && - !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FSETID )) { -struct iattr iattr = { .ia_valid =ATTR_KILL_SGID }; - - err =ovl_setattr (&init_user_ns, dentry, &iattr); -if (err) -return err; - } - - err =ovl_xattr_set (dentry, inode, handler->name, value, size, flags); -return err; - -out_acl_release: -posix_acl_release (acl); -return err; -} -static int ovl_own_xattr_get (const struct xattr_handler *handler,struct dentry *dentry,struct inode *inode,const char *name,void *buffer,size_t size)
@@ -1107,22 +1030,6 @@ static int ovl_other_xattr_set(const struct xattr_handler *handler,return ovl_xattr_set (dentry, inode, name, value, size, flags); } -static const struct xattr_handler __maybe_unused -ovl_posix_acl_access_xattr_handler = { - .name =XATTR_NAME_POSIX_ACL_ACCESS , - .flags =ACL_TYPE_ACCESS , - .get = ovl_posix_acl_xattr_get, - .set = ovl_posix_acl_xattr_set, -}; - -static const struct xattr_handler __maybe_unused -ovl_posix_acl_default_xattr_handler = { - .name =XATTR_NAME_POSIX_ACL_DEFAULT , - .flags =ACL_TYPE_DEFAULT , - .get = ovl_posix_acl_xattr_get, - .set = ovl_posix_acl_xattr_set, -}; -static const struct xattr_handler ovl_own_trusted_xattr_handler = { .prefix =OVL_XATTR_TRUSTED_PREFIX , .get = ovl_own_xattr_get,
@@ -1143,8 +1050,8 @@ static const struct xattr_handler ovl_other_xattr_handler = {static const struct xattr_handler *ovl_trusted_xattr_handlers[] = { #ifdef CONFIG_FS_POSIX_ACL - &ovl_posix_acl_access_xattr_handler, - &ovl_posix_acl_default_xattr_handler, + &posix_acl_access_xattr_handler, + &posix_acl_default_xattr_handler, #endif &ovl_own_trusted_xattr_handler, &ovl_other_xattr_handler,
@@ -1153,8 +1060,8 @@ static const struct xattr_handler *ovl_trusted_xattr_handlers[] = {static const struct xattr_handler *ovl_user_xattr_handlers[] = { #ifdef CONFIG_FS_POSIX_ACL - &ovl_posix_acl_access_xattr_handler, - &ovl_posix_acl_default_xattr_handler, + &posix_acl_access_xattr_handler, + &posix_acl_default_xattr_handler, #endif &ovl_own_user_xattr_handler, &ovl_other_xattr_handler,
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 25/30 xattr: use posix acl api
In reply to Christian BraunerIn previous patches we built a new posix api solely around get and set inode operations. Now that we have all the pieces in place we can switch the system calls and the vfs over to only rely on this api when interacting with posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.
With the new posix acl api we immediately translate into an appropriate kernel internal struct posix_acl format both when getting and setting posix acls. This is a stark contrast to before were we hacked unsafe raw values into the uapi struct that was stored in a void pointer relying and having filesystems and security modules hack around in the uapi struct as well.
---
Notes:
/* v2 */
unchangedfs/internal.h | 1 + fs/xattr.c | 62 ++++++++++++++++++++++++++++----- include/linux/posix_acl_xattr.h | 10 ++++-- io_uring/xattr.c | 2 ++ 4 files changed, 64 insertions(+), 11 deletions(-)
fs/internal.h +1 -0
@@ -206,6 +206,7 @@ struct xattr_ctx {const void __user *cvalue;void __user *value; }; +struct posix_acl *acl;void *kvalue;size_t size;/* Attribute name */
fs/xattr.c +53 -9
118 lines not on this page · raw message
include/linux/posix_acl_xattr.h +8 -2
@@ -33,6 +33,8 @@ posix_acl_xattr_count(size_t size) }#ifdef CONFIG_FS_POSIX_ACL +struct posix_acl *posix_acl_from_xattr (struct user_namespace *user_ns, +const void *value,size_t size);void posix_acl_fix_xattr_from_user (void *value,size_t size);void posix_acl_fix_xattr_to_user (void *value,size_t size); void posix_acl_getxattr_idmapped_mnt(struct user_namespace *mnt_userns,
@@ -42,6 +44,12 @@ ssize_t vfs_posix_acl_to_xattr(struct user_namespace *mnt_userns, struct inode *inode, const struct posix_acl *acl, void *buffer, size_t size);#else +static inline struct posix_acl * +posix_acl_from_xattr (struct user_namespace *user_ns,const void *value, +size_t size) +{ +return ERR_PTR (-EOPNOTSUPP ); +}static inline void posix_acl_fix_xattr_from_user (void *value,size_t size) { }
@@ -63,8 +71,6 @@ static inline ssize_t vfs_posix_acl_to_xattr(struct user_namespace *mnt_userns, }#endif -struct posix_acl *posix_acl_from_xattr (struct user_namespace *user_ns, -const void *value,size_t size);int posix_acl_to_xattr (struct user_namespace *user_ns,const struct posix_acl *acl,void *buffer,size_t size); struct posix_acl *vfs_set_acl_prepare(struct user_namespace *mnt_userns,
io_uring/xattr.c +2 -0
@@ -8,6 +8,7 @@#include <linux/namei.h> #include <linux/io_uring.h> #include <linux/xattr.h> +#include <linux/posix_acl_xattr.h> #include <uapi/linux/io_uring.h>
@@ -31,6 +32,7 @@ void io_xattr_cleanup(struct io_kiocb *req)kfree (ix->ctx.kname);kvfree (ix->ctx.kvalue); +posix_acl_release (ix->ctx.acl); }static void io_xattr_finish (struct io_kiocb *req,int ret)
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 28/30 cifs: use stub posix acl handlers
In reply to Christian BraunerNow that cifs supports the get and set acl inode operations and the vfs has been switched to the new posi api, cifs can simply rely on the stub posix acl handlers. The custom xattr handlers and associated unused helpers can be removed.
---
Notes:
/* v2 */
unchangedfs/cifs/cifsproto.h | 8 -- fs/cifs/cifssmb.c | 298 -------------------------------------------- fs/cifs/xattr.c | 68 +--------- 3 files changed, 4 insertions(+), 370 deletions(-)
fs/cifs/cifsproto.h +0 -8
@@ -542,18 +542,10 @@ extern int CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, struct cifs_ntsd **acl_inf, __u32 *buflen);extern int CIFSSMBSetCIFSACL (const unsigned int ,struct cifs_tcon *,__u16 ,struct cifs_ntsd *,__u32 ,int ); -extern int CIFSSMBGetPosixACL (const unsigned int xid,struct cifs_tcon *tcon, -const unsigned char *searchName, -char *acl_inf,const int buflen,const int acl_type, -const struct nls_table *nls_codepage,int remap_special_chars);extern int cifs_do_get_acl (const unsigned int xid,struct cifs_tcon *tcon,const unsigned char *searchName,struct posix_acl **acl,const int acl_type,const struct nls_table *nls_codepage,int remap); -extern int CIFSSMBSetPosixACL (const unsigned int xid,struct cifs_tcon *tcon, -const unsigned char *fileName, -const char *local_acl,const int buflen,const int acl_type, -const struct nls_table *nls_codepage,int remap_special_chars); extern int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon, const unsigned char *fileName, const struct posix_acl *acl, const int acl_type,
fs/cifs/cifssmb.c +0 -298
304 lines not on this page · raw message
fs/cifs/xattr.c +4 -64
91 lines not on this page · raw message
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 29/30 9p: use stub posix acl handlers
In reply to Christian BraunerNow that 9p supports the get and set acl inode operations and the vfs has been switched to the new posi api, 9p can simply rely on the stub posix acl handlers. The custom xattr handlers and associated unused helpers can be removed.
---
Notes:
/* v2 */
unchangedfs/9p/acl.c | 121 -------------------------------------------------- fs/9p/xattr.c | 7 +-- fs/9p/xattr.h | 2 - 3 files changed, 4 insertions(+), 126 deletions(-)
fs/9p/acl.c +0 -121
@@ -343,124 +343,3 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep, *modep = mode;return 0 ; } - -static int v9fs_xattr_get_acl (const struct xattr_handler *handler, -struct dentry *dentry,struct inode *inode, -const char *name,void *buffer,size_t size) -{ -struct v9fs_session_info *v9ses; -struct posix_acl *acl; -int error; - - v9ses =v9fs_dentry2v9ses (dentry); -/* -* We allow set/get/list of acl when access=client is not specified -*/ -if ((v9ses->flags &V9FS_ACCESS_MASK ) !=V9FS_ACCESS_CLIENT ) -return v9fs_xattr_get (dentry, handler->name, buffer, size); - - acl =v9fs_get_cached_acl (inode, handler->flags); -if (IS_ERR (acl)) -return PTR_ERR (acl); -if (acl ==NULL ) -return -ENODATA ; - error =posix_acl_to_xattr (&init_user_ns, acl, buffer, size); -posix_acl_release (acl); - -return error; -} - -static int v9fs_xattr_set_acl (const struct xattr_handler *handler, -struct user_namespace *mnt_userns, -struct dentry *dentry,struct inode *inode, -const char *name,const void *value, -size_t size,int flags) -{ -int retval; -struct posix_acl *acl; -struct v9fs_session_info *v9ses; - - v9ses =v9fs_dentry2v9ses (dentry); -/* -* set the attribute on the remote. Without even looking at the -* xattr value. We leave it to the server to validate -*/ -if ((v9ses->flags &V9FS_ACCESS_MASK ) !=V9FS_ACCESS_CLIENT ) -return v9fs_xattr_set (dentry, handler->name, value, size, - flags); - -if (S_ISLNK (inode->i_mode)) -return -EOPNOTSUPP ; -if (!inode_owner_or_capable (&init_user_ns, inode)) -return -EPERM ; -if (value) { -/* update the cached acl value */ - acl =posix_acl_from_xattr (&init_user_ns, value, size); -if (IS_ERR (acl)) -return PTR_ERR (acl); -else if (acl) { - retval =posix_acl_valid (inode->i_sb->s_user_ns, acl); -if (retval) - goto err_out; - } - }else - acl =NULL ; - -switch (handler->flags) { -case ACL_TYPE_ACCESS : -if (acl) { -struct iattr iattr = {0 }; -struct posix_acl *old_acl = acl; - - retval =posix_acl_update_mode (&init_user_ns, inode, - &iattr.ia_mode, &acl); -if (retval) - goto err_out; -if (!acl) { -/* -* ACL can be represented -* by the mode bits. So don't -* update ACL. -*/ -posix_acl_release (old_acl); - value =NULL ; - size =0 ; - } - iattr.ia_valid =ATTR_MODE ; -/* FIXME should we update ctime ? -* What is the following setxattr update the -* mode ? -*/ -v9fs_vfs_setattr_dotl (&init_user_ns, dentry, &iattr); - } -break ; -case ACL_TYPE_DEFAULT : -if (!S_ISDIR (inode->i_mode)) { - retval = acl ? -EINVAL :0 ; - goto err_out; - } -break ; -default : -BUG (); - } - retval =v9fs_xattr_set (dentry, handler->name, value, size, flags); -if (!retval) -set_cached_acl (inode, handler->flags, acl); -err_out: -posix_acl_release (acl); -return retval; -} - -const struct xattr_handler v9fs_xattr_acl_access_handler = { - .name =XATTR_NAME_POSIX_ACL_ACCESS , - .flags =ACL_TYPE_ACCESS , - .get = v9fs_xattr_get_acl, - .set = v9fs_xattr_set_acl, -}; - -const struct xattr_handler v9fs_xattr_acl_default_handler = { - .name =XATTR_NAME_POSIX_ACL_DEFAULT , - .flags =ACL_TYPE_DEFAULT , - .get = v9fs_xattr_get_acl, - .set = v9fs_xattr_set_acl, -};
fs/9p/xattr.c +4 -3
@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/sched.h> #include <linux/uio.h> +#include <linux/posix_acl_xattr.h> #include <net/9p/9p.h> #include <net/9p/client.h>
@@ -182,9 +183,9 @@ static struct xattr_handler v9fs_xattr_security_handler = {const struct xattr_handler *v9fs_xattr_handlers[] = { &v9fs_xattr_user_handler, &v9fs_xattr_trusted_handler, -#ifdef CONFIG_9P_FS_POSIX_ACL - &v9fs_xattr_acl_access_handler, - &v9fs_xattr_acl_default_handler, +#ifdef CONFIG_FS_POSIX_ACL + &posix_acl_access_xattr_handler, + &posix_acl_default_xattr_handler, #endif #ifdef CONFIG_9P_FS_SECURITY &v9fs_xattr_security_handler,
fs/9p/xattr.h +0 -2
@@ -11,8 +11,6 @@#include <net/9p/client.h> extern const struct xattr_handler *v9fs_xattr_handlers[]; -extern const struct xattr_handler v9fs_xattr_acl_access_handler; -extern const struct xattr_handler v9fs_xattr_acl_default_handler;ssize_t v9fs_fid_xattr_get (struct p9_fid *fid,const char *name,void *buffer,size_t buffer_size);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH v2 30/30 acl: remove a slew of now unused helpers
In reply to Christian BraunerNow that the posix acl api is active we can remove all the hacky helpers we had to keep around for all these years and also remove the set and get posix acl xattr handler methods as they aren't needed anymore.
---
Notes:
/* v2 */
unchangedfs/posix_acl.c | 363 ++------------------------------ fs/xattr.c | 5 +- include/linux/posix_acl_xattr.h | 20 -- 3 files changed, 23 insertions(+), 365 deletions(-)
fs/posix_acl.c +22 -341
@@ -744,118 +744,32 @@ static int posix_acl_fix_xattr_common(const void *value, size_t size)return count; } -void posix_acl_getxattr_idmapped_mnt (struct user_namespace *mnt_userns, -const struct inode *inode, -void *value,size_t size) -{ -struct posix_acl_xattr_header *header = value; -struct posix_acl_xattr_entry *entry = (void *)(header +1 ), *end; -struct user_namespace *fs_userns =i_user_ns (inode); -int count; -vfsuid_t vfsuid; -vfsgid_t vfsgid; -kuid_t uid; -kgid_t gid; - -if (no_idmapping (mnt_userns,i_user_ns (inode))) -return ; - - count =posix_acl_fix_xattr_common (value, size); -if (count <=0 ) -return ; - -for (end = entry + count; entry != end; entry++) { -switch (le16_to_cpu (entry->e_tag)) { -case ACL_USER : - uid =make_kuid (&init_user_ns,le32_to_cpu (entry->e_id)); - vfsuid =make_vfsuid (mnt_userns, fs_userns, uid); - entry->e_id =cpu_to_le32 (from_kuid (&init_user_ns, -vfsuid_into_kuid (vfsuid))); -break ; -case ACL_GROUP : - gid =make_kgid (&init_user_ns,le32_to_cpu (entry->e_id)); - vfsgid =make_vfsgid (mnt_userns, fs_userns, gid); - entry->e_id =cpu_to_le32 (from_kgid (&init_user_ns, -vfsgid_into_kgid (vfsgid))); -break ; -default : -break ; - } - } -} - -static void posix_acl_fix_xattr_userns ( -struct user_namespace *to,struct user_namespace *from, -void *value,size_t size) -{ -struct posix_acl_xattr_header *header = value; -struct posix_acl_xattr_entry *entry = (void *)(header +1 ), *end; -int count; -kuid_t uid; -kgid_t gid; - - count =posix_acl_fix_xattr_common (value, size); -if (count <=0 ) -return ; - -for (end = entry + count; entry != end; entry++) { -switch (le16_to_cpu (entry->e_tag)) { -case ACL_USER : - uid =make_kuid (from,le32_to_cpu (entry->e_id)); - entry->e_id =cpu_to_le32 (from_kuid (to, uid)); -break ; -case ACL_GROUP : - gid =make_kgid (from,le32_to_cpu (entry->e_id)); - entry->e_id =cpu_to_le32 (from_kgid (to, gid)); -break ; -default : -break ; - } - } -} - -void posix_acl_fix_xattr_from_user (void *value,size_t size) -{ -struct user_namespace *user_ns =current_user_ns (); -if (user_ns == &init_user_ns) -return ; -posix_acl_fix_xattr_userns (&init_user_ns, user_ns, value, size); -} - -void posix_acl_fix_xattr_to_user (void *value,size_t size) -{ -struct user_namespace *user_ns =current_user_ns (); -if (user_ns == &init_user_ns) -return ; -posix_acl_fix_xattr_userns (user_ns, &init_user_ns, value, size); -} -/** -* make_posix_acl - convert POSIX ACLs from uapi to VFS format using the -* provided callbacks to map ACL_{GROUP,USER} entries into the -* appropriate format -* @mnt_userns: the mount's idmapping -* @fs_userns: the filesystem's idmapping +* posix_acl_from_xattr - convert POSIX ACLs from backing store to VFS format +* @userns: the filesystem's idmapping * @value: the uapi representation of POSIX ACLs * @size: the size of @void -* @uid_cb: callback to use for mapping the uid stored in ACL_USER entries -* @gid_cb: callback to use for mapping the gid stored in ACL_GROUP entries * -* The make_posix_acl() helper is an abstraction to translate from uapi format -* into the VFS format allowing the caller to specific callbacks to map -* ACL_{GROUP,USER} entries into the expected format. This is used in -* posix_acl_from_xattr() and vfs_set_acl_prepare() and avoids pointless code -* duplication. +* Filesystems that store POSIX ACLs in the unaltered uapi format should use +* posix_acl_from_xattr() when reading them from the backing store and +* converting them into the struct posix_acl VFS format. The helper is +* specifically intended to be called from the acl inode operation. +* +* The posix_acl_from_xattr() function will map the raw {g,u}id values stored +* in ACL_{GROUP,USER} entries into idmapping in @userns. +* +* Note that posix_acl_from_xattr() does not take idmapped mounts into account. +* If it did it calling it from the get acl inode operation would return POSIX +* ACLs mapped according to an idmapped mount which would mean that the value +* couldn't be cached for the filesystem. Idmapped mounts are taken into +* account on the fly during permission checking or right at the VFS - +* userspace boundary before reporting them to the user. * * Return: Allocated struct posix_acl on success, NULL for a valid header but * without actual POSIX ACL entries, or ERR_PTR() encoded error code. */ -static struct posix_acl *make_posix_acl (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns,const void *value,size_t size, -kuid_t (*uid_cb)(struct user_namespace *,struct user_namespace *, -const struct posix_acl_xattr_entry *), -kgid_t (*gid_cb)(struct user_namespace *,struct user_namespace *, -const struct posix_acl_xattr_entry *)) +struct posix_acl *posix_acl_from_xattr (struct user_namespace *userns, +const void *value,size_t size) {const struct posix_acl_xattr_header *header = value;const struct posix_acl_xattr_entry *entry = (const void *)(header +1 ), *end;
@@ -886,12 +800,14 @@ static struct posix_acl *make_posix_acl(struct user_namespace *mnt_userns,break ;case ACL_USER : - acl_e->e_uid =uid_cb (mnt_userns, fs_userns, entry); + acl_e->e_uid =make_kuid (userns, +le32_to_cpu (entry->e_id));if (!uid_valid (acl_e->e_uid)) goto fail;break ;case ACL_GROUP : - acl_e->e_gid =gid_cb (mnt_userns, fs_userns, entry); + acl_e->e_gid =make_kgid (userns, +le32_to_cpu (entry->e_id));if (!gid_valid (acl_e->e_gid)) goto fail;break ;
@@ -906,182 +822,6 @@ static struct posix_acl *make_posix_acl(struct user_namespace *mnt_userns,posix_acl_release (acl);return ERR_PTR (-EINVAL ); } - -/** -* vfs_set_acl_prepare_kuid - map ACL_USER uid according to mount- and -* filesystem idmapping -* @mnt_userns: the mount's idmapping -* @fs_userns: the filesystem's idmapping -* @e: a ACL_USER entry in POSIX ACL uapi format -* -* The uid stored as ACL_USER entry in @e is a kuid_t stored as a raw {g,u}id -* value. The vfs_set_acl_prepare_kuid() will recover the kuid_t through -* KUIDT_INIT() and then map it according to the idmapped mount. The resulting -* kuid_t is the value which the filesystem can map up into a raw backing store -* id in the filesystem's idmapping. -* -* This is used in vfs_set_acl_prepare() to generate the proper VFS -* representation of POSIX ACLs with ACL_USER entries during setxattr(). -* -* Return: A kuid in @fs_userns for the uid stored in @e. -*/ -static inline kuid_t -vfs_set_acl_prepare_kuid (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns, -const struct posix_acl_xattr_entry *e) -{ -kuid_t kuid =KUIDT_INIT (le32_to_cpu (e->e_id)); -return from_vfsuid (mnt_userns, fs_userns,VFSUIDT_INIT (kuid)); -} - -/** -* vfs_set_acl_prepare_kgid - map ACL_GROUP gid according to mount- and -* filesystem idmapping -* @mnt_userns: the mount's idmapping -* @fs_userns: the filesystem's idmapping -* @e: a ACL_GROUP entry in POSIX ACL uapi format -* -* The gid stored as ACL_GROUP entry in @e is a kgid_t stored as a raw {g,u}id -* value. The vfs_set_acl_prepare_kgid() will recover the kgid_t through -* KGIDT_INIT() and then map it according to the idmapped mount. The resulting -* kgid_t is the value which the filesystem can map up into a raw backing store -* id in the filesystem's idmapping. -* -* This is used in vfs_set_acl_prepare() to generate the proper VFS -* representation of POSIX ACLs with ACL_GROUP entries during setxattr(). -* -* Return: A kgid in @fs_userns for the gid stored in @e. -*/ -static inline kgid_t -vfs_set_acl_prepare_kgid (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns, -const struct posix_acl_xattr_entry *e) -{ -kgid_t kgid =KGIDT_INIT (le32_to_cpu (e->e_id)); -return from_vfsgid (mnt_userns, fs_userns,VFSGIDT_INIT (kgid)); -} - -/** -* vfs_set_acl_prepare - convert POSIX ACLs from uapi to VFS format taking -* mount and filesystem idmappings into account -* @mnt_userns: the mount's idmapping -* @fs_userns: the filesystem's idmapping -* @value: the uapi representation of POSIX ACLs -* @size: the size of @void -* -* When setting POSIX ACLs with ACL_{GROUP,USER} entries they need to be -* mapped according to the relevant mount- and filesystem idmapping. It is -* important that the ACL_{GROUP,USER} entries in struct posix_acl will be -* mapped into k{g,u}id_t that are supposed to be mapped up in the filesystem -* idmapping. This is crucial since the resulting struct posix_acl might be -* cached filesystem wide. The vfs_set_acl_prepare() function will take care to -* perform all necessary idmappings. -* -* Note, that since basically forever the {g,u}id values encoded as -* ACL_{GROUP,USER} entries in the uapi POSIX ACLs passed via @value contain -* values that have been mapped according to the caller's idmapping. In other -* words, POSIX ACLs passed in uapi format as @value during setxattr() contain -* {g,u}id values in their ACL_{GROUP,USER} entries that should actually have -* been stored as k{g,u}id_t. -* -* This means, vfs_set_acl_prepare() needs to first recover the k{g,u}id_t by -* calling K{G,U}IDT_INIT(). Afterwards they can be interpreted as vfs{g,u}id_t -* through from_vfs{g,u}id() to account for any idmapped mounts. The -* vfs_set_acl_prepare_k{g,u}id() helpers will take care to generate the -* correct k{g,u}id_t. -* -* The filesystem will then receive the POSIX ACLs ready to be cached -* filesystem wide and ready to be written to the backing store taking the -* filesystem's idmapping into account. -* -* Return: Allocated struct posix_acl on success, NULL for a valid header but -* without actual POSIX ACL entries, or ERR_PTR() encoded error code. -*/ -struct posix_acl *vfs_set_acl_prepare (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns, -const void *value,size_t size) -{ -return make_posix_acl (mnt_userns, fs_userns, value, size, - vfs_set_acl_prepare_kuid, - vfs_set_acl_prepare_kgid); -} -EXPORT_SYMBOL (vfs_set_acl_prepare); - -/** -* posix_acl_from_xattr_kuid - map ACL_USER uid into filesystem idmapping -* @mnt_userns: unused -* @fs_userns: the filesystem's idmapping -* @e: a ACL_USER entry in POSIX ACL uapi format -* -* Map the uid stored as ACL_USER entry in @e into the filesystem's idmapping. -* This is used in posix_acl_from_xattr() to generate the proper VFS -* representation of POSIX ACLs with ACL_USER entries. -* -* Return: A kuid in @fs_userns for the uid stored in @e. -*/ -static inline kuid_t -posix_acl_from_xattr_kuid (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns, -const struct posix_acl_xattr_entry *e) -{ -return make_kuid (fs_userns,le32_to_cpu (e->e_id)); -} - -/** -* posix_acl_from_xattr_kgid - map ACL_GROUP gid into filesystem idmapping -* @mnt_userns: unused -* @fs_userns: the filesystem's idmapping -* @e: a ACL_GROUP entry in POSIX ACL uapi format -* -* Map the gid stored as ACL_GROUP entry in @e into the filesystem's idmapping. -* This is used in posix_acl_from_xattr() to generate the proper VFS -* representation of POSIX ACLs with ACL_GROUP entries. -* -* Return: A kgid in @fs_userns for the gid stored in @e. -*/ -static inline kgid_t -posix_acl_from_xattr_kgid (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns, -const struct posix_acl_xattr_entry *e) -{ -return make_kgid (fs_userns,le32_to_cpu (e->e_id)); -} - -/** -* posix_acl_from_xattr - convert POSIX ACLs from backing store to VFS format -* @fs_userns: the filesystem's idmapping -* @value: the uapi representation of POSIX ACLs -* @size: the size of @void -* -* Filesystems that store POSIX ACLs in the unaltered uapi format should use -* posix_acl_from_xattr() when reading them from the backing store and -* converting them into the struct posix_acl VFS format. The helper is -* specifically intended to be called from the ->get_inode_acl() inode -* operation. -* -* The posix_acl_from_xattr() function will map the raw {g,u}id values stored -* in ACL_{GROUP,USER} entries into the filesystem idmapping in @fs_userns. The -* posix_acl_from_xattr_k{g,u}id() helpers will take care to generate the -* correct k{g,u}id_t. The returned struct posix_acl can be cached. -* -* Note that posix_acl_from_xattr() does not take idmapped mounts into account. -* If it did it calling is from the ->get_inode_acl() inode operation would -* return POSIX ACLs mapped according to an idmapped mount which would mean -* that the value couldn't be cached for the filesystem. Idmapped mounts are -* taken into account on the fly during permission checking or right at the VFS -* - userspace boundary before reporting them to the user. -* -* Return: Allocated struct posix_acl on success, NULL for a valid header but -* without actual POSIX ACL entries, or ERR_PTR() encoded error code. -*/ -struct posix_acl * -posix_acl_from_xattr (struct user_namespace *fs_userns, -const void *value,size_t size) -{ -return make_posix_acl (&init_user_ns, fs_userns, value, size, - posix_acl_from_xattr_kuid, - posix_acl_from_xattr_kgid); -}EXPORT_SYMBOL (posix_acl_from_xattr);/*
@@ -1187,31 +927,6 @@ ssize_t vfs_posix_acl_to_xattr(struct user_namespace *mnt_userns,return real_size; } -static int -posix_acl_xattr_get (const struct xattr_handler *handler, -struct dentry *unused,struct inode *inode, -const char *name,void *value,size_t size) -{ -struct posix_acl *acl; -int error; - -if (!IS_POSIXACL (inode)) -return -EOPNOTSUPP ; -if (S_ISLNK (inode->i_mode)) -return -EOPNOTSUPP ; - - acl =get_acl (inode, handler->flags); -if (IS_ERR (acl)) -return PTR_ERR (acl); -if (acl ==NULL ) -return -ENODATA ; - - error =posix_acl_to_xattr (&init_user_ns, acl, value, size); -posix_acl_release (acl); - -return error; -} -int set_posix_acl (struct user_namespace *mnt_userns,struct dentry *dentry,int type,struct posix_acl *acl)
@@ -1237,36 +952,6 @@ set_posix_acl(struct user_namespace *mnt_userns, struct dentry *dentry, }EXPORT_SYMBOL (set_posix_acl); -static int -posix_acl_xattr_set (const struct xattr_handler *handler, -struct user_namespace *mnt_userns, -struct dentry *dentry,struct inode *inode, -const char *name,const void *value,size_t size, -int flags) -{ -struct posix_acl *acl =NULL ; -int ret; - -if (value) { -/* -* By the time we end up here the {g,u}ids stored in -* ACL_{GROUP,USER} have already been mapped according to the -* caller's idmapping. The vfs_set_acl_prepare() helper will -* recover them and take idmapped mounts into account. The -* filesystem will receive the POSIX ACLs in the correct -* format ready to be cached or written to the backing store -* taking the filesystem idmapping into account. -*/ - acl =vfs_set_acl_prepare (mnt_userns,i_user_ns (inode), - value, size); -if (IS_ERR (acl)) -return PTR_ERR (acl); - } - ret =set_posix_acl (mnt_userns, dentry, handler->flags, acl); -posix_acl_release (acl); -return ret; -} -static bool posix_acl_xattr_list (struct dentry *dentry) {
@@ -1277,8 +962,6 @@ const struct xattr_handler posix_acl_access_xattr_handler = { .name = XATTR_NAME_POSIX_ACL_ACCESS, .flags = ACL_TYPE_ACCESS, .list = posix_acl_xattr_list, - .get = posix_acl_xattr_get, - .set = posix_acl_xattr_set, };EXPORT_SYMBOL_GPL (posix_acl_access_xattr_handler);
@@ -1286,8 +969,6 @@ const struct xattr_handler posix_acl_default_xattr_handler = { .name = XATTR_NAME_POSIX_ACL_DEFAULT, .flags = ACL_TYPE_DEFAULT, .list = posix_acl_xattr_list, - .get = posix_acl_xattr_get, - .set = posix_acl_xattr_set, };EXPORT_SYMBOL_GPL (posix_acl_default_xattr_handler);
fs/xattr.c +1 -4
@@ -436,10 +436,7 @@ vfs_getxattr(struct user_namespace *mnt_userns, struct dentry *dentry,return ret; } nolsm: - error =__vfs_getxattr (dentry, inode, name, value, size); -if (error >0 &&is_posix_acl_xattr (name)) -posix_acl_getxattr_idmapped_mnt (mnt_userns, inode, value, size); -return error; +return __vfs_getxattr (dentry, inode, name, value, size); }EXPORT_SYMBOL_GPL (vfs_getxattr);
include/linux/posix_acl_xattr.h +0 -20
@@ -35,11 +35,6 @@ posix_acl_xattr_count(size_t size)#ifdef CONFIG_FS_POSIX_ACL struct posix_acl *posix_acl_from_xattr (struct user_namespace *user_ns,const void *value,size_t size); -void posix_acl_fix_xattr_from_user (void *value,size_t size); -void posix_acl_fix_xattr_to_user (void *value,size_t size); -void posix_acl_getxattr_idmapped_mnt (struct user_namespace *mnt_userns, -const struct inode *inode, -void *value,size_t size);ssize_t vfs_posix_acl_to_xattr (struct user_namespace *mnt_userns,struct inode *inode,const struct posix_acl *acl,void *buffer,size_t size);
@@ -50,18 +45,6 @@ posix_acl_from_xattr(struct user_namespace *user_ns, const void *value, {return ERR_PTR (-EOPNOTSUPP ); } -static inline void posix_acl_fix_xattr_from_user (void *value,size_t size) -{ -} -static inline void posix_acl_fix_xattr_to_user (void *value,size_t size) -{ -} -static inline void -posix_acl_getxattr_idmapped_mnt (struct user_namespace *mnt_userns, -const struct inode *inode,void *value, -size_t size) -{ -} static inline ssize_t vfs_posix_acl_to_xattr(struct user_namespace *mnt_userns, struct inode *inode, const struct posix_acl *acl,
@@ -73,9 +56,6 @@ static inline ssize_t vfs_posix_acl_to_xattr(struct user_namespace *mnt_userns,int posix_acl_to_xattr (struct user_namespace *user_ns,const struct posix_acl *acl,void *buffer,size_t size); -struct posix_acl *vfs_set_acl_prepare (struct user_namespace *mnt_userns, -struct user_namespace *fs_userns, -const void *value,size_t size);static inline const char *posix_acl_xattr_name (int type) {switch (type) {
Signature · 1 line
2.34.1
Casey Schaufler
maintainerQuoted 30 lines · Christian Brauner
From: "Christian Brauner (Microsoft)" <[email protected]>
Hey everyone,
/* v2 */
This fixes various things pointed out during review. The individual commits contain more details were appropriate.As we discussed and seen multiple times the current state of how posix acls are handled isn't nice and comes with a lot of problems. For a long and detailed explanation for just some of the issues [1] provides a good summary.
The current way of handling posix acls via the generic xattr api is error prone, hard to maintain, and type unsafe for the vfs until we call into the filesystem's dedicated get and set inode operations.
It is already the case that posix acls are special-cased to death all the way through the vfs. There are an uncounted number of hacks that operate on the uapi posix acl struct instead of the dedicated vfs struct
posix_acl. And the vfs must be involved in order to interpret and fixup posix acls before storing them to the backing store, caching them, reporting them to userspace, or for permission checking.Currently a range of hacks and duct tape exist to make this work. As with most things this is really no ones fault it's just something that happened over time. But the code is hard to understand and difficult to maintain and one is constantly at risk of introducing bugs and regressions when having to touch it.
Quoted 8 lines
Instead of continuing to hack posix acls through the xattr handlers this series builds a dedicated posix acl api solely around the get and set inode operations. Going forward, the
vfs_get_acl(),vfs_remove_acl(), andvfs_set_acl()helpers must be used in order to interact with posix acls. They operate directly on the vfs internal structposix_aclinstead of abusing the uapi posix acl struct as we currently do. In the end this removes all of the hackiness, makes the codepaths easier to maintain, and gets us type safety.
I may have missed something obvious, but from the LSM side the only place where the ACL handling differs from general xattr handling in in EVM. This seems like a lot of "clean-up" to address that one special case. Especially since EVM isn't (currently) an LSM. I'll admit that a future LSM might look into the posix acl, although looking at another security feature's data is hardly encouraged. EVM, which is all about protecting the content of other security data is kind of exceptional in that.
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Quoted 280 lines
This series passes the LTP and xfstests suites without any regressions. For xfstests the following combinations were tested:
* xfs
* ext4
* btrfs
* overlayfs
* overlayfs on top of idmapped mountsFor people wanting to run their own xfstests I'd recommend to shorten their test runs via:
./check -g acl,attr,cap,idmapped,io_uring,perms,subvol,unlink
I would appreciate if the 9p and cifs folks could run any posix acl related tests as I have no setup to really do this without causing me a lot of pain.
Very likely there's a lot more simplifications for posix acls that we can make in the future if the basic api has made it.
A few implementation details:
* The series makes sure to retain exactly the same security and integrity module permission checks. See [2] for annotated callchains. Especially for the integrity modules this api is a win because right now they convert the uapi posix acl struct passed to them via a void pointer into the vfs struct
posix_aclformat to perform permission checking on the mode.There's a new dedicated security hook for setting posix acls which passes the vfs struct
posix_aclnot a void pointer. Basing checking on the posix acl stored in the uapi format is really unreliable. The vfs currently hacks around directly in the uapi struct storing values that frankly the security and integrity modules can't correctly interpret as evidenced by bugs we reported and fixed in this area. It's not necessarily even their fault it's just that the format we provide to them is sub optimal.* Some filesystems like 9p and cifs need access to the dentry in order to get and set posix acls which is why they either only partially or not even at all implement get and set inode operations. For example, cifs allows
setxattr()andgetxattr()operations but doesn't allow permission checking based on posix acls because it can't implement a get acl inode operation.Thus, this patch series updates the set acl inode operation to take a dentry instead of an inode argument. However, for the get acl inode operation we can't do this as the old get acl method is called in e.g.,
generic_permission()andinode_permission(). These helpers in turn are called in various filesystem's permission inode operation. So passing a dentry argument to the old get acl inode operation would amount to passing a dentry to the permission inode operation which we shouldn't and probably can't do.So instead of extending the existing inode operation Christoph suggested to add a new one. He also requested to ensure that the get and set acl inode operation taking a dentry are consistently named. So for this version the old get acl operation is renamed to ->get_inode_acl() and a new ->get_acl() inode operation taking a dentry is added. With this we can give both 9p and cifs get and set acl inode operations and in turn remove their complex custom posix xattr handlers.
* I've done a full audit of every codepaths using variant of the current generic xattr api to get and set posix acls and surprisingly it isn't that many places. There's of course always a chance that I might have missed some and I'm sure we'll find them soon enough.
The crucial codepaths to be converted are obviously stacking filesystems such as ecryptfs and overlayfs.
For a list of all callers currently using generic xattr api helpers see [2] including comments whether they support posix acls or not.
* The old vfs generic posix acl infrastructure doesn't obey the create and replace semantics promised on the setxattr(2) manpage. This patch series doesn't address this. It really is something we should revisit later though.
The patch series is roughly organized as follows:
// intended to be a non-functional change
1. Change existing set acl inode operation to take a dentry argument.// intended to be a non-functional change
2. Rename existing get acl method.// intended to be a non-functional change
3. Implement get and set acl inode operations for filesystems that couldn't implement one before because of the missing dentry. That's mostly 9p and cifs.// intended to be a non-functional change
4. Build posix acl api, i.e., addvfs_get_acl(),vfs_remove_acl(), andvfs_set_acl()including security and integrity hooks.// intended to be a non-functional change
5. Implement get and set acl inode operations for stacking filesystems.// semantical change
6. Switch posix acl handling in stacking filesystems to new posix acl api now that all filesystems it can stack upon support it.// semantical change
7. Switch vfs to new posix acl api8. Remove all now unused helpers
The series can be pulled from:
https://gitlab.com/brauner/linux/-/commits/fs.acl.rework
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping.git/log/?h=fs.acl.reworkThe series contains a few preliminary patches which are scheduled for the next merge window. It was just easier to base the series on top of them. But if you pull this branch you'll get them included.
I've been working on this for a while and before going any further it'd be nice to get some reviews. I think that it should be fine to have get and set acl inode operations that operate on the dentry at least nothing stuck out immediately that would prevent this. But obviously having other people point out issues with that would be helpful.
Thanks to Seth for a lot of good discussion around this and encouragement and input from Christoph.
[1]: https://lore.kernel.org/all/[email protected]
[2]: https://gist.github.com/brauner/12c795b93a05dc3b3056b1982549a633v1: https://lore.kernel.org/linux-cifs/[email protected]
Thanks!
ChristianChristian Brauner (30):
orangefs: rework posix acl handling when creating new filesystem
objects
fs: pass dentry to set acl method
fs: rename current get acl method
fs: add new get acl method
cifs: implement get acl method
cifs: implement set acl method
9p: implement get acl method
9p: implement set acl method
acl: addvfs_set_acl()
security: add set acl hook
selinux: implement set acl hook
smack: implement set acl hook
evm: implement set acl hook
acl: use set acl hook
evm: add post set acl hook
acl: addvfs_get_acl()
acl: addvfs_remove_acl()
evm: simplifyevm_xattr_acl_change()
ksmbd: usevfs_remove_acl()
ecryptfs: implement get acl method
ecryptfs: implement set acl method
ovl: implement get acl method
ovl: implement set acl method
ovl: use posix acl api
xattr: use posix acl api
ecryptfs: use stub posix acl handlers
ovl: use stub posix acl handlers
cifs: use stub posix acl handlers
9p: use stub posix acl handlers
acl: remove a slew of now unused helpersDocumentation/filesystems/locking.rst | 4 +- Documentation/filesystems/porting.rst | 4 +- Documentation/filesystems/vfs.rst | 3 +- fs/9p/acl.c | 295 +++++------ fs/9p/acl.h | 8 +- fs/9p/vfs_inode_dotl.c | 4 + fs/9p/xattr.c | 7 +- fs/9p/xattr.h | 2 - fs/bad_inode.c | 4 +- fs/btrfs/acl.c | 3 +- fs/btrfs/ctree.h | 2 +- fs/btrfs/inode.c | 8 +- fs/ceph/acl.c | 3 +- fs/ceph/dir.c | 2 +- fs/ceph/inode.c | 4 +- fs/ceph/super.h | 2 +- fs/cifs/cifsacl.c | 141 ++++++ fs/cifs/cifsfs.c | 4 + fs/cifs/cifsproto.h | 20 +- fs/cifs/cifssmb.c | 206 +++++--- fs/cifs/xattr.c | 68 +-- fs/ecryptfs/inode.c | 32 ++ fs/erofs/inode.c | 6 +- fs/erofs/namei.c | 2 +- fs/ext2/acl.c | 3 +- fs/ext2/acl.h | 2 +- fs/ext2/file.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext2/namei.c | 4 +- fs/ext4/acl.c | 3 +- fs/ext4/acl.h | 2 +- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 2 +- fs/ext4/namei.c | 4 +- fs/f2fs/acl.c | 4 +- fs/f2fs/acl.h | 2 +- fs/f2fs/file.c | 4 +- fs/f2fs/namei.c | 4 +- fs/fuse/acl.c | 3 +- fs/fuse/dir.c | 4 +- fs/fuse/fuse_i.h | 2 +- fs/gfs2/acl.c | 3 +- fs/gfs2/acl.h | 2 +- fs/gfs2/inode.c | 6 +- fs/internal.h | 1 + fs/jffs2/acl.c | 3 +- fs/jffs2/acl.h | 2 +- fs/jffs2/dir.c | 2 +- fs/jffs2/file.c | 2 +- fs/jffs2/fs.c | 2 +- fs/jfs/acl.c | 3 +- fs/jfs/file.c | 4 +- fs/jfs/jfs_acl.h | 2 +- fs/jfs/namei.c | 2 +- fs/ksmbd/smb2pdu.c | 4 +- fs/ksmbd/smbacl.c | 4 +- fs/ksmbd/vfs.c | 17 +- fs/ksmbd/vfs.h | 4 +- fs/namei.c | 2 +- fs/nfs/nfs3_fs.h | 2 +- fs/nfs/nfs3acl.c | 3 +- fs/nfs/nfs3proc.c | 4 +- fs/nfsd/nfs2acl.c | 4 +- fs/nfsd/nfs3acl.c | 4 +- fs/nfsd/vfs.c | 4 +- fs/ntfs3/file.c | 4 +- fs/ntfs3/namei.c | 4 +- fs/ntfs3/ntfs_fs.h | 4 +- fs/ntfs3/xattr.c | 9 +- fs/ocfs2/acl.c | 3 +- fs/ocfs2/acl.h | 2 +- fs/ocfs2/file.c | 4 +- fs/ocfs2/namei.c | 2 +- fs/orangefs/acl.c | 47 +- fs/orangefs/inode.c | 47 +- fs/orangefs/namei.c | 2 +- fs/orangefs/orangefs-kernel.h | 9 +- fs/orangefs/orangefs-utils.c | 12 +- fs/overlayfs/copy_up.c | 38 ++ fs/overlayfs/dir.c | 22 +- fs/overlayfs/inode.c | 151 +++++- fs/overlayfs/overlayfs.h | 34 +- fs/overlayfs/super.c | 107 +--- fs/posix_acl.c | 681 +++++++++++++------------- fs/reiserfs/acl.h | 6 +- fs/reiserfs/file.c | 2 +- fs/reiserfs/inode.c | 2 +- fs/reiserfs/namei.c | 4 +- fs/reiserfs/xattr_acl.c | 9 +- fs/xattr.c | 78 ++- fs/xfs/xfs_acl.c | 3 +- fs/xfs/xfs_acl.h | 2 +- fs/xfs/xfs_iops.c | 16 +- include/linux/evm.h | 23 + include/linux/fs.h | 10 +- include/linux/lsm_hook_defs.h | 2 + include/linux/lsm_hooks.h | 4 + include/linux/posix_acl.h | 39 +- include/linux/posix_acl_xattr.h | 43 +- include/linux/security.h | 11 + include/linux/xattr.h | 8 + io_uring/xattr.c | 2 + mm/shmem.c | 2 +- security/integrity/evm/evm_main.c | 128 +++-- security/security.c | 16 + security/selinux/hooks.c | 8 + security/smack/smack_lsm.c | 24 + 107 files changed, 1550 insertions(+), 1043 deletions(-)base-commit:
38e316398e4e6338b80223fb5f74415c0513718f
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Christian Brauner
maintainerQuoted 5 lines · Christoph Hellwig
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Quoted 7 lines
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Agreed.
Casey Schaufler
maintainerQuoted 11 lines · Christoph Hellwig
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Here's the problem I see. All of the LSMs see xattrs, except for their own, as opaque objects. Introducing LSM hooks to address the data interpretation issues between VFS and EVM, which is not an LSM, adds to an already overlarge and interface. And the "real" users of the interface don't need the new hook. I'm not saying that the ACL doesn't have problems. I'm not saying that the solution you've proposed isn't better than what's there now. I am saying that using LSM as a conduit between VFS and EVM at the expense of the rest of the modules is dubious. A lot of change to LSM for no value to LSM.
I am not adamant about this. A whole lot worse has been done for worse reasons. But as Paul says, we're overdue to make an effort to keep the LSM interface sane.
Quoted 22 lines · Casey Schaufler
Quoted 11 lines · Christoph Hellwig
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Here's the problem I see. All of the LSMs see xattrs, except for their own, as opaque objects. Introducing LSM hooks to address the data interpretation issues between VFS and EVM, which is not an LSM, adds to an already overlarge and interface. And the "real" users of the interface don't need the new hook. I'm not saying that the ACL doesn't have problems. I'm not saying that the solution you've proposed isn't better than what's there now. I am saying that using LSM as a conduit between VFS and EVM at the expense of the rest of the modules is dubious. A lot of change to LSM for no value to LSM.
Quoted 2 lines
I am not adamant about this. A whole lot worse has been done for worse reasons. But as Paul says, we're overdue to make an effort to keep the LSM interface sane.
So I assume the alternative you have in mind would be to use the existing setxattr hook? I worry about type confusion if an LSM does someday want to look inside the ACL data. Unless LSMs aren't supposed to look inside of xattr data, but in that case why pass the data pointer on to the LSMs?
Note that the caller of this new hook does not have access to the uapi xattr data, and I think this is the right place for the new hook to be called as it's the interface that stacked filesystems like overlayfs will use to write ACLs to the lower filesystems.
Seth
Casey Schaufler
maintainerQuoted 22 lines · Seth Forshee
Quoted 21 lines · Casey Schaufler
Quoted 11 lines · Christoph Hellwig
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Here's the problem I see. All of the LSMs see xattrs, except for their own, as opaque objects. Introducing LSM hooks to address the data interpretation issues between VFS and EVM, which is not an LSM, adds to an already overlarge and interface. And the "real" users of the interface don't need the new hook. I'm not saying that the ACL doesn't have problems. I'm not saying that the solution you've proposed isn't better than what's there now. I am saying that using LSM as a conduit between VFS and EVM at the expense of the rest of the modules is dubious. A lot of change to LSM for no value to LSM.
Quoted 4 lines
Quoted 2 lines
I am not adamant about this. A whole lot worse has been done for worse reasons. But as Paul says, we're overdue to make an effort to keep the LSM interface sane.
So I assume the alternative you have in mind would be to use the existing setxattr hook?
That is how it works today.
Quoted 2 lines
I worry about type confusion if an LSM does
someday want to look inside the ACL data.
I suggest that changes to system behavior based on the content of an ACL really belongs in the ACL code, not in an LSM. Can I imagine someone wanting to add SELinux policy that controls what entries are allowed to be set by a particular domain? Sure, but I can't see how that would be popular with existing ACL fans.
Quoted 3 lines
Unless LSMs aren't supposed to
look inside of xattr data, but in that case why pass the data pointer on to the LSMs?
So that the LSM can look at it's own xattr data.
Quoted 4 lines
Note that the caller of this new hook does not have access to the uapi xattr data, and I think this is the right place for the new hook to be called as it's the interface that stacked filesystems like overlayfs will use to write ACLs to the lower filesystems.
I'm not saying anything about the organization of the calling code. Why is it calling
security_acl_hooha(...)
instead of
evm_acl_hooha(...)
Quoted 2 lines
Seth
Paul Moore
maintainerRe: [PATCH v2 16/30] acl: add vfs_get_acl()
In reply to Christian BraunerQuoted 27 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_get_acl()api that can be used to get posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 131 ++++++++++++++++++++++++++++++-- include/linux/posix_acl.h | 9 +++ include/linux/posix_acl_xattr.h | 10 +++ 3 files changed, 142 insertions(+), 8 deletions(-)
...
Quoted 28 lines
fs/posix_acl.c +20
-0@@ -1369,3 +1439,48 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,return error; }EXPORT_SYMBOL (vfs_set_acl); + +/** +* vfs_get_acl - get posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function retrieves @kacl from the filesystem. The caller must all +* posix_acl_release() on @kacl. +* +* Return: On success POSIX ACLs in VFS format, on error negative errno. +*/ +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +struct inode *inode =d_inode (dentry); +struct posix_acl *acl; +int acl_type, error; + + acl_type =posix_acl_type (acl_name);
fs/posix_acl.c int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, · line 1471
Quoted 10 lines
fs/posix_acl.c +10
-0+if (acl_type <0 ) +return ERR_PTR (-EINVAL ); + +/* +* The VFS has no restrictions on reading POSIX ACLs so calling +* something like xattr_permission() isn't needed. Only LSMs get a say. +*/ + error =security_inode_getxattr (dentry, acl_name); +if (error) +return ERR_PTR (error);
I understand the desire to reuse the security_inode_getxattr() hook here, it makes perfect sense, but given that this patchset introduces an ACL specific setter hook I think it makes sense to have a matching getter hook. It's arguably a little silly given the current crop of LSMs and their approach to ACLs, but if we are going to differentiate on the write side I think we might as well be consistent and differentiate on the read side as well.
Quoted 4 lines
fs/posix_acl.c +4
-0+if (!IS_POSIXACL (inode)) +return ERR_PTR (-EOPNOTSUPP ); +if (S_ISLNK (inode->i_mode)) +return ERR_PTR (-EOPNOTSUPP );
fs/posix_acl.c int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, · line 1486
Quoted 10 lines
fs/posix_acl.c +10
-0+ + acl =__get_acl (mnt_userns, dentry, inode, acl_type); +if (IS_ERR (acl)) +return acl; +if (!acl) +return ERR_PTR (-ENODATA ); + +return acl; +} +EXPORT_SYMBOL (vfs_get_acl);
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH v2 17/30] acl: add vfs_remove_acl()
In reply to Christian BraunerQuoted 26 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_remove_acl()api that can be used to set posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 65 +++++++++++++++++++++++++++++++++++++++ include/linux/posix_acl.h | 8 +++++ 2 files changed, 73 insertions(+)
...
Quoted 35 lines
fs/posix_acl.c +27
-0@@ -1484,3 +1484,68 @@ struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns,return acl; }EXPORT_SYMBOL (vfs_get_acl); + +/** +* vfs_remove_acl - remove posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function removes posix acls. +* +* Return: On success 0, on error negative errno. +*/ +int vfs_remove_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +const char *acl_name) +{ +int acl_type; +int error; +struct inode *inode =d_inode (dentry); +struct inode *delegated_inode =NULL ; + + acl_type =posix_acl_type (acl_name); +if (acl_type <0 ) +return -EINVAL ; + +retry_deleg: +inode_lock (inode); + +/*
fs/posix_acl.c struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns, · line 1523
Quoted 10 lines
fs/posix_acl.c +10
-0+* We only care about restrictions the inode struct itself places upon +* us otherwise POSIX ACLs aren't subject to any VFS restrictions. +*/ + error =xattr_permission (mnt_userns, inode, acl_name,MAY_WRITE ); +if (error) + goto out_inode_unlock; + + error =security_inode_removexattr (mnt_userns, dentry, acl_name); +if (error) + goto out_inode_unlock;
Similar to my comments in patch 16/30 for vfs_get_acl(), I would suggest a dedicated ACL remove hook here. Yes, it's still a little bit silly, but if we are going to make one dedicated hook, we might as well do them all.
Quoted 17 lines
fs/posix_acl.c +17
-0+ error =try_break_deleg (inode, &delegated_inode); +if (error) + goto out_inode_unlock; + +if (inode->i_opflags &IOP_XATTR ) + error =set_posix_acl (mnt_userns, dentry, acl_type,NULL ); +else if (unlikely (is_bad_inode (inode))) + error = -EIO ; +else + error = -EOPNOTSUPP ; +if (!error) { +fsnotify_xattr (dentry); +evm_inode_post_removexattr (dentry, acl_name); + } + +out_inode_unlock: +inode_unlock (inode);
fs/posix_acl.c struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns, · line 1551
Quoted 10 lines
fs/posix_acl.c +10
-0+ +if (delegated_inode) { + error =break_deleg_wait (&delegated_inode); +if (!error) + goto retry_deleg; + } + +return error; +} +EXPORT_SYMBOL (vfs_remove_acl);
--
paul-moore.com
Re: [PATCH v2 10/30] security: add set acl hook
In reply to Christian BraunerQuoted 29 lines · Christian Brauner
The current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
In the next patches we implement the hooks for the few security modules that do actually have restrictions on posix acls.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
Quoted 8 lines
/* v2 */ unchangedinclude/linux/lsm_hook_defs.h | 2 ++ include/linux/lsm_hooks.h | 4 ++++ include/linux/security.h | 11 +++++++++++ security/security.c | 9 +++++++++ 4 files changed, 26 insertions(+)
The only thing that is really absent from the new hook, compared to the existing security_inode_setxattr() hook in the ACL case, is the EVM hook which looks to be addressed in patch 13/30.
--
paul-moore.com
Re: [PATCH v2 11/30] selinux: implement set acl hook
In reply to Christian BraunerQuoted 29 lines · Christian Brauner
The current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
I spent considerate time in the security module infrastructure and audited all codepaths. SELinux has no restrictions based on the posix acl values passed through it. The capability hook doesn't need to be called either because it only has restrictions on security.* xattrs. So this all becomes a very simple hook for SELinux.
Quoted 8 lines
---
Notes:
/* v2 */ unchangedsecurity/selinux/hooks.c | 8 ++++++++ 1 file changed, 8 insertions(+)
--
paul-moore.com
Re: [PATCH v2 12/30] smack: implement set acl hook
In reply to Christian BraunerQuoted 29 lines · Christian Brauner
The current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
I spent considerate time in the security module infrastructure and audited all codepaths. Smack has no restrictions based on the posix acl values passed through it. The capability hook doesn't need to be called either because it only has restrictions on security.* xattrs. So this all becomes a very simple hook for smack.
Quoted 8 lines
---
Notes:
/* v2 */ unchangedsecurity/smack/smack_lsm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
--
paul-moore.com
Re: [PATCH v2 13/30] evm: implement set acl hook
In reply to Christian BraunerQuoted 35 lines · Christian Brauner
The current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
I spent considerate time in the security module and integrity infrastructure and audited all codepaths. EVM is the only part that really has restrictions based on the actual posix acl values passed through it. Before this dedicated hook EVM used to translate from the uapi posix acl format sent to it in the form of a void pointer into the vfs format. This is not a good thing. Instead of hacking around in the uapi struct give EVM the posix acls in the appropriate vfs format and perform sane permissions checks that mirror what it used to to in the generic xattr hook.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Quoted 8 lines
Notes:
/* v2 */ unchangedinclude/linux/evm.h | 10 +++++ security/integrity/evm/evm_main.c | 66 ++++++++++++++++++++++++++++++- security/security.c | 9 ++++- 3 files changed, 83 insertions(+), 2 deletions(-)
Ultimately this is Mimi's call, and it can be done later after this patchset is merged, but it seems to me that some of the code in evm_inode_set_acl() could be pulled out into a helper function(s) shared with evm_protect_xattr().
--
paul-moore.com
Re: [PATCH v2 14/30] acl: use set acl hook
In reply to Christian BraunerQuoted 25 lines · Christian Brauner
The current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs.
Now that we have a proper security hook for setting posix acls that passes down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format make use of it in the new posix acl api.
Quoted 8 lines
---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 5 +++++ 1 file changed, 5 insertions(+)
--
paul-moore.com
Re: [PATCH v2 15/30] evm: add post set acl hook
In reply to Christian BraunerQuoted 36 lines · Christian Brauner
The
security_inode_post_setxattr()hook is used by security modules to update their own security.* xattrs. Consequently none of the security modules operate on posix acls. So we don't need an additional security hook when post setting posix acls.However, the integrity subsystem wants to be informed about posix acl changes and specifically evm to update their hashes when the xattrs change. The callchain for
evm_inode_post_setxattr()is:->
evm_inode_post_setxattr()
->evm_update_evmxattr()-> evm_calc_hmac() -> evm_calc_hmac_or_hash()and
evm_cacl_hmac_or_hash()walks the global list of protected xattr namesevm_config_xattrnames. This global list can be modified via/sys/security/integrity/evm/evm_xattrs. The write to "evm_xattrs" is restricted to security.* xattrs and the default xattrs inevm_config_xattrnamesonly contains security.* xattrs as well.So the actual value for posix acls is currently completely irrelevant for evm during
evm_inode_post_setxattr()and frankly it should stay that way in the future to not cause the vfs any more headaches. But if the actual posix acl values matter then evm shouldn't operate on the binary void blob and try to hack around in the uapi struct anyway. Instead it should then in the future add a dedicated hook which takes a structposix_aclargument passing the posix acls in the proper vfs format.For now it is sufficient to make
evm_inode_post_set_acl()a wrapper aroundevm_inode_post_setxattr()not passing any actual values down. This will still cause the hashes to be updated as before.Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Quoted 7 lines
Notes:
/* v2 */ unchangedfs/posix_acl.c | 5 ++++- include/linux/evm.h | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
--
paul-moore.com
Paul Moore
maintainerRe: [PATCH v2 18/30] evm: simplify evm_xattr_acl_change()
In reply to Christian BraunerQuoted 90 lines · Christian Brauner
The posix acl api provides a dedicated security and integrity hook for setting posix acls. This means that
evm_protect_xattr()
->evm_xattr_change()
->evm_xattr_acl_change()is now only hit during
vfs_remove_acl()at which point we are guaranteed thatxattr_valueandxattr_value_lenare NULL and 0. In this case evm always used to return 1. Simplify this function to do just that.Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedsecurity/integrity/evm/evm_main.c | 62 +++++++------------------------ 1 file changed, 14 insertions(+), 48 deletions(-)security/integrity/evm/evm_main.c +6
-45@@ -436,62 +436,29 @@ static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)/* * evm_xattr_acl_change - check if passed ACL changes the inode mode -* @mnt_userns: user namespace of the idmapped mount -* @dentry: pointer to the affected dentry * @xattr_name: requested xattr * @xattr_value: requested xattr value * @xattr_value_len: requested xattr value length * -* Check if passed ACL changes the inode mode, which is protected by EVM. +* This is only hit during xattr removal at which point we always return 1. +* Splat a warning in case someone managed to pass data to this function. That +* should never happen. * * Returns 1 if passed ACL causes inode mode change, 0 otherwise. */ -static int evm_xattr_acl_change (struct user_namespace *mnt_userns, -struct dentry *dentry,const char *xattr_name, -const void *xattr_value,size_t xattr_value_len) +static int evm_xattr_acl_change (const void *xattr_value,size_t xattr_value_len) { -#ifdef CONFIG_FS_POSIX_ACL -umode_t mode; -struct posix_acl *acl =NULL , *acl_res; -struct inode *inode =d_backing_inode (dentry); -int rc; - -/* -* An earlier comment here mentioned that the idmappings for -* ACL_{GROUP,USER} don't matter since EVM is only interested in the -* mode stored as part of POSIX ACLs. Nonetheless, if it must translate -* from the uapi POSIX ACL representation to the VFS internal POSIX ACL -* representation it should do so correctly. There's no guarantee that -* we won't change POSIX ACLs in a way that ACL_{GROUP,USER} matters -* for the mode at some point and it's difficult to keep track of all -* the LSM and integrity modules and what they do to POSIX ACLs. -* -* Frankly, EVM shouldn't try to interpret the uapi struct for POSIX -* ACLs it received. It requires knowledge that only the VFS is -* guaranteed to have. -*/ - acl =vfs_set_acl_prepare (mnt_userns,i_user_ns (inode), - xattr_value, xattr_value_len); -if (IS_ERR_OR_NULL (acl)) -return 1 ; - - acl_res = acl; -/* -* Passing mnt_userns is necessary to correctly determine the GID in -* an idmapped mount, as the GID is used to clear the setgid bit in -* the inode mode. -*/ - rc =posix_acl_update_mode (mnt_userns, inode, &mode, &acl_res); - -posix_acl_release (acl); - -if (rc) -return 1 ; +int rc =0 ; -if (inode->i_mode != mode) -return 1 ; +#ifdef CONFIG_FS_POSIX_ACL
security/integrity/evm/evm_main.c static enum integrity_status evm_verify_current_integrity(struct dentry *dentry) · line 462
Quoted 10 lines
security/integrity/evm/evm_main.c +7
-1+WARN_ONCE (xattr_value !=NULL , +"Passing xattr value for POSIX ACLs not supported\n" ); +WARN_ONCE (xattr_value_len !=0 , +"Passing non-zero length for POSIX ACLs not supported\n" ); + rc =1 ;#endif -return 0 ; + +return rc; }
This is another case where I'll leave the final say up to Mimi, but why not just get rid of evm_xattr_acl_change() entirely? Unless I'm missing something, it's only reason for existing now is to check that it is passed the proper (empty) parameters which seems pointless ... no?
--
paul-moore.com
Re: [PATCH v2 12/30] smack: implement set acl hook
In reply to Christian BraunerQuoted 20 lines · Christian Brauner
The current way of setting and getting posix acls through the generic xattr interface is error prone and type unsafe. The vfs needs to interpret and fixup posix acls before storing or reporting it to userspace. Various hacks exist to make this work. The code is hard to understand and difficult to maintain in it's current form. Instead of making this work by hacking posix acls through xattr handlers we are building a dedicated posix acl api around the get and set inode operations. This removes a lot of hackiness and makes the codepaths easier to maintain. A lot of background can be found in [1].
So far posix acls were passed as a void blob to the security and integrity modules. Some of them like evm then proceed to interpret the void pointer and convert it into the kernel internal struct posix acl representation to perform their integrity checking magic. This is obviously pretty problematic as that requires knowledge that only the vfs is guaranteed to have and has lead to various bugs. Add a proper security hook for setting posix acls and pass down the posix acls in their appropriate vfs format instead of hacking it through a void pointer stored in the uapi format.
Quoted 8 lines
I spent considerate time in the security module infrastructure and audited all codepaths. Smack has no restrictions based on the posix acl values passed through it. The capability hook doesn't need to be called either because it only has restrictions on security.* xattrs. So this all becomes a very simple hook for smack.
The Smack hook looks fine.
Quoted 51 lines
---
Notes:
/* v2 */ unchangedsecurity/smack/smack_lsm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)security/smack/smack_lsm.c +24
-0@@ -1393,6 +1393,29 @@ static int smack_inode_removexattr(struct user_namespace *mnt_userns,return 0 ; } +/** +* smack_inode_set_acl - Smack check for setting posix acls +* @mnt_userns: the userns attached to the mnt this request came from +* @dentry: the object +* @acl_name: name of the posix acl +* @kacl: the posix acls +* +* Returns 0 if access is permitted, an error code otherwise +*/ +static int smack_inode_set_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name, +struct posix_acl *kacl) +{ +struct smk_audit_info ad; +int rc; + +smk_ad_init (&ad, __func__,LSM_AUDIT_DATA_DENTRY ); +smk_ad_setfield_u_fs_path_dentry (&ad, dentry); + rc =smk_curacc (smk_of_inode (d_backing_inode (dentry)),MAY_WRITE , &ad); + rc =smk_bu_inode (d_backing_inode (dentry),MAY_WRITE , rc); +return rc; +} +/** * smack_inode_getsecurity - get smack xattrs * @mnt_userns: active user namespace @@ -4772,6 +4795,7 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (inode_post_setxattr, smack_inode_post_setxattr),LSM_HOOK_INIT (inode_getxattr, smack_inode_getxattr),LSM_HOOK_INIT (inode_removexattr, smack_inode_removexattr), +LSM_HOOK_INIT (inode_set_acl, smack_inode_set_acl),LSM_HOOK_INIT (inode_getsecurity, smack_inode_getsecurity),LSM_HOOK_INIT (inode_setsecurity, smack_inode_setsecurity), LSM_HOOK_INIT(inode_listsecurity, smack_inode_listsecurity),
Paul Moore
maintainerQuoted 14 lines · Casey Schaufler
Quoted 11 lines · Christoph Hellwig
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Quoted 8 lines
Here's the problem I see. All of the LSMs see xattrs, except for their own, as opaque objects. Introducing LSM hooks to address the data interpretation issues between VFS and EVM, which is not an LSM, adds to an already overlarge and interface. And the "real" users of the interface don't need the new hook. I'm not saying that the ACL doesn't have problems. I'm not saying that the solution you've proposed isn't better than what's there now. I am saying that using LSM as a conduit between VFS and EVM at the expense of the rest of the modules is dubious. A lot of change to LSM for no value to LSM.
Let's take a step back and look not just at the LSM changes, but the patchset as a whole. Forgive my paraphrasing, but what Christian is trying to do here is introduce a proper ACL API in the kernel to remove a lot of kludges, special-cases, etc. in the VFS layer, enabling better type checking, code abstractions, and all the nice things you get when you have nice APIs. This is admirable work, even if it does result in some duplication at the LSM layer (and below).
It is my opinion that the impact to the LSM, both at the LSM layer, and in the individual affected LSMs is not significant enough to outweigh the other advantages offered by this patchset.
Signature · 1 line
paul-moore.com
Casey Schaufler
maintainerQuoted 29 lines · Paul Moore
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Christoph Hellwig
Quoted 3 lines · Casey Schaufler
I suggest that you might focus on the acl/evm interface rather than the entire LSM interface. Unless there's a serious plan to make ima/evm into a proper LSM I don't see how the breadth of this patch set is appropriate.
Umm. The problem is the historically the Linux xattr interface was intended for unstructured data, while some of it is very much structured and requires interpretation by the VFS and associated entities. So splitting these out and add proper interface is absolutely the right thing to do and long overdue (also for other thing like capabilities). It might make things a little more verbose for LSM, but it fixes a very real problem.
Quoted 8 lines
Here's the problem I see. All of the LSMs see xattrs, except for their own, as opaque objects. Introducing LSM hooks to address the data interpretation issues between VFS and EVM, which is not an LSM, adds to an already overlarge and interface. And the "real" users of the interface don't need the new hook. I'm not saying that the ACL doesn't have problems. I'm not saying that the solution you've proposed isn't better than what's there now. I am saying that using LSM as a conduit between VFS and EVM at the expense of the rest of the modules is dubious. A lot of change to LSM for no value to LSM.
Let's take a step back and look not just at the LSM changes, but the patchset as a whole. Forgive my paraphrasing, but what Christian is trying to do here is introduce a proper ACL API in the kernel to remove a lot of kludges, special-cases, etc. in the VFS layer, enabling better type checking, code abstractions, and all the nice things you get when you have nice APIs. This is admirable work, even if it does result in some duplication at the LSM layer (and below).
Quoted 3 lines
It is my opinion that the impact to the LSM, both at the LSM layer, and in the individual affected LSMs is not significant enough to outweigh the other advantages offered by this patchset.
Hey, in the end it's your call. I agree that cleaning up kludgy code is inherently good. I'm willing to believe that putting further effort into the patch set to make the LSM aspects cleaner isn't cost effective. If everyone else thinks this is the right approach, I don't need to question it further.
Christian Brauner
maintainerRe: [PATCH v2 16/30] acl: add vfs_get_acl()
In reply to Paul MooreQuoted 70 lines · Paul Moore
Quoted 27 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_get_acl()api that can be used to get posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 131 ++++++++++++++++++++++++++++++-- include/linux/posix_acl.h | 9 +++ include/linux/posix_acl_xattr.h | 10 +++ 3 files changed, 142 insertions(+), 8 deletions(-)...
Quoted 28 lines
fs/posix_acl.c +20
-0@@ -1369,3 +1439,48 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,return error; }EXPORT_SYMBOL (vfs_set_acl); + +/** +* vfs_get_acl - get posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function retrieves @kacl from the filesystem. The caller must all +* posix_acl_release() on @kacl. +* +* Return: On success POSIX ACLs in VFS format, on error negative errno. +*/ +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +struct inode *inode =d_inode (dentry); +struct posix_acl *acl; +int acl_type, error; + + acl_type =posix_acl_type (acl_name);fs/posix_acl.c int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, · line 1471
Quoted 10 lines
fs/posix_acl.c +10
-0+if (acl_type <0 ) +return ERR_PTR (-EINVAL ); + +/* +* The VFS has no restrictions on reading POSIX ACLs so calling +* something like xattr_permission() isn't needed. Only LSMs get a say. +*/ + error =security_inode_getxattr (dentry, acl_name); +if (error) +return ERR_PTR (error);
Quoted 7 lines
I understand the desire to reuse the
security_inode_getxattr()hook here, it makes perfect sense, but given that this patchset introduces an ACL specific setter hook I think it makes sense to have a matching getter hook. It's arguably a little silly given the current crop of LSMs and their approach to ACLs, but if we are going to differentiate on the write side I think we might as well be consistent and differentiate on the read side as well.
Sure, I don't mind doing that. I'll add the infrastructure and then the individual LSMs can add their own hooks.
Christian Brauner
maintainerRe: [PATCH v2 17/30] acl: add vfs_remove_acl()
In reply to Paul MooreQuoted 72 lines · Paul Moore
Quoted 26 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_remove_acl()api that can be used to set posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 65 +++++++++++++++++++++++++++++++++++++++ include/linux/posix_acl.h | 8 +++++ 2 files changed, 73 insertions(+)...
Quoted 42 lines
fs/posix_acl.c +34
-0@@ -1484,3 +1484,68 @@ struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns,return acl; }EXPORT_SYMBOL (vfs_get_acl); + +/** +* vfs_remove_acl - remove posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function removes posix acls. +* +* Return: On success 0, on error negative errno. +*/ +int vfs_remove_acl (struct user_namespace *mnt_userns,struct dentry *dentry, +const char *acl_name) +{ +int acl_type; +int error; +struct inode *inode =d_inode (dentry); +struct inode *delegated_inode =NULL ; + + acl_type =posix_acl_type (acl_name); +if (acl_type <0 ) +return -EINVAL ; + +retry_deleg: +inode_lock (inode); + +/* +* We only care about restrictions the inode struct itself places upon +* us otherwise POSIX ACLs aren't subject to any VFS restrictions. +*/ + error =xattr_permission (mnt_userns, inode, acl_name,MAY_WRITE ); +if (error) + goto out_inode_unlock; +
Quoted 8 lines
fs/posix_acl.c struct posix_acl *vfs_get_acl(struct user_namespace *mnt_userns, · line 1523
Quoted 3 lines
fs/posix_acl.c +3
-0+ error =security_inode_removexattr (mnt_userns, dentry, acl_name); +if (error) + goto out_inode_unlock;Similar to my comments in patch 16/30 for
vfs_get_acl(), I would suggest a dedicated ACL remove hook here. Yes, it's still a little bit silly, but if we are going to make one dedicated hook, we might as well do them all.
Sure, I don't mind doing that. I'll add the infrastructure and then the individual LSMs can add their own hooks.
Christian Brauner
maintainerRe: [PATCH v2 18/30] evm: simplify evm_xattr_acl_change()
In reply to Paul MooreQuoted 99 lines · Paul Moore
Quoted 98 lines · Christian Brauner
The posix acl api provides a dedicated security and integrity hook for setting posix acls. This means that
evm_protect_xattr()
->evm_xattr_change()
->evm_xattr_acl_change()is now only hit during
vfs_remove_acl()at which point we are guaranteed thatxattr_valueandxattr_value_lenare NULL and 0. In this case evm always used to return 1. Simplify this function to do just that.Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedsecurity/integrity/evm/evm_main.c | 62 +++++++------------------------ 1 file changed, 14 insertions(+), 48 deletions(-)security/integrity/evm/evm_main.c +12
-46@@ -436,62 +436,29 @@ static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)/* * evm_xattr_acl_change - check if passed ACL changes the inode mode -* @mnt_userns: user namespace of the idmapped mount -* @dentry: pointer to the affected dentry * @xattr_name: requested xattr * @xattr_value: requested xattr value * @xattr_value_len: requested xattr value length * -* Check if passed ACL changes the inode mode, which is protected by EVM. +* This is only hit during xattr removal at which point we always return 1. +* Splat a warning in case someone managed to pass data to this function. That +* should never happen. * * Returns 1 if passed ACL causes inode mode change, 0 otherwise. */ -static int evm_xattr_acl_change (struct user_namespace *mnt_userns, -struct dentry *dentry,const char *xattr_name, -const void *xattr_value,size_t xattr_value_len) +static int evm_xattr_acl_change (const void *xattr_value,size_t xattr_value_len) { -#ifdef CONFIG_FS_POSIX_ACL -umode_t mode; -struct posix_acl *acl =NULL , *acl_res; -struct inode *inode =d_backing_inode (dentry); -int rc; - -/* -* An earlier comment here mentioned that the idmappings for -* ACL_{GROUP,USER} don't matter since EVM is only interested in the -* mode stored as part of POSIX ACLs. Nonetheless, if it must translate -* from the uapi POSIX ACL representation to the VFS internal POSIX ACL -* representation it should do so correctly. There's no guarantee that -* we won't change POSIX ACLs in a way that ACL_{GROUP,USER} matters -* for the mode at some point and it's difficult to keep track of all -* the LSM and integrity modules and what they do to POSIX ACLs. -* -* Frankly, EVM shouldn't try to interpret the uapi struct for POSIX -* ACLs it received. It requires knowledge that only the VFS is -* guaranteed to have. -*/ - acl =vfs_set_acl_prepare (mnt_userns,i_user_ns (inode), - xattr_value, xattr_value_len); -if (IS_ERR_OR_NULL (acl)) -return 1 ; - - acl_res = acl; -/* -* Passing mnt_userns is necessary to correctly determine the GID in -* an idmapped mount, as the GID is used to clear the setgid bit in -* the inode mode. -*/ - rc =posix_acl_update_mode (mnt_userns, inode, &mode, &acl_res); - -posix_acl_release (acl); - -if (rc) -return 1 ; +int rc =0 ; -if (inode->i_mode != mode) -return 1 ; +#ifdef CONFIG_FS_POSIX_ACL +WARN_ONCE (xattr_value !=NULL , +"Passing xattr value for POSIX ACLs not supported\n" ); +WARN_ONCE (xattr_value_len !=0 , +"Passing non-zero length for POSIX ACLs not supported\n" ); + rc =1 ;#endif -return 0 ; +
Quoted 8 lines
security/integrity/evm/evm_main.c static enum integrity_status evm_verify_current_integrity(struct dentry *dentry) · line 462
Quoted 2 lines
security/integrity/evm/evm_main.c +1
-0+return rc; }This is another case where I'll leave the final say up to Mimi, but why not just get rid of
evm_xattr_acl_change()entirely? Unless I'm missing something, it's only reason for existing now is to check that it is passed the proper (empty) parameters which seems pointless ... no?
Yeah, I think we can remove it. evm_inode_remove_acl() is just evm_inode_set_acl(NULL, 0) so if we add evm_inode_remove_acl() as a wrapper around it instead of simply abusing the existing evm_inode_removexattr() we can delete all that code indeed as it won't be reachable from generic xattr code anymore.
Paul Moore
maintainerRe: [PATCH v2 16/30] acl: add vfs_get_acl()
In reply to Christian BraunerQuoted 80 lines · Christian Brauner
Quoted 70 lines · Paul Moore
Quoted 27 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_get_acl()api that can be used to get posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 131 ++++++++++++++++++++++++++++++-- include/linux/posix_acl.h | 9 +++ include/linux/posix_acl_xattr.h | 10 +++ 3 files changed, 142 insertions(+), 8 deletions(-)...
Quoted 28 lines
fs/posix_acl.c +20
-0@@ -1369,3 +1439,48 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,return error; }EXPORT_SYMBOL (vfs_set_acl); + +/** +* vfs_get_acl - get posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function retrieves @kacl from the filesystem. The caller must all +* posix_acl_release() on @kacl. +* +* Return: On success POSIX ACLs in VFS format, on error negative errno. +*/ +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +struct inode *inode =d_inode (dentry); +struct posix_acl *acl; +int acl_type, error; + + acl_type =posix_acl_type (acl_name);fs/posix_acl.c int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, · line 1471
Quoted 10 lines
fs/posix_acl.c +10
-0+if (acl_type <0 ) +return ERR_PTR (-EINVAL ); + +/* +* The VFS has no restrictions on reading POSIX ACLs so calling +* something like xattr_permission() isn't needed. Only LSMs get a say. +*/ + error =security_inode_getxattr (dentry, acl_name); +if (error) +return ERR_PTR (error);Quoted 7 lines
I understand the desire to reuse the
security_inode_getxattr()hook here, it makes perfect sense, but given that this patchset introduces an ACL specific setter hook I think it makes sense to have a matching getter hook. It's arguably a little silly given the current crop of LSMs and their approach to ACLs, but if we are going to differentiate on the write side I think we might as well be consistent and differentiate on the read side as well.
Quoted 2 lines
Sure, I don't mind doing that. I'll add the infrastructure and then the individual LSMs can add their own hooks.
Adding the ACL hook infrastructure, including the call in vfs_get_acl(), without the LSM implementations would result in an access control regression for both SELinux and Smack. Similar issues with the removexattr hook, although that looks to have IMA/EVM calls too (which may be noops in the case of an ACL, I haven't checked).
The good news is that the individual LSM implementations should be trivial, and if you wanted to just have the new ACL hook implementations call into the existing xattr implementations inside each LSM I think that would be okay to start.
Signature · 1 line
paul-moore.com
Christian Brauner
maintainerRe: [PATCH v2 16/30] acl: add vfs_get_acl()
Quoted 90 lines · Paul Moore
Quoted 80 lines · Christian Brauner
Quoted 70 lines · Paul Moore
Quoted 27 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_get_acl()api that can be used to get posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 131 ++++++++++++++++++++++++++++++-- include/linux/posix_acl.h | 9 +++ include/linux/posix_acl_xattr.h | 10 +++ 3 files changed, 142 insertions(+), 8 deletions(-)...
Quoted 28 lines
fs/posix_acl.c +20
-0@@ -1369,3 +1439,48 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,return error; }EXPORT_SYMBOL (vfs_set_acl); + +/** +* vfs_get_acl - get posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function retrieves @kacl from the filesystem. The caller must all +* posix_acl_release() on @kacl. +* +* Return: On success POSIX ACLs in VFS format, on error negative errno. +*/ +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +struct inode *inode =d_inode (dentry); +struct posix_acl *acl; +int acl_type, error; + + acl_type =posix_acl_type (acl_name);fs/posix_acl.c int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, · line 1471
Quoted 10 lines
fs/posix_acl.c +10
-0+if (acl_type <0 ) +return ERR_PTR (-EINVAL ); + +/* +* The VFS has no restrictions on reading POSIX ACLs so calling +* something like xattr_permission() isn't needed. Only LSMs get a say. +*/ + error =security_inode_getxattr (dentry, acl_name); +if (error) +return ERR_PTR (error);Quoted 7 lines
I understand the desire to reuse the
security_inode_getxattr()hook here, it makes perfect sense, but given that this patchset introduces an ACL specific setter hook I think it makes sense to have a matching getter hook. It's arguably a little silly given the current crop of LSMs and their approach to ACLs, but if we are going to differentiate on the write side I think we might as well be consistent and differentiate on the read side as well.Quoted 2 lines
Sure, I don't mind doing that. I'll add the infrastructure and then the individual LSMs can add their own hooks.
Adding the ACL hook infrastructure, including the call in
vfs_get_acl(), without the LSM implementations would result in an access control regression for both SELinux and Smack. Similar issues with the removexattr hook, although that looks to have IMA/EVM calls too (which may be noops in the case of an ACL, I haven't checked).
Quoted 4 lines
The good news is that the individual LSM implementations should be trivial, and if you wanted to just have the new ACL hook implementations call into the existing xattr implementations inside each LSM I think that would be okay to start.
Yeah, I realized right after I sent the mail that I'd need to implement them. I think I came up with something fairly minimal for all lsms and the integrity modules. I folded the trivial patches for adding get, set, and remove hooks for the individual modules together to not needlessly inflate the security portion of the patchset.
Paul Moore
maintainerRe: [PATCH v2 16/30] acl: add vfs_get_acl()
Quoted 96 lines · Christian Brauner
Quoted 90 lines · Paul Moore
Quoted 80 lines · Christian Brauner
Quoted 70 lines · Paul Moore
Quoted 27 lines · Christian Brauner
In previous patches we implemented get and set inode operations for all non-stacking filesystems that support posix acls but didn't yet implement get and/or set acl inode operations. This specifically affected cifs and 9p.
Now we can build a posix acl api based solely on get and set inode operations. We add a new
vfs_get_acl()api that can be used to get posix acls. This finally removes all type unsafety and type conversion issues explained in detail in [1] that we aim to get rid of.After we finished building the vfs api we can switch stacking filesystems to rely on the new posix api and then finally switch the xattr system calls themselves to rely on the posix acl api.
Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Notes:
/* v2 */ unchangedfs/posix_acl.c | 131 ++++++++++++++++++++++++++++++-- include/linux/posix_acl.h | 9 +++ include/linux/posix_acl_xattr.h | 10 +++ 3 files changed, 142 insertions(+), 8 deletions(-)...
Quoted 28 lines
fs/posix_acl.c +20
-0@@ -1369,3 +1439,48 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,return error; }EXPORT_SYMBOL (vfs_set_acl); + +/** +* vfs_get_acl - get posix acls +* @mnt_userns: user namespace of the mount +* @dentry: the dentry based on which to retrieve the posix acls +* @acl_name: the name of the posix acl +* +* This function retrieves @kacl from the filesystem. The caller must all +* posix_acl_release() on @kacl. +* +* Return: On success POSIX ACLs in VFS format, on error negative errno. +*/ +struct posix_acl *vfs_get_acl (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *acl_name) +{ +struct inode *inode =d_inode (dentry); +struct posix_acl *acl; +int acl_type, error; + + acl_type =posix_acl_type (acl_name);fs/posix_acl.c int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry, · line 1471
Quoted 10 lines
fs/posix_acl.c +10
-0+if (acl_type <0 ) +return ERR_PTR (-EINVAL ); + +/* +* The VFS has no restrictions on reading POSIX ACLs so calling +* something like xattr_permission() isn't needed. Only LSMs get a say. +*/ + error =security_inode_getxattr (dentry, acl_name); +if (error) +return ERR_PTR (error);Quoted 7 lines
I understand the desire to reuse the
security_inode_getxattr()hook here, it makes perfect sense, but given that this patchset introduces an ACL specific setter hook I think it makes sense to have a matching getter hook. It's arguably a little silly given the current crop of LSMs and their approach to ACLs, but if we are going to differentiate on the write side I think we might as well be consistent and differentiate on the read side as well.Quoted 2 lines
Sure, I don't mind doing that. I'll add the infrastructure and then the individual LSMs can add their own hooks.
Adding the ACL hook infrastructure, including the call in
vfs_get_acl(), without the LSM implementations would result in an access control regression for both SELinux and Smack. Similar issues with the removexattr hook, although that looks to have IMA/EVM calls too (which may be noops in the case of an ACL, I haven't checked).Quoted 4 lines
The good news is that the individual LSM implementations should be trivial, and if you wanted to just have the new ACL hook implementations call into the existing xattr implementations inside each LSM I think that would be okay to start.
Quoted 5 lines
Yeah, I realized right after I sent the mail that I'd need to implement them. I think I came up with something fairly minimal for all lsms and the integrity modules. I folded the trivial patches for adding get, set, and remove hooks for the individual modules together to not needlessly inflate the security portion of the patchset.
I'll keep an eye out for v3.
Signature · 1 line
paul-moore.com