Skip to content

acl: add vfs posix acl api

Christian Brauner ecryptfs linux-cifs linux-fsdevel linux-integrity linux-security-module linux-unionfs selinux 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest30 patches 6 repliesIn review
  2. v430 patches 29 repliesSuperseded
  3. v329 patches 21 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v230 patches24 repliesSuperseded
v1 RFC29 patches45 repliesSuperseded

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/30orangefs: rework posix acl handling when creating new filesystem objectsfs/orangefs/acl.c fs/orangefs/inode.c fs/orangefs/orangefs-kernel.h +1 more+50 -543 replies
2/30fs: pass dentry to set acl methodDocumentation/filesystems/vfs.rst fs/bad_inode.c fs/btrfs/acl.c +52 more+119 -933 replies
3/30fs: rename current get acl methodDocumentation/filesystems/locking.rst Documentation/filesystems/porting.rst Documentation/filesystems/vfs.rst +44 more+98 -970 replies
4/30fs: add new get acl methodDocumentation/filesystems/locking.rst Documentation/filesystems/vfs.rst include/linux/fs.h+5 -00 replies
5/30cifs: implement get acl methodfs/cifs/cifsacl.c fs/cifs/cifsfs.c fs/cifs/cifsproto.h +1 more+271 -00 replies
6/30cifs: implement set acl methodfs/cifs/cifsacl.c fs/cifs/cifsfs.c fs/cifs/cifsproto.h +1 more+242 -00 replies
7/309p: implement get acl methodfs/9p/acl.c fs/9p/acl.h fs/9p/vfs_inode_dotl.c +1 more+80 -220 replies
8/309p: implement set acl methodfs/9p/acl.c fs/9p/acl.h fs/9p/vfs_inode_dotl.c+99 -00 replies
9/30security: add get, remove and set acl hookinclude/linux/lsm_hook_defs.h include/linux/lsm_hooks.h include/linux/security.h +1 more+72 -00 replies
10/30selinux: implement get, set and remove acl hooksecurity/selinux/hooks.c+22 -00 replies
11/30smack: implement get, set and remove acl hooksecurity/smack/smack_lsm.c+71 -00 replies
12/30integrity: implement get and set acl hookinclude/linux/evm.h include/linux/ima.h security/integrity/evm/evm_main.c +2 more+157 -31 reply
13/30evm: add post set acl hookinclude/linux/evm.h+13 -00 replies
14/30internal: add may_write_xattr()fs/internal.h fs/xattr.c+31 -130 replies
15/30acl: add vfs_set_acl()fs/posix_acl.c include/linux/posix_acl.h include/linux/posix_acl_xattr.h+127 -00 replies
16/30acl: add vfs_get_acl()fs/posix_acl.c include/linux/posix_acl.h include/linux/posix_acl_xattr.h+141 -70 replies
17/30acl: add vfs_remove_acl()fs/posix_acl.c include/linux/evm.h include/linux/posix_acl.h+86 -00 replies
18/30ksmbd: use vfs_remove_acl()fs/ksmbd/vfs.c+1 -10 replies
19/30ecryptfs: implement get acl methodfs/ecryptfs/inode.c+11 -00 replies
20/30ecryptfs: implement set acl methodfs/ecryptfs/inode.c+17 -00 replies
21/30ovl: implement get acl methodfs/overlayfs/dir.c fs/overlayfs/inode.c fs/overlayfs/overlayfs.h+95 -340 replies
22/30ovl: implement set acl methodfs/overlayfs/dir.c fs/overlayfs/inode.c fs/overlayfs/overlayfs.h+112 -00 replies
23/30ovl: use posix acl apifs/overlayfs/copy_up.c fs/overlayfs/dir.c fs/overlayfs/inode.c +4 more+58 -300 replies
24/30xattr: use posix acl apifs/internal.h fs/posix_acl.c fs/xattr.c +1 more+69 -130 replies
25/30evm: remove evm_xattr_acl_change()security/integrity/evm/evm_main.c+0 -640 replies
26/30ecryptfs: use stub posix acl handlersfs/ecryptfs/inode.c+4 -00 replies
27/30ovl: use stub posix acl handlersfs/overlayfs/super.c+4 -970 replies
28/30cifs: use stub posix acl handlersfs/cifs/cifsproto.h fs/cifs/cifssmb.c fs/cifs/xattr.c+4 -3700 replies
29/309p: use stub posix acl handlersfs/9p/acl.c fs/9p/xattr.c fs/9p/xattr.h+4 -1260 replies
30/30acl: remove a slew of now unused helpersfs/posix_acl.c fs/xattr.c include/linux/posix_acl_xattr.h+23 -3650 replies

Reviews trailers per patch

10 of 30 patches have a Reviewed-by or Acked-by.

PatchChristoph HellwigPaul MooreCasey SchauflerMiklos Szeredi
1/30R-b
2/30R-b
3/30R-b
4/30
5/30
6/30
7/30
8/30
9/30A-b
10/30A-b A-b
11/30R-b A-b R-b R-b
12/30A-b
13/30R-b
14/30
15/30
16/30
17/30
18/30
19/30
20/30
21/30
22/30A-b
23/30A-b
24/30
25/30
26/30
27/30
28/30
29/30
30/30

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v5 thread

Cover letter [PATCH v5 00/30] acl: add vfs posix acl api

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

/* v5 */
Rebased onto v6.1-rc1 and adressed some fs specific feedback. Reran xfstests and LTP and no regressions or bugs were reported.

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

Thanks!
Christian

/* v1 */

/* v2 */

This fixes various things pointed out during review. The individual commits contain more details were appropriate.

/* v3 */

As requested this adds dedicated get and remove security hooks in addition to the set hook instead of reusing the generic xattr hooks.

/* v4 */
Various minor changes. Details in the notes to the commits.

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
security: add get, remove and set acl hook
selinux: implement get, set and remove acl hook
smack: implement get, set and remove acl hook
integrity: implement get and set acl hook
evm: add post set acl hook
internal: add may_write_xattr()
acl: add vfs_set_acl()
acl: add vfs_get_acl()
acl: add vfs_remove_acl()
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
evm: remove evm_xattr_acl_change()
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     |   5 +-
 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/ialloc.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                         |   5 +
 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                    |   8 +-
 fs/ksmbd/smbacl.c                     |   6 +-
 fs/ksmbd/vfs.c                        |  21 +-
 fs/ksmbd/vfs.h                        |   4 +-
 fs/namei.c                            |   4 +-
 fs/nfs/nfs3_fs.h                      |   2 +-
 fs/nfs/nfs3acl.c                      |   9 +-
 fs/nfs/nfs3proc.c                     |   4 +-
 fs/nfsd/nfs2acl.c                     |   8 +-
 fs/nfsd/nfs3acl.c                     |   8 +-
 fs/nfsd/nfs4acl.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         |   8 +-
 fs/orangefs/orangefs-utils.c          |  10 +-
 fs/overlayfs/copy_up.c                |  38 ++
 fs/overlayfs/dir.c                    |  22 +-
 fs/overlayfs/inode.c                  | 187 ++++++-
 fs/overlayfs/overlayfs.h              |  42 +-
 fs/overlayfs/super.c                  | 107 +---
 fs/posix_acl.c                        | 718 +++++++++++++-------------
 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               |  11 +-
 fs/xattr.c                            |  85 +--
 fs/xfs/xfs_acl.c                      |   3 +-
 fs/xfs/xfs_acl.h                      |   2 +-
 fs/xfs/xfs_iops.c                     |  16 +-
 include/linux/evm.h                   |  49 ++
 include/linux/fs.h                    |  10 +-
 include/linux/ima.h                   |  24 +
 include/linux/lsm_hook_defs.h         |   6 +
 include/linux/lsm_hooks.h             |  12 +
 include/linux/posix_acl.h             |  41 +-
 include/linux/posix_acl_xattr.h       |  53 +-
 include/linux/security.h              |  29 ++
 include/linux/xattr.h                 |   6 +
 mm/shmem.c                            |   2 +-
 security/integrity/evm/evm_main.c     | 147 +++---
 security/integrity/ima/ima_appraise.c |   9 +
 security/security.c                   |  42 ++
 security/selinux/hooks.c              |  22 +
 security/smack/smack_lsm.c            |  71 +++
 110 files changed, 1809 insertions(+), 1112 deletions(-)

base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780

Signature · 1 line
2.34.1