Unverified Commit 138060ba authored by Christian Brauner's avatar Christian Brauner Committed by Christian Brauner (Microsoft)
Browse files

fs: pass dentry to set acl method

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].

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.

Link: https://lore.kernel.org/all/20220801145520.1532837-1-brauner@kernel.org

 [1]
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
parent 4053d250
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -443,7 +443,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 file *, umode_t);
	        int (*set_acl)(struct user_namespace *, struct inode *, struct posix_acl *, int);
	        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);
		int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa);
+1 −1
Original line number Diff line number Diff line
@@ -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;
+2 −1
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -3987,7 +3987,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);
+1 −1
Original line number Diff line number Diff line
@@ -5256,7 +5256,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;
Loading