2 * FUSE: Filesystem in Userspace
3 * Copyright (C) 2016 Canonical Ltd. <seth.forshee@canonical.com>
5 * This program can be distributed under the terms of the GNU GPL.
6 * See the file COPYING.
11 #include <linux/posix_acl.h>
12 #include <linux/posix_acl_xattr.h>
14 struct posix_acl *fuse_get_acl(struct inode *inode, int type, bool rcu)
16 struct fuse_conn *fc = get_fuse_conn(inode);
20 struct posix_acl *acl;
23 return ERR_PTR(-ECHILD);
25 if (fuse_is_bad(inode))
28 if (!fc->posix_acl || fc->no_getxattr)
31 if (type == ACL_TYPE_ACCESS)
32 name = XATTR_NAME_POSIX_ACL_ACCESS;
33 else if (type == ACL_TYPE_DEFAULT)
34 name = XATTR_NAME_POSIX_ACL_DEFAULT;
36 return ERR_PTR(-EOPNOTSUPP);
38 value = kmalloc(PAGE_SIZE, GFP_KERNEL);
40 return ERR_PTR(-ENOMEM);
41 size = fuse_getxattr(inode, name, value, PAGE_SIZE);
43 acl = posix_acl_from_xattr(fc->user_ns, value, size);
44 else if ((size == 0) || (size == -ENODATA) ||
45 (size == -EOPNOTSUPP && fc->no_getxattr))
47 else if (size == -ERANGE)
48 acl = ERR_PTR(-E2BIG);
56 int fuse_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
57 struct posix_acl *acl, int type)
59 struct fuse_conn *fc = get_fuse_conn(inode);
63 if (fuse_is_bad(inode))
66 if (!fc->posix_acl || fc->no_setxattr)
69 if (type == ACL_TYPE_ACCESS)
70 name = XATTR_NAME_POSIX_ACL_ACCESS;
71 else if (type == ACL_TYPE_DEFAULT)
72 name = XATTR_NAME_POSIX_ACL_DEFAULT;
77 unsigned int extra_flags = 0;
79 * Fuse userspace is responsible for updating access
80 * permissions in the inode, if needed. fuse_setxattr
81 * invalidates the inode attributes, which will force
82 * them to be refreshed the next time they are used,
83 * and it also updates i_ctime.
85 size_t size = posix_acl_xattr_size(acl->a_count);
91 value = kmalloc(size, GFP_KERNEL);
95 ret = posix_acl_to_xattr(fc->user_ns, acl, value, size);
101 if (!vfsgid_in_group_p(i_gid_into_vfsgid(&init_user_ns, inode)) &&
102 !capable_wrt_inode_uidgid(&init_user_ns, inode, CAP_FSETID))
103 extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
105 ret = fuse_setxattr(inode, name, value, size, 0, extra_flags);
108 ret = fuse_removexattr(inode, name);
110 forget_all_cached_acls(inode);
111 fuse_invalidate_attr(inode);