Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2008, Christoph Hellwig |
| 4 | * All Rights Reserved. |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include "xfs.h" |
Darrick J. Wong | 5467b34 | 2019-06-28 19:25:35 -0700 | [diff] [blame] | 7 | #include "xfs_shared.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 8 | #include "xfs_format.h" |
Dave Chinner | 6943283 | 2013-08-12 20:49:23 +1000 | [diff] [blame] | 9 | #include "xfs_log_format.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 10 | #include "xfs_trans_resv.h" |
Dave Chinner | 0a8aa19 | 2013-06-05 12:09:10 +1000 | [diff] [blame] | 11 | #include "xfs_mount.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 12 | #include "xfs_inode.h" |
Dave Chinner | e0c4108 | 2022-05-12 15:12:52 +1000 | [diff] [blame] | 13 | #include "xfs_da_format.h" |
| 14 | #include "xfs_da_btree.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 15 | #include "xfs_attr.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 16 | #include "xfs_trace.h" |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 17 | #include "xfs_error.h" |
Darrick J. Wong | 5f213dd | 2019-11-06 17:19:33 -0800 | [diff] [blame] | 18 | #include "xfs_acl.h" |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 19 | #include "xfs_trans.h" |
Darrick J. Wong | efc2efe | 2022-05-27 10:34:04 +1000 | [diff] [blame] | 20 | #include "xfs_xattr.h" |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 21 | |
Darrick J. Wong | 5f213dd | 2019-11-06 17:19:33 -0800 | [diff] [blame] | 22 | #include <linux/posix_acl_xattr.h> |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 23 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 24 | /* |
| 25 | * Locking scheme: |
| 26 | * - all ACL updates are protected by inode->i_mutex, which is taken before |
| 27 | * calling into this file. |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | STATIC struct posix_acl * |
Dave Chinner | 0a8aa19 | 2013-06-05 12:09:10 +1000 | [diff] [blame] | 31 | xfs_acl_from_disk( |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 32 | struct xfs_mount *mp, |
Andreas Gruenbacher | 86a21c7 | 2015-11-03 12:41:59 +1100 | [diff] [blame] | 33 | const struct xfs_acl *aclp, |
| 34 | int len, |
| 35 | int max_entries) |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 36 | { |
| 37 | struct posix_acl_entry *acl_e; |
| 38 | struct posix_acl *acl; |
Andreas Gruenbacher | 86a21c7 | 2015-11-03 12:41:59 +1100 | [diff] [blame] | 39 | const struct xfs_acl_entry *ace; |
Xi Wang | 093019c | 2011-12-12 21:55:52 +0000 | [diff] [blame] | 40 | unsigned int count, i; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 41 | |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 42 | if (len < sizeof(*aclp)) { |
| 43 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, aclp, |
| 44 | len); |
Andreas Gruenbacher | 86a21c7 | 2015-11-03 12:41:59 +1100 | [diff] [blame] | 45 | return ERR_PTR(-EFSCORRUPTED); |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 48 | count = be32_to_cpu(aclp->acl_cnt); |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 49 | if (count > max_entries || XFS_ACL_SIZE(count) != len) { |
| 50 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, aclp, |
| 51 | len); |
Christoph Hellwig | fa8b18e | 2011-11-20 15:35:32 +0000 | [diff] [blame] | 52 | return ERR_PTR(-EFSCORRUPTED); |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 53 | } |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 54 | |
| 55 | acl = posix_acl_alloc(count, GFP_KERNEL); |
| 56 | if (!acl) |
| 57 | return ERR_PTR(-ENOMEM); |
| 58 | |
| 59 | for (i = 0; i < count; i++) { |
| 60 | acl_e = &acl->a_entries[i]; |
| 61 | ace = &aclp->acl_entry[i]; |
| 62 | |
| 63 | /* |
| 64 | * The tag is 32 bits on disk and 16 bits in core. |
| 65 | * |
| 66 | * Because every access to it goes through the core |
| 67 | * format first this is not a problem. |
| 68 | */ |
| 69 | acl_e->e_tag = be32_to_cpu(ace->ae_tag); |
| 70 | acl_e->e_perm = be16_to_cpu(ace->ae_perm); |
| 71 | |
| 72 | switch (acl_e->e_tag) { |
| 73 | case ACL_USER: |
Christoph Hellwig | ba8adad | 2020-02-21 08:31:27 -0800 | [diff] [blame] | 74 | acl_e->e_uid = make_kuid(&init_user_ns, |
| 75 | be32_to_cpu(ace->ae_id)); |
Dwight Engen | 288bbe0 | 2013-08-15 14:07:59 -0400 | [diff] [blame] | 76 | break; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 77 | case ACL_GROUP: |
Christoph Hellwig | ba8adad | 2020-02-21 08:31:27 -0800 | [diff] [blame] | 78 | acl_e->e_gid = make_kgid(&init_user_ns, |
| 79 | be32_to_cpu(ace->ae_id)); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 80 | break; |
| 81 | case ACL_USER_OBJ: |
| 82 | case ACL_GROUP_OBJ: |
| 83 | case ACL_MASK: |
| 84 | case ACL_OTHER: |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 85 | break; |
| 86 | default: |
| 87 | goto fail; |
| 88 | } |
| 89 | } |
| 90 | return acl; |
| 91 | |
| 92 | fail: |
| 93 | posix_acl_release(acl); |
| 94 | return ERR_PTR(-EINVAL); |
| 95 | } |
| 96 | |
| 97 | STATIC void |
| 98 | xfs_acl_to_disk(struct xfs_acl *aclp, const struct posix_acl *acl) |
| 99 | { |
| 100 | const struct posix_acl_entry *acl_e; |
| 101 | struct xfs_acl_entry *ace; |
| 102 | int i; |
| 103 | |
| 104 | aclp->acl_cnt = cpu_to_be32(acl->a_count); |
| 105 | for (i = 0; i < acl->a_count; i++) { |
| 106 | ace = &aclp->acl_entry[i]; |
| 107 | acl_e = &acl->a_entries[i]; |
| 108 | |
| 109 | ace->ae_tag = cpu_to_be32(acl_e->e_tag); |
Dwight Engen | 288bbe0 | 2013-08-15 14:07:59 -0400 | [diff] [blame] | 110 | switch (acl_e->e_tag) { |
| 111 | case ACL_USER: |
Christoph Hellwig | ba8adad | 2020-02-21 08:31:27 -0800 | [diff] [blame] | 112 | ace->ae_id = cpu_to_be32( |
| 113 | from_kuid(&init_user_ns, acl_e->e_uid)); |
Dwight Engen | 288bbe0 | 2013-08-15 14:07:59 -0400 | [diff] [blame] | 114 | break; |
| 115 | case ACL_GROUP: |
Christoph Hellwig | ba8adad | 2020-02-21 08:31:27 -0800 | [diff] [blame] | 116 | ace->ae_id = cpu_to_be32( |
| 117 | from_kgid(&init_user_ns, acl_e->e_gid)); |
Dwight Engen | 288bbe0 | 2013-08-15 14:07:59 -0400 | [diff] [blame] | 118 | break; |
| 119 | default: |
| 120 | ace->ae_id = cpu_to_be32(ACL_UNDEFINED_ID); |
| 121 | break; |
| 122 | } |
| 123 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 124 | ace->ae_perm = cpu_to_be16(acl_e->e_perm); |
| 125 | } |
| 126 | } |
| 127 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 128 | struct posix_acl * |
Miklos Szeredi | 0cad624 | 2021-08-18 22:08:24 +0200 | [diff] [blame] | 129 | xfs_get_acl(struct inode *inode, int type, bool rcu) |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 130 | { |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 131 | struct xfs_inode *ip = XFS_I(inode); |
| 132 | struct xfs_mount *mp = ip->i_mount; |
| 133 | struct posix_acl *acl = NULL; |
| 134 | struct xfs_da_args args = { |
| 135 | .dp = ip, |
Christoph Hellwig | d5f0f49 | 2020-02-26 17:30:42 -0800 | [diff] [blame] | 136 | .attr_filter = XFS_ATTR_ROOT, |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 137 | .valuelen = XFS_ACL_MAX_SIZE(mp), |
| 138 | }; |
| 139 | int error; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 140 | |
Miklos Szeredi | 0cad624 | 2021-08-18 22:08:24 +0200 | [diff] [blame] | 141 | if (rcu) |
| 142 | return ERR_PTR(-ECHILD); |
| 143 | |
Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 144 | trace_xfs_get_acl(ip); |
| 145 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 146 | switch (type) { |
| 147 | case ACL_TYPE_ACCESS: |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 148 | args.name = SGI_ACL_FILE; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 149 | break; |
| 150 | case ACL_TYPE_DEFAULT: |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 151 | args.name = SGI_ACL_DEFAULT; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 152 | break; |
| 153 | default: |
Al Viro | 1cbd20d | 2009-06-09 13:29:39 -0400 | [diff] [blame] | 154 | BUG(); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 155 | } |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 156 | args.namelen = strlen(args.name); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 157 | |
Christoph Hellwig | d49db18 | 2020-02-26 17:30:35 -0800 | [diff] [blame] | 158 | /* |
| 159 | * If the attribute doesn't exist make sure we have a negative cache |
| 160 | * entry, for any other error assume it is transient. |
| 161 | */ |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 162 | error = xfs_attr_get(&args); |
Christoph Hellwig | d49db18 | 2020-02-26 17:30:35 -0800 | [diff] [blame] | 163 | if (!error) { |
Christoph Hellwig | e5171d7 | 2020-02-26 17:30:34 -0800 | [diff] [blame] | 164 | acl = xfs_acl_from_disk(mp, args.value, args.valuelen, |
| 165 | XFS_ACL_MAX_ENTRIES(mp)); |
Christoph Hellwig | d49db18 | 2020-02-26 17:30:35 -0800 | [diff] [blame] | 166 | } else if (error != -ENOATTR) { |
| 167 | acl = ERR_PTR(error); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 168 | } |
Christoph Hellwig | d49db18 | 2020-02-26 17:30:35 -0800 | [diff] [blame] | 169 | |
| 170 | kmem_free(args.value); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 171 | return acl; |
| 172 | } |
| 173 | |
Jan Kara | 8ba3587 | 2017-06-26 08:48:18 -0700 | [diff] [blame] | 174 | int |
| 175 | __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 176 | { |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 177 | struct xfs_inode *ip = XFS_I(inode); |
| 178 | struct xfs_da_args args = { |
| 179 | .dp = ip, |
Christoph Hellwig | d5f0f49 | 2020-02-26 17:30:42 -0800 | [diff] [blame] | 180 | .attr_filter = XFS_ATTR_ROOT, |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 181 | }; |
| 182 | int error; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 183 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 184 | switch (type) { |
| 185 | case ACL_TYPE_ACCESS: |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 186 | args.name = SGI_ACL_FILE; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 187 | break; |
| 188 | case ACL_TYPE_DEFAULT: |
| 189 | if (!S_ISDIR(inode->i_mode)) |
| 190 | return acl ? -EACCES : 0; |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 191 | args.name = SGI_ACL_DEFAULT; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 192 | break; |
| 193 | default: |
| 194 | return -EINVAL; |
| 195 | } |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 196 | args.namelen = strlen(args.name); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 197 | |
| 198 | if (acl) { |
Christoph Hellwig | ed02d13 | 2020-02-26 17:30:44 -0800 | [diff] [blame] | 199 | args.valuelen = XFS_ACL_SIZE(acl->a_count); |
Carlos Maiolino | 8ca79df | 2020-09-01 11:47:12 -0700 | [diff] [blame] | 200 | args.value = kvzalloc(args.valuelen, GFP_KERNEL); |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 201 | if (!args.value) |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 202 | return -ENOMEM; |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 203 | xfs_acl_to_disk(args.value, acl); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Darrick J. Wong | efc2efe | 2022-05-27 10:34:04 +1000 | [diff] [blame] | 206 | error = xfs_attr_change(&args); |
Christoph Hellwig | a254462 | 2020-02-26 17:30:33 -0800 | [diff] [blame] | 207 | kmem_free(args.value); |
Christoph Hellwig | 0eb81a5 | 2020-02-26 17:30:29 -0800 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * If the attribute didn't exist to start with that's fine. |
| 211 | */ |
| 212 | if (!acl && error == -ENOATTR) |
| 213 | error = 0; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 214 | if (!error) |
Al Viro | 1cbd20d | 2009-06-09 13:29:39 -0400 | [diff] [blame] | 215 | set_cached_acl(inode, type, acl); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 216 | return error; |
| 217 | } |
| 218 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 219 | static int |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 220 | xfs_acl_set_mode( |
| 221 | struct inode *inode, |
| 222 | umode_t mode) |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 223 | { |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 224 | struct xfs_inode *ip = XFS_I(inode); |
| 225 | struct xfs_mount *mp = ip->i_mount; |
| 226 | struct xfs_trans *tp; |
| 227 | int error; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 228 | |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 229 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); |
| 230 | if (error) |
| 231 | return error; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 232 | |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 233 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 234 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
| 235 | inode->i_mode = mode; |
| 236 | inode->i_ctime = current_time(inode); |
| 237 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 238 | |
Dave Chinner | 0560f31 | 2021-08-18 18:46:52 -0700 | [diff] [blame] | 239 | if (xfs_has_wsync(mp)) |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 240 | xfs_trans_set_sync(tp); |
| 241 | return xfs_trans_commit(tp); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 244 | int |
Christian Brauner | 13e83a4 | 2023-01-13 12:49:20 +0100 | [diff] [blame] | 245 | xfs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 246 | struct posix_acl *acl, int type) |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 247 | { |
Dave Chinner | 67f2ffe | 2017-10-09 11:37:23 -0700 | [diff] [blame] | 248 | umode_t mode; |
| 249 | bool set_mode = false; |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 250 | int error = 0; |
Christian Brauner | 138060b | 2022-09-23 10:29:39 +0200 | [diff] [blame] | 251 | struct inode *inode = d_inode(dentry); |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 252 | |
Christoph Hellwig | 2401dc2 | 2013-12-20 05:16:50 -0800 | [diff] [blame] | 253 | if (!acl) |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 254 | goto set_acl; |
| 255 | |
Jie Liu | 4ae69fe | 2014-02-07 15:26:11 +1100 | [diff] [blame] | 256 | error = -E2BIG; |
Dave Chinner | 0a8aa19 | 2013-06-05 12:09:10 +1000 | [diff] [blame] | 257 | if (acl->a_count > XFS_ACL_MAX_ENTRIES(XFS_M(inode->i_sb))) |
Christoph Hellwig | 2401dc2 | 2013-12-20 05:16:50 -0800 | [diff] [blame] | 258 | return error; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 259 | |
| 260 | if (type == ACL_TYPE_ACCESS) { |
Christian Brauner | 700b794 | 2023-01-13 12:49:24 +0100 | [diff] [blame] | 261 | error = posix_acl_update_mode(idmap, inode, &mode, &acl); |
Jan Kara | 0739310 | 2016-09-19 17:39:09 +0200 | [diff] [blame] | 262 | if (error) |
| 263 | return error; |
Dave Chinner | 67f2ffe | 2017-10-09 11:37:23 -0700 | [diff] [blame] | 264 | set_mode = true; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | set_acl: |
Dave Chinner | 67f2ffe | 2017-10-09 11:37:23 -0700 | [diff] [blame] | 268 | /* |
| 269 | * We set the mode after successfully updating the ACL xattr because the |
| 270 | * xattr update can fail at ENOSPC and we don't want to change the mode |
| 271 | * if the ACL update hasn't been applied. |
| 272 | */ |
Christoph Hellwig | 5d24ec4c | 2020-12-10 20:00:39 -0800 | [diff] [blame] | 273 | error = __xfs_set_acl(inode, acl, type); |
| 274 | if (!error && set_mode && mode != inode->i_mode) |
| 275 | error = xfs_acl_set_mode(inode, mode); |
Dave Chinner | 67f2ffe | 2017-10-09 11:37:23 -0700 | [diff] [blame] | 276 | return error; |
Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 277 | } |
Christoph Hellwig | 5a3930e | 2020-02-26 17:30:41 -0800 | [diff] [blame] | 278 | |
| 279 | /* |
| 280 | * Invalidate any cached ACLs if the user has bypassed the ACL interface. |
| 281 | * We don't validate the content whatsoever so it is caller responsibility to |
| 282 | * provide data in valid format and ensure i_mode is consistent. |
| 283 | */ |
| 284 | void |
| 285 | xfs_forget_acl( |
| 286 | struct inode *inode, |
| 287 | const char *name) |
| 288 | { |
| 289 | if (!strcmp(name, SGI_ACL_FILE)) |
| 290 | forget_cached_acl(inode, ACL_TYPE_ACCESS); |
| 291 | else if (!strcmp(name, SGI_ACL_DEFAULT)) |
| 292 | forget_cached_acl(inode, ACL_TYPE_DEFAULT); |
| 293 | } |