Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | File: fs/xattr.c |
| 3 | |
| 4 | Extended attribute handling. |
| 5 | |
| 6 | Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org> |
| 7 | Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com> |
| 8 | Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com> |
| 9 | */ |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/file.h> |
| 13 | #include <linux/xattr.h> |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 14 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/namei.h> |
| 16 | #include <linux/security.h> |
Mimi Zohar | c7b87de | 2011-03-09 14:39:18 -0500 | [diff] [blame] | 17 | #include <linux/evm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/syscalls.h> |
Paul Gortmaker | 630d9c4 | 2011-11-16 23:57:37 -0500 | [diff] [blame] | 19 | #include <linux/export.h> |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 20 | #include <linux/fsnotify.h> |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 21 | #include <linux/audit.h> |
Andrew Morton | 0d08d7b | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 22 | #include <linux/vmalloc.h> |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 23 | #include <linux/posix_acl_xattr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Andrew Morton | 0d08d7b | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 25 | #include <asm/uaccess.h> |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 26 | |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 27 | /* |
| 28 | * Check permissions for extended attribute access. This is a bit complicated |
| 29 | * because different namespaces have very different rules. |
| 30 | */ |
| 31 | static int |
| 32 | xattr_permission(struct inode *inode, const char *name, int mask) |
| 33 | { |
| 34 | /* |
| 35 | * We can never set or remove an extended attribute on a read-only |
| 36 | * filesystem or on an immutable / append-only inode. |
| 37 | */ |
| 38 | if (mask & MAY_WRITE) { |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 39 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
| 40 | return -EPERM; |
Eric W. Biederman | 0bd23d09 | 2016-06-29 14:54:46 -0500 | [diff] [blame^] | 41 | /* |
| 42 | * Updating an xattr will likely cause i_uid and i_gid |
| 43 | * to be writen back improperly if their true value is |
| 44 | * unknown to the vfs. |
| 45 | */ |
| 46 | if (HAS_UNMAPPED_ID(inode)) |
| 47 | return -EPERM; |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* |
| 51 | * No restriction for security.* and system.* from the VFS. Decision |
| 52 | * on these is left to the underlying filesystem / security module. |
| 53 | */ |
| 54 | if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) || |
| 55 | !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) |
| 56 | return 0; |
| 57 | |
| 58 | /* |
Andreas Gruenbacher | 55b23bd | 2011-05-27 14:50:36 +0200 | [diff] [blame] | 59 | * The trusted.* namespace can only be accessed by privileged users. |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 60 | */ |
Andreas Gruenbacher | 55b23bd | 2011-05-27 14:50:36 +0200 | [diff] [blame] | 61 | if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) { |
| 62 | if (!capable(CAP_SYS_ADMIN)) |
| 63 | return (mask & MAY_WRITE) ? -EPERM : -ENODATA; |
| 64 | return 0; |
| 65 | } |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 66 | |
Andreas Gruenbacher | 55b23bd | 2011-05-27 14:50:36 +0200 | [diff] [blame] | 67 | /* |
| 68 | * In the user.* namespace, only regular files and directories can have |
Andreas Gruenbacher | f1f2d87 | 2006-11-02 22:07:29 -0800 | [diff] [blame] | 69 | * extended attributes. For sticky directories, only the owner and |
Andreas Gruenbacher | 55b23bd | 2011-05-27 14:50:36 +0200 | [diff] [blame] | 70 | * privileged users can write attributes. |
Andreas Gruenbacher | f1f2d87 | 2006-11-02 22:07:29 -0800 | [diff] [blame] | 71 | */ |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 72 | if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) { |
Andreas Gruenbacher | f1f2d87 | 2006-11-02 22:07:29 -0800 | [diff] [blame] | 73 | if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) |
Andreas Gruenbacher | 55b23bd | 2011-05-27 14:50:36 +0200 | [diff] [blame] | 74 | return (mask & MAY_WRITE) ? -EPERM : -ENODATA; |
Andreas Gruenbacher | f1f2d87 | 2006-11-02 22:07:29 -0800 | [diff] [blame] | 75 | if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) && |
Serge E. Hallyn | 2e14967 | 2011-03-23 16:43:26 -0700 | [diff] [blame] | 76 | (mask & MAY_WRITE) && !inode_owner_or_capable(inode)) |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 77 | return -EPERM; |
| 78 | } |
| 79 | |
Al Viro | f419a2e | 2008-07-22 00:07:17 -0400 | [diff] [blame] | 80 | return inode_permission(inode, mask); |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 81 | } |
| 82 | |
David P. Quigley | b1ab7e4 | 2009-09-03 14:25:56 -0400 | [diff] [blame] | 83 | /** |
| 84 | * __vfs_setxattr_noperm - perform setxattr operation without performing |
| 85 | * permission checks. |
| 86 | * |
| 87 | * @dentry - object to perform setxattr on |
| 88 | * @name - xattr name to set |
| 89 | * @value - value to set @name to |
| 90 | * @size - size of @value |
| 91 | * @flags - flags to pass into filesystem operations |
| 92 | * |
| 93 | * returns the result of the internal setxattr or setsecurity operations. |
| 94 | * |
| 95 | * This function requires the caller to lock the inode's i_mutex before it |
| 96 | * is executed. It also assumes that the caller will make the appropriate |
| 97 | * permission checks. |
| 98 | */ |
| 99 | int __vfs_setxattr_noperm(struct dentry *dentry, const char *name, |
| 100 | const void *value, size_t size, int flags) |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 101 | { |
| 102 | struct inode *inode = dentry->d_inode; |
David P. Quigley | b1ab7e4 | 2009-09-03 14:25:56 -0400 | [diff] [blame] | 103 | int error = -EOPNOTSUPP; |
Andi Kleen | 69b4573 | 2011-05-28 08:25:51 -0700 | [diff] [blame] | 104 | int issec = !strncmp(name, XATTR_SECURITY_PREFIX, |
| 105 | XATTR_SECURITY_PREFIX_LEN); |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 106 | |
Andi Kleen | 69b4573 | 2011-05-28 08:25:51 -0700 | [diff] [blame] | 107 | if (issec) |
| 108 | inode->i_flags &= ~S_NOSEC; |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 109 | if (inode->i_op->setxattr) { |
Al Viro | 3767e25 | 2016-05-27 11:06:05 -0400 | [diff] [blame] | 110 | error = inode->i_op->setxattr(dentry, inode, name, value, size, flags); |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 111 | if (!error) { |
| 112 | fsnotify_xattr(dentry); |
| 113 | security_inode_post_setxattr(dentry, name, value, |
| 114 | size, flags); |
| 115 | } |
Andi Kleen | 69b4573 | 2011-05-28 08:25:51 -0700 | [diff] [blame] | 116 | } else if (issec) { |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 117 | const char *suffix = name + XATTR_SECURITY_PREFIX_LEN; |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 118 | error = security_inode_setsecurity(inode, suffix, value, |
| 119 | size, flags); |
| 120 | if (!error) |
| 121 | fsnotify_xattr(dentry); |
| 122 | } |
David P. Quigley | b1ab7e4 | 2009-09-03 14:25:56 -0400 | [diff] [blame] | 123 | |
| 124 | return error; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | int |
| 129 | vfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
| 130 | size_t size, int flags) |
| 131 | { |
| 132 | struct inode *inode = dentry->d_inode; |
| 133 | int error; |
| 134 | |
| 135 | error = xattr_permission(inode, name, MAY_WRITE); |
| 136 | if (error) |
| 137 | return error; |
| 138 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 139 | inode_lock(inode); |
David P. Quigley | b1ab7e4 | 2009-09-03 14:25:56 -0400 | [diff] [blame] | 140 | error = security_inode_setxattr(dentry, name, value, size, flags); |
| 141 | if (error) |
| 142 | goto out; |
| 143 | |
| 144 | error = __vfs_setxattr_noperm(dentry, name, value, size, flags); |
| 145 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 146 | out: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 147 | inode_unlock(inode); |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 148 | return error; |
| 149 | } |
| 150 | EXPORT_SYMBOL_GPL(vfs_setxattr); |
| 151 | |
| 152 | ssize_t |
David P. Quigley | 4249259 | 2008-02-04 22:29:39 -0800 | [diff] [blame] | 153 | xattr_getsecurity(struct inode *inode, const char *name, void *value, |
| 154 | size_t size) |
| 155 | { |
| 156 | void *buffer = NULL; |
| 157 | ssize_t len; |
| 158 | |
| 159 | if (!value || !size) { |
| 160 | len = security_inode_getsecurity(inode, name, &buffer, false); |
| 161 | goto out_noalloc; |
| 162 | } |
| 163 | |
| 164 | len = security_inode_getsecurity(inode, name, &buffer, true); |
| 165 | if (len < 0) |
| 166 | return len; |
| 167 | if (size < len) { |
| 168 | len = -ERANGE; |
| 169 | goto out; |
| 170 | } |
| 171 | memcpy(value, buffer, len); |
| 172 | out: |
| 173 | security_release_secctx(buffer, len); |
| 174 | out_noalloc: |
| 175 | return len; |
| 176 | } |
| 177 | EXPORT_SYMBOL_GPL(xattr_getsecurity); |
| 178 | |
Mimi Zohar | 1601fba | 2011-03-09 14:23:34 -0500 | [diff] [blame] | 179 | /* |
| 180 | * vfs_getxattr_alloc - allocate memory, if necessary, before calling getxattr |
| 181 | * |
| 182 | * Allocate memory, if not already allocated, or re-allocate correct size, |
| 183 | * before retrieving the extended attribute. |
| 184 | * |
| 185 | * Returns the result of alloc, if failed, or the getxattr operation. |
| 186 | */ |
| 187 | ssize_t |
| 188 | vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, |
| 189 | size_t xattr_size, gfp_t flags) |
| 190 | { |
| 191 | struct inode *inode = dentry->d_inode; |
| 192 | char *value = *xattr_value; |
| 193 | int error; |
| 194 | |
| 195 | error = xattr_permission(inode, name, MAY_READ); |
| 196 | if (error) |
| 197 | return error; |
| 198 | |
| 199 | if (!inode->i_op->getxattr) |
| 200 | return -EOPNOTSUPP; |
| 201 | |
Al Viro | ce23e64 | 2016-04-11 00:48:00 -0400 | [diff] [blame] | 202 | error = inode->i_op->getxattr(dentry, inode, name, NULL, 0); |
Mimi Zohar | 1601fba | 2011-03-09 14:23:34 -0500 | [diff] [blame] | 203 | if (error < 0) |
| 204 | return error; |
| 205 | |
| 206 | if (!value || (error > xattr_size)) { |
| 207 | value = krealloc(*xattr_value, error + 1, flags); |
| 208 | if (!value) |
| 209 | return -ENOMEM; |
| 210 | memset(value, 0, error + 1); |
| 211 | } |
| 212 | |
Al Viro | ce23e64 | 2016-04-11 00:48:00 -0400 | [diff] [blame] | 213 | error = inode->i_op->getxattr(dentry, inode, name, value, error); |
Mimi Zohar | 1601fba | 2011-03-09 14:23:34 -0500 | [diff] [blame] | 214 | *xattr_value = value; |
| 215 | return error; |
| 216 | } |
| 217 | |
David P. Quigley | 4249259 | 2008-02-04 22:29:39 -0800 | [diff] [blame] | 218 | ssize_t |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 219 | vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 220 | { |
| 221 | struct inode *inode = dentry->d_inode; |
| 222 | int error; |
| 223 | |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 224 | error = xattr_permission(inode, name, MAY_READ); |
| 225 | if (error) |
| 226 | return error; |
| 227 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 228 | error = security_inode_getxattr(dentry, name); |
| 229 | if (error) |
| 230 | return error; |
| 231 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 232 | if (!strncmp(name, XATTR_SECURITY_PREFIX, |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 233 | XATTR_SECURITY_PREFIX_LEN)) { |
| 234 | const char *suffix = name + XATTR_SECURITY_PREFIX_LEN; |
David P. Quigley | 4249259 | 2008-02-04 22:29:39 -0800 | [diff] [blame] | 235 | int ret = xattr_getsecurity(inode, suffix, value, size); |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 236 | /* |
| 237 | * Only overwrite the return value if a security module |
| 238 | * is actually active. |
| 239 | */ |
David P. Quigley | 4bea580 | 2008-02-04 22:29:40 -0800 | [diff] [blame] | 240 | if (ret == -EOPNOTSUPP) |
| 241 | goto nolsm; |
| 242 | return ret; |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 243 | } |
David P. Quigley | 4bea580 | 2008-02-04 22:29:40 -0800 | [diff] [blame] | 244 | nolsm: |
| 245 | if (inode->i_op->getxattr) |
Al Viro | ce23e64 | 2016-04-11 00:48:00 -0400 | [diff] [blame] | 246 | error = inode->i_op->getxattr(dentry, inode, name, value, size); |
David P. Quigley | 4bea580 | 2008-02-04 22:29:40 -0800 | [diff] [blame] | 247 | else |
| 248 | error = -EOPNOTSUPP; |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 249 | |
| 250 | return error; |
| 251 | } |
| 252 | EXPORT_SYMBOL_GPL(vfs_getxattr); |
| 253 | |
Bill Nottingham | 659564c | 2006-10-09 16:10:48 -0400 | [diff] [blame] | 254 | ssize_t |
| 255 | vfs_listxattr(struct dentry *d, char *list, size_t size) |
| 256 | { |
| 257 | ssize_t error; |
| 258 | |
| 259 | error = security_inode_listxattr(d); |
| 260 | if (error) |
| 261 | return error; |
| 262 | error = -EOPNOTSUPP; |
Al Viro | acfa438 | 2008-12-04 10:06:33 -0500 | [diff] [blame] | 263 | if (d->d_inode->i_op->listxattr) { |
Bill Nottingham | 659564c | 2006-10-09 16:10:48 -0400 | [diff] [blame] | 264 | error = d->d_inode->i_op->listxattr(d, list, size); |
| 265 | } else { |
| 266 | error = security_inode_listsecurity(d->d_inode, list, size); |
| 267 | if (size && error > size) |
| 268 | error = -ERANGE; |
| 269 | } |
| 270 | return error; |
| 271 | } |
| 272 | EXPORT_SYMBOL_GPL(vfs_listxattr); |
| 273 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 274 | int |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 275 | vfs_removexattr(struct dentry *dentry, const char *name) |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 276 | { |
| 277 | struct inode *inode = dentry->d_inode; |
| 278 | int error; |
| 279 | |
| 280 | if (!inode->i_op->removexattr) |
| 281 | return -EOPNOTSUPP; |
| 282 | |
akpm@osdl.org | e0ad7b0 | 2006-01-09 20:51:56 -0800 | [diff] [blame] | 283 | error = xattr_permission(inode, name, MAY_WRITE); |
| 284 | if (error) |
| 285 | return error; |
| 286 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 287 | inode_lock(inode); |
Mimi Zohar | 2ab51f3 | 2011-03-23 17:23:06 -0400 | [diff] [blame] | 288 | error = security_inode_removexattr(dentry, name); |
Dmitry Kasatkin | 7c51bb00 | 2014-11-20 16:31:01 +0200 | [diff] [blame] | 289 | if (error) |
| 290 | goto out; |
Mimi Zohar | 2ab51f3 | 2011-03-23 17:23:06 -0400 | [diff] [blame] | 291 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 292 | error = inode->i_op->removexattr(dentry, name); |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 293 | |
Mimi Zohar | c7b87de | 2011-03-09 14:39:18 -0500 | [diff] [blame] | 294 | if (!error) { |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 295 | fsnotify_xattr(dentry); |
Mimi Zohar | c7b87de | 2011-03-09 14:39:18 -0500 | [diff] [blame] | 296 | evm_inode_post_removexattr(dentry, name); |
| 297 | } |
Dmitry Kasatkin | 7c51bb00 | 2014-11-20 16:31:01 +0200 | [diff] [blame] | 298 | |
| 299 | out: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 300 | inode_unlock(inode); |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 301 | return error; |
| 302 | } |
| 303 | EXPORT_SYMBOL_GPL(vfs_removexattr); |
| 304 | |
| 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | /* |
| 307 | * Extended attribute SET operations |
| 308 | */ |
| 309 | static long |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 310 | setxattr(struct dentry *d, const char __user *name, const void __user *value, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | size_t size, int flags) |
| 312 | { |
| 313 | int error; |
| 314 | void *kvalue = NULL; |
| 315 | char kname[XATTR_NAME_MAX + 1]; |
| 316 | |
| 317 | if (flags & ~(XATTR_CREATE|XATTR_REPLACE)) |
| 318 | return -EINVAL; |
| 319 | |
| 320 | error = strncpy_from_user(kname, name, sizeof(kname)); |
| 321 | if (error == 0 || error == sizeof(kname)) |
| 322 | error = -ERANGE; |
| 323 | if (error < 0) |
| 324 | return error; |
| 325 | |
| 326 | if (size) { |
| 327 | if (size > XATTR_SIZE_MAX) |
| 328 | return -E2BIG; |
Andrew Morton | 44c8249 | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 329 | kvalue = kmalloc(size, GFP_KERNEL | __GFP_NOWARN); |
| 330 | if (!kvalue) { |
Richard Weinberger | 0b2a6f2 | 2016-01-02 23:09:47 +0100 | [diff] [blame] | 331 | kvalue = vmalloc(size); |
| 332 | if (!kvalue) |
Andrew Morton | 44c8249 | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 333 | return -ENOMEM; |
Andrew Morton | 44c8249 | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 334 | } |
| 335 | if (copy_from_user(kvalue, value, size)) { |
| 336 | error = -EFAULT; |
| 337 | goto out; |
| 338 | } |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 339 | if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) || |
| 340 | (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) |
| 341 | posix_acl_fix_xattr_from_user(kvalue, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 344 | error = vfs_setxattr(d, kname, kvalue, size, flags); |
Andrew Morton | 44c8249 | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 345 | out: |
Richard Weinberger | 0b2a6f2 | 2016-01-02 23:09:47 +0100 | [diff] [blame] | 346 | kvfree(kvalue); |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | return error; |
| 349 | } |
| 350 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 351 | static int path_setxattr(const char __user *pathname, |
| 352 | const char __user *name, const void __user *value, |
| 353 | size_t size, int flags, unsigned int lookup_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 355 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | int error; |
Jeff Layton | 68f1bb8 | 2012-12-11 12:10:15 -0500 | [diff] [blame] | 357 | retry: |
| 358 | error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (error) |
| 360 | return error; |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 361 | error = mnt_want_write(path.mnt); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 362 | if (!error) { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 363 | error = setxattr(path.dentry, name, value, size, flags); |
| 364 | mnt_drop_write(path.mnt); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 365 | } |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 366 | path_put(&path); |
Jeff Layton | 68f1bb8 | 2012-12-11 12:10:15 -0500 | [diff] [blame] | 367 | if (retry_estale(error, lookup_flags)) { |
| 368 | lookup_flags |= LOOKUP_REVAL; |
| 369 | goto retry; |
| 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return error; |
| 372 | } |
| 373 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 374 | SYSCALL_DEFINE5(setxattr, const char __user *, pathname, |
| 375 | const char __user *, name, const void __user *, value, |
| 376 | size_t, size, int, flags) |
| 377 | { |
| 378 | return path_setxattr(pathname, name, value, size, flags, LOOKUP_FOLLOW); |
| 379 | } |
| 380 | |
Heiko Carstens | 64fd1de | 2009-01-14 14:14:14 +0100 | [diff] [blame] | 381 | SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname, |
| 382 | const char __user *, name, const void __user *, value, |
| 383 | size_t, size, int, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 385 | return path_setxattr(pathname, name, value, size, flags, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Heiko Carstens | 64fd1de | 2009-01-14 14:14:14 +0100 | [diff] [blame] | 388 | SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, |
| 389 | const void __user *,value, size_t, size, int, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 391 | struct fd f = fdget(fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | int error = -EBADF; |
| 393 | |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 394 | if (!f.file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return error; |
Al Viro | 9f45f5b | 2014-10-31 17:44:57 -0400 | [diff] [blame] | 396 | audit_file(f.file); |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 397 | error = mnt_want_write_file(f.file); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 398 | if (!error) { |
Al Viro | 9f45f5b | 2014-10-31 17:44:57 -0400 | [diff] [blame] | 399 | error = setxattr(f.file->f_path.dentry, name, value, size, flags); |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 400 | mnt_drop_write_file(f.file); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 401 | } |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 402 | fdput(f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return error; |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * Extended attribute GET operations |
| 408 | */ |
| 409 | static ssize_t |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 410 | getxattr(struct dentry *d, const char __user *name, void __user *value, |
| 411 | size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
| 413 | ssize_t error; |
| 414 | void *kvalue = NULL; |
| 415 | char kname[XATTR_NAME_MAX + 1]; |
| 416 | |
| 417 | error = strncpy_from_user(kname, name, sizeof(kname)); |
| 418 | if (error == 0 || error == sizeof(kname)) |
| 419 | error = -ERANGE; |
| 420 | if (error < 0) |
| 421 | return error; |
| 422 | |
| 423 | if (size) { |
| 424 | if (size > XATTR_SIZE_MAX) |
| 425 | size = XATTR_SIZE_MAX; |
Sasha Levin | 779302e | 2012-07-30 14:39:13 -0700 | [diff] [blame] | 426 | kvalue = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); |
| 427 | if (!kvalue) { |
Richard Weinberger | 0b2a6f2 | 2016-01-02 23:09:47 +0100 | [diff] [blame] | 428 | kvalue = vmalloc(size); |
| 429 | if (!kvalue) |
Sasha Levin | 779302e | 2012-07-30 14:39:13 -0700 | [diff] [blame] | 430 | return -ENOMEM; |
Sasha Levin | 779302e | 2012-07-30 14:39:13 -0700 | [diff] [blame] | 431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 434 | error = vfs_getxattr(d, kname, kvalue, size); |
Stephen Smalley | f549d6c | 2005-09-03 15:55:18 -0700 | [diff] [blame] | 435 | if (error > 0) { |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 436 | if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) || |
| 437 | (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) |
| 438 | posix_acl_fix_xattr_to_user(kvalue, size); |
Stephen Smalley | f549d6c | 2005-09-03 15:55:18 -0700 | [diff] [blame] | 439 | if (size && copy_to_user(value, kvalue, error)) |
| 440 | error = -EFAULT; |
| 441 | } else if (error == -ERANGE && size >= XATTR_SIZE_MAX) { |
| 442 | /* The file system tried to returned a value bigger |
| 443 | than XATTR_SIZE_MAX bytes. Not possible. */ |
| 444 | error = -E2BIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
Richard Weinberger | 0b2a6f2 | 2016-01-02 23:09:47 +0100 | [diff] [blame] | 446 | |
| 447 | kvfree(kvalue); |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | return error; |
| 450 | } |
| 451 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 452 | static ssize_t path_getxattr(const char __user *pathname, |
| 453 | const char __user *name, void __user *value, |
| 454 | size_t size, unsigned int lookup_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 456 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | ssize_t error; |
Jeff Layton | 60e66b4 | 2012-12-11 12:10:16 -0500 | [diff] [blame] | 458 | retry: |
| 459 | error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (error) |
| 461 | return error; |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 462 | error = getxattr(path.dentry, name, value, size); |
| 463 | path_put(&path); |
Jeff Layton | 60e66b4 | 2012-12-11 12:10:16 -0500 | [diff] [blame] | 464 | if (retry_estale(error, lookup_flags)) { |
| 465 | lookup_flags |= LOOKUP_REVAL; |
| 466 | goto retry; |
| 467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return error; |
| 469 | } |
| 470 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 471 | SYSCALL_DEFINE4(getxattr, const char __user *, pathname, |
| 472 | const char __user *, name, void __user *, value, size_t, size) |
| 473 | { |
| 474 | return path_getxattr(pathname, name, value, size, LOOKUP_FOLLOW); |
| 475 | } |
| 476 | |
Heiko Carstens | 64fd1de | 2009-01-14 14:14:14 +0100 | [diff] [blame] | 477 | SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname, |
| 478 | const char __user *, name, void __user *, value, size_t, size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 480 | return path_getxattr(pathname, name, value, size, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Heiko Carstens | 64fd1de | 2009-01-14 14:14:14 +0100 | [diff] [blame] | 483 | SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, |
| 484 | void __user *, value, size_t, size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 486 | struct fd f = fdget(fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | ssize_t error = -EBADF; |
| 488 | |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 489 | if (!f.file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | return error; |
Al Viro | 9f45f5b | 2014-10-31 17:44:57 -0400 | [diff] [blame] | 491 | audit_file(f.file); |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 492 | error = getxattr(f.file->f_path.dentry, name, value, size); |
| 493 | fdput(f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return error; |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * Extended attribute LIST operations |
| 499 | */ |
| 500 | static ssize_t |
| 501 | listxattr(struct dentry *d, char __user *list, size_t size) |
| 502 | { |
| 503 | ssize_t error; |
| 504 | char *klist = NULL; |
| 505 | |
| 506 | if (size) { |
| 507 | if (size > XATTR_LIST_MAX) |
| 508 | size = XATTR_LIST_MAX; |
Dave Jones | 703bf2d | 2012-04-05 14:25:06 -0700 | [diff] [blame] | 509 | klist = kmalloc(size, __GFP_NOWARN | GFP_KERNEL); |
Andrew Morton | 0d08d7b | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 510 | if (!klist) { |
Richard Weinberger | 0b2a6f2 | 2016-01-02 23:09:47 +0100 | [diff] [blame] | 511 | klist = vmalloc(size); |
| 512 | if (!klist) |
Andrew Morton | 0d08d7b | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 513 | return -ENOMEM; |
Andrew Morton | 0d08d7b | 2012-04-05 14:25:07 -0700 | [diff] [blame] | 514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Bill Nottingham | 659564c | 2006-10-09 16:10:48 -0400 | [diff] [blame] | 517 | error = vfs_listxattr(d, klist, size); |
Stephen Smalley | f549d6c | 2005-09-03 15:55:18 -0700 | [diff] [blame] | 518 | if (error > 0) { |
| 519 | if (size && copy_to_user(list, klist, error)) |
| 520 | error = -EFAULT; |
| 521 | } else if (error == -ERANGE && size >= XATTR_LIST_MAX) { |
| 522 | /* The file system tried to returned a list bigger |
| 523 | than XATTR_LIST_MAX bytes. Not possible. */ |
| 524 | error = -E2BIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
Richard Weinberger | 0b2a6f2 | 2016-01-02 23:09:47 +0100 | [diff] [blame] | 526 | |
| 527 | kvfree(klist); |
| 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | return error; |
| 530 | } |
| 531 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 532 | static ssize_t path_listxattr(const char __user *pathname, char __user *list, |
| 533 | size_t size, unsigned int lookup_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 535 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | ssize_t error; |
Jeff Layton | 10a90cf | 2012-12-11 12:10:16 -0500 | [diff] [blame] | 537 | retry: |
| 538 | error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | if (error) |
| 540 | return error; |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 541 | error = listxattr(path.dentry, list, size); |
| 542 | path_put(&path); |
Jeff Layton | 10a90cf | 2012-12-11 12:10:16 -0500 | [diff] [blame] | 543 | if (retry_estale(error, lookup_flags)) { |
| 544 | lookup_flags |= LOOKUP_REVAL; |
| 545 | goto retry; |
| 546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | return error; |
| 548 | } |
| 549 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 550 | SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list, |
| 551 | size_t, size) |
| 552 | { |
| 553 | return path_listxattr(pathname, list, size, LOOKUP_FOLLOW); |
| 554 | } |
| 555 | |
Heiko Carstens | 64fd1de | 2009-01-14 14:14:14 +0100 | [diff] [blame] | 556 | SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list, |
| 557 | size_t, size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 559 | return path_listxattr(pathname, list, size, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Heiko Carstens | 64fd1de | 2009-01-14 14:14:14 +0100 | [diff] [blame] | 562 | SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 564 | struct fd f = fdget(fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | ssize_t error = -EBADF; |
| 566 | |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 567 | if (!f.file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | return error; |
Al Viro | 9f45f5b | 2014-10-31 17:44:57 -0400 | [diff] [blame] | 569 | audit_file(f.file); |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 570 | error = listxattr(f.file->f_path.dentry, list, size); |
| 571 | fdput(f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return error; |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | * Extended attribute REMOVE operations |
| 577 | */ |
| 578 | static long |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 579 | removexattr(struct dentry *d, const char __user *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
| 581 | int error; |
| 582 | char kname[XATTR_NAME_MAX + 1]; |
| 583 | |
| 584 | error = strncpy_from_user(kname, name, sizeof(kname)); |
| 585 | if (error == 0 || error == sizeof(kname)) |
| 586 | error = -ERANGE; |
| 587 | if (error < 0) |
| 588 | return error; |
| 589 | |
Christoph Hellwig | 5be196e | 2006-01-09 20:51:55 -0800 | [diff] [blame] | 590 | return vfs_removexattr(d, kname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 593 | static int path_removexattr(const char __user *pathname, |
| 594 | const char __user *name, unsigned int lookup_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 596 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | int error; |
Jeff Layton | 12f0621 | 2012-12-11 12:10:17 -0500 | [diff] [blame] | 598 | retry: |
| 599 | error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | if (error) |
| 601 | return error; |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 602 | error = mnt_want_write(path.mnt); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 603 | if (!error) { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 604 | error = removexattr(path.dentry, name); |
| 605 | mnt_drop_write(path.mnt); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 606 | } |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 607 | path_put(&path); |
Jeff Layton | 12f0621 | 2012-12-11 12:10:17 -0500 | [diff] [blame] | 608 | if (retry_estale(error, lookup_flags)) { |
| 609 | lookup_flags |= LOOKUP_REVAL; |
| 610 | goto retry; |
| 611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | return error; |
| 613 | } |
| 614 | |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 615 | SYSCALL_DEFINE2(removexattr, const char __user *, pathname, |
| 616 | const char __user *, name) |
| 617 | { |
| 618 | return path_removexattr(pathname, name, LOOKUP_FOLLOW); |
| 619 | } |
| 620 | |
Heiko Carstens | 6a6160a | 2009-01-14 14:14:15 +0100 | [diff] [blame] | 621 | SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname, |
| 622 | const char __user *, name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
Eric Biggers | 8cc4311 | 2014-10-12 11:59:58 -0500 | [diff] [blame] | 624 | return path_removexattr(pathname, name, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Heiko Carstens | 6a6160a | 2009-01-14 14:14:15 +0100 | [diff] [blame] | 627 | SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 629 | struct fd f = fdget(fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | int error = -EBADF; |
| 631 | |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 632 | if (!f.file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return error; |
Al Viro | 9f45f5b | 2014-10-31 17:44:57 -0400 | [diff] [blame] | 634 | audit_file(f.file); |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 635 | error = mnt_want_write_file(f.file); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 636 | if (!error) { |
Al Viro | 9f45f5b | 2014-10-31 17:44:57 -0400 | [diff] [blame] | 637 | error = removexattr(f.file->f_path.dentry, name); |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 638 | mnt_drop_write_file(f.file); |
Dave Hansen | 18f335a | 2008-02-15 14:37:38 -0800 | [diff] [blame] | 639 | } |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 640 | fdput(f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return error; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | static const char * |
| 646 | strcmp_prefix(const char *a, const char *a_prefix) |
| 647 | { |
| 648 | while (*a_prefix && *a == *a_prefix) { |
| 649 | a++; |
| 650 | a_prefix++; |
| 651 | } |
| 652 | return *a_prefix ? NULL : a; |
| 653 | } |
| 654 | |
| 655 | /* |
| 656 | * In order to implement different sets of xattr operations for each xattr |
| 657 | * prefix with the generic xattr API, a filesystem should create a |
| 658 | * null-terminated array of struct xattr_handler (one for each prefix) and |
| 659 | * hang a pointer to it off of the s_xattr field of the superblock. |
| 660 | * |
| 661 | * The generic_fooxattr() functions will use this list to dispatch xattr |
| 662 | * operations to the correct xattr_handler. |
| 663 | */ |
| 664 | #define for_each_xattr_handler(handlers, handler) \ |
Al Viro | 0040773 | 2016-05-25 17:34:41 -0400 | [diff] [blame] | 665 | if (handlers) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | for ((handler) = *(handlers)++; \ |
| 667 | (handler) != NULL; \ |
| 668 | (handler) = *(handlers)++) |
| 669 | |
| 670 | /* |
| 671 | * Find the xattr_handler with the matching prefix. |
| 672 | */ |
Stephen Hemminger | bb43545 | 2010-05-13 17:53:14 -0700 | [diff] [blame] | 673 | static const struct xattr_handler * |
| 674 | xattr_resolve_name(const struct xattr_handler **handlers, const char **name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Stephen Hemminger | bb43545 | 2010-05-13 17:53:14 -0700 | [diff] [blame] | 676 | const struct xattr_handler *handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | if (!*name) |
Andreas Gruenbacher | aaf431b | 2016-05-09 13:28:49 +0200 | [diff] [blame] | 679 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
| 681 | for_each_xattr_handler(handlers, handler) { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 682 | const char *n; |
| 683 | |
| 684 | n = strcmp_prefix(*name, xattr_prefix(handler)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | if (n) { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 686 | if (!handler->prefix ^ !*n) { |
| 687 | if (*n) |
| 688 | continue; |
| 689 | return ERR_PTR(-EINVAL); |
| 690 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | *name = n; |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 692 | return handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 695 | return ERR_PTR(-EOPNOTSUPP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /* |
| 699 | * Find the handler for the prefix and dispatch its get() operation. |
| 700 | */ |
| 701 | ssize_t |
Al Viro | ce23e64 | 2016-04-11 00:48:00 -0400 | [diff] [blame] | 702 | generic_getxattr(struct dentry *dentry, struct inode *inode, |
| 703 | const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
Stephen Hemminger | bb43545 | 2010-05-13 17:53:14 -0700 | [diff] [blame] | 705 | const struct xattr_handler *handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 707 | handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 708 | if (IS_ERR(handler)) |
| 709 | return PTR_ERR(handler); |
Al Viro | ce23e64 | 2016-04-11 00:48:00 -0400 | [diff] [blame] | 710 | return handler->get(handler, dentry, inode, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 711 | name, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /* |
| 715 | * Combine the results of the list() operation from every xattr_handler in the |
| 716 | * list. |
| 717 | */ |
| 718 | ssize_t |
| 719 | generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) |
| 720 | { |
Stephen Hemminger | bb43545 | 2010-05-13 17:53:14 -0700 | [diff] [blame] | 721 | const struct xattr_handler *handler, **handlers = dentry->d_sb->s_xattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | unsigned int size = 0; |
| 723 | |
| 724 | if (!buffer) { |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 725 | for_each_xattr_handler(handlers, handler) { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 726 | if (!handler->name || |
| 727 | (handler->list && !handler->list(dentry))) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 728 | continue; |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 729 | size += strlen(handler->name) + 1; |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 730 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } else { |
| 732 | char *buf = buffer; |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 733 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | for_each_xattr_handler(handlers, handler) { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 736 | if (!handler->name || |
| 737 | (handler->list && !handler->list(dentry))) |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 738 | continue; |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 739 | len = strlen(handler->name); |
| 740 | if (len + 1 > buffer_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | return -ERANGE; |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 742 | memcpy(buf, handler->name, len + 1); |
| 743 | buf += len + 1; |
| 744 | buffer_size -= len + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
| 746 | size = buf - buffer; |
| 747 | } |
| 748 | return size; |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | * Find the handler for the prefix and dispatch its set() operation. |
| 753 | */ |
| 754 | int |
Al Viro | 3767e25 | 2016-05-27 11:06:05 -0400 | [diff] [blame] | 755 | generic_setxattr(struct dentry *dentry, struct inode *inode, const char *name, |
| 756 | const void *value, size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
Stephen Hemminger | bb43545 | 2010-05-13 17:53:14 -0700 | [diff] [blame] | 758 | const struct xattr_handler *handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | if (size == 0) |
| 761 | value = ""; /* empty EA, do not remove */ |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 762 | handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 763 | if (IS_ERR(handler)) |
| 764 | return PTR_ERR(handler); |
Al Viro | 3767e25 | 2016-05-27 11:06:05 -0400 | [diff] [blame] | 765 | return handler->set(handler, dentry, inode, name, value, size, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /* |
| 769 | * Find the handler for the prefix and dispatch its set() operation to remove |
| 770 | * any associated extended attribute. |
| 771 | */ |
| 772 | int |
| 773 | generic_removexattr(struct dentry *dentry, const char *name) |
| 774 | { |
Stephen Hemminger | bb43545 | 2010-05-13 17:53:14 -0700 | [diff] [blame] | 775 | const struct xattr_handler *handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 777 | handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 778 | if (IS_ERR(handler)) |
| 779 | return PTR_ERR(handler); |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 780 | return handler->set(handler, dentry, d_inode(dentry), name, NULL, |
| 781 | 0, XATTR_REPLACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | EXPORT_SYMBOL(generic_getxattr); |
| 785 | EXPORT_SYMBOL(generic_listxattr); |
| 786 | EXPORT_SYMBOL(generic_setxattr); |
| 787 | EXPORT_SYMBOL(generic_removexattr); |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 788 | |
Andreas Gruenbacher | e409de9 | 2015-10-04 19:18:52 +0200 | [diff] [blame] | 789 | /** |
| 790 | * xattr_full_name - Compute full attribute name from suffix |
| 791 | * |
| 792 | * @handler: handler of the xattr_handler operation |
| 793 | * @name: name passed to the xattr_handler operation |
| 794 | * |
| 795 | * The get and set xattr handler operations are called with the remainder of |
| 796 | * the attribute name after skipping the handler's prefix: for example, "foo" |
| 797 | * is passed to the get operation of a handler with prefix "user." to get |
| 798 | * attribute "user.foo". The full name is still "there" in the name though. |
| 799 | * |
| 800 | * Note: the list xattr handler operation when called from the vfs is passed a |
| 801 | * NULL name; some file systems use this operation internally, with varying |
| 802 | * semantics. |
| 803 | */ |
| 804 | const char *xattr_full_name(const struct xattr_handler *handler, |
| 805 | const char *name) |
| 806 | { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 807 | size_t prefix_len = strlen(xattr_prefix(handler)); |
Andreas Gruenbacher | e409de9 | 2015-10-04 19:18:52 +0200 | [diff] [blame] | 808 | |
| 809 | return name - prefix_len; |
| 810 | } |
| 811 | EXPORT_SYMBOL(xattr_full_name); |
| 812 | |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 813 | /* |
| 814 | * Allocate new xattr and copy in the value; but leave the name to callers. |
| 815 | */ |
| 816 | struct simple_xattr *simple_xattr_alloc(const void *value, size_t size) |
| 817 | { |
| 818 | struct simple_xattr *new_xattr; |
| 819 | size_t len; |
| 820 | |
| 821 | /* wrap around? */ |
| 822 | len = sizeof(*new_xattr) + size; |
Hugh Dickins | 4e66d44 | 2014-07-23 14:00:17 -0700 | [diff] [blame] | 823 | if (len < sizeof(*new_xattr)) |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 824 | return NULL; |
| 825 | |
| 826 | new_xattr = kmalloc(len, GFP_KERNEL); |
| 827 | if (!new_xattr) |
| 828 | return NULL; |
| 829 | |
| 830 | new_xattr->size = size; |
| 831 | memcpy(new_xattr->value, value, size); |
| 832 | return new_xattr; |
| 833 | } |
| 834 | |
| 835 | /* |
| 836 | * xattr GET operation for in-memory/pseudo filesystems |
| 837 | */ |
| 838 | int simple_xattr_get(struct simple_xattrs *xattrs, const char *name, |
| 839 | void *buffer, size_t size) |
| 840 | { |
| 841 | struct simple_xattr *xattr; |
| 842 | int ret = -ENODATA; |
| 843 | |
| 844 | spin_lock(&xattrs->lock); |
| 845 | list_for_each_entry(xattr, &xattrs->head, list) { |
| 846 | if (strcmp(name, xattr->name)) |
| 847 | continue; |
| 848 | |
| 849 | ret = xattr->size; |
| 850 | if (buffer) { |
| 851 | if (size < xattr->size) |
| 852 | ret = -ERANGE; |
| 853 | else |
| 854 | memcpy(buffer, xattr->value, xattr->size); |
| 855 | } |
| 856 | break; |
| 857 | } |
| 858 | spin_unlock(&xattrs->lock); |
| 859 | return ret; |
| 860 | } |
| 861 | |
Andreas Gruenbacher | aa7c524 | 2015-12-02 14:44:38 +0100 | [diff] [blame] | 862 | /** |
| 863 | * simple_xattr_set - xattr SET operation for in-memory/pseudo filesystems |
| 864 | * @xattrs: target simple_xattr list |
| 865 | * @name: name of the extended attribute |
| 866 | * @value: value of the xattr. If %NULL, will remove the attribute. |
| 867 | * @size: size of the new xattr |
| 868 | * @flags: %XATTR_{CREATE|REPLACE} |
| 869 | * |
| 870 | * %XATTR_CREATE is set, the xattr shouldn't exist already; otherwise fails |
| 871 | * with -EEXIST. If %XATTR_REPLACE is set, the xattr should exist; |
| 872 | * otherwise, fails with -ENODATA. |
| 873 | * |
| 874 | * Returns 0 on success, -errno on failure. |
| 875 | */ |
| 876 | int simple_xattr_set(struct simple_xattrs *xattrs, const char *name, |
| 877 | const void *value, size_t size, int flags) |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 878 | { |
| 879 | struct simple_xattr *xattr; |
David Rientjes | 4338584 | 2012-10-17 20:41:15 -0700 | [diff] [blame] | 880 | struct simple_xattr *new_xattr = NULL; |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 881 | int err = 0; |
| 882 | |
| 883 | /* value == NULL means remove */ |
| 884 | if (value) { |
| 885 | new_xattr = simple_xattr_alloc(value, size); |
| 886 | if (!new_xattr) |
| 887 | return -ENOMEM; |
| 888 | |
| 889 | new_xattr->name = kstrdup(name, GFP_KERNEL); |
| 890 | if (!new_xattr->name) { |
| 891 | kfree(new_xattr); |
| 892 | return -ENOMEM; |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | spin_lock(&xattrs->lock); |
| 897 | list_for_each_entry(xattr, &xattrs->head, list) { |
| 898 | if (!strcmp(name, xattr->name)) { |
| 899 | if (flags & XATTR_CREATE) { |
| 900 | xattr = new_xattr; |
| 901 | err = -EEXIST; |
| 902 | } else if (new_xattr) { |
| 903 | list_replace(&xattr->list, &new_xattr->list); |
| 904 | } else { |
| 905 | list_del(&xattr->list); |
| 906 | } |
| 907 | goto out; |
| 908 | } |
| 909 | } |
| 910 | if (flags & XATTR_REPLACE) { |
| 911 | xattr = new_xattr; |
| 912 | err = -ENODATA; |
| 913 | } else { |
| 914 | list_add(&new_xattr->list, &xattrs->head); |
| 915 | xattr = NULL; |
| 916 | } |
| 917 | out: |
| 918 | spin_unlock(&xattrs->lock); |
| 919 | if (xattr) { |
| 920 | kfree(xattr->name); |
| 921 | kfree(xattr); |
| 922 | } |
| 923 | return err; |
| 924 | |
| 925 | } |
| 926 | |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 927 | static bool xattr_is_trusted(const char *name) |
| 928 | { |
| 929 | return !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN); |
| 930 | } |
| 931 | |
Andreas Gruenbacher | 786534b | 2015-12-02 14:44:39 +0100 | [diff] [blame] | 932 | static int xattr_list_one(char **buffer, ssize_t *remaining_size, |
| 933 | const char *name) |
| 934 | { |
| 935 | size_t len = strlen(name) + 1; |
| 936 | if (*buffer) { |
| 937 | if (*remaining_size < len) |
| 938 | return -ERANGE; |
| 939 | memcpy(*buffer, name, len); |
| 940 | *buffer += len; |
| 941 | } |
| 942 | *remaining_size -= len; |
| 943 | return 0; |
| 944 | } |
| 945 | |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 946 | /* |
| 947 | * xattr LIST operation for in-memory/pseudo filesystems |
| 948 | */ |
Andreas Gruenbacher | 786534b | 2015-12-02 14:44:39 +0100 | [diff] [blame] | 949 | ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs, |
| 950 | char *buffer, size_t size) |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 951 | { |
| 952 | bool trusted = capable(CAP_SYS_ADMIN); |
| 953 | struct simple_xattr *xattr; |
Andreas Gruenbacher | 786534b | 2015-12-02 14:44:39 +0100 | [diff] [blame] | 954 | ssize_t remaining_size = size; |
Mateusz Guzik | 0e9a7da | 2016-02-04 02:56:30 +0100 | [diff] [blame] | 955 | int err = 0; |
Andreas Gruenbacher | 786534b | 2015-12-02 14:44:39 +0100 | [diff] [blame] | 956 | |
| 957 | #ifdef CONFIG_FS_POSIX_ACL |
| 958 | if (inode->i_acl) { |
| 959 | err = xattr_list_one(&buffer, &remaining_size, |
| 960 | XATTR_NAME_POSIX_ACL_ACCESS); |
| 961 | if (err) |
| 962 | return err; |
| 963 | } |
| 964 | if (inode->i_default_acl) { |
| 965 | err = xattr_list_one(&buffer, &remaining_size, |
| 966 | XATTR_NAME_POSIX_ACL_DEFAULT); |
| 967 | if (err) |
| 968 | return err; |
| 969 | } |
| 970 | #endif |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 971 | |
| 972 | spin_lock(&xattrs->lock); |
| 973 | list_for_each_entry(xattr, &xattrs->head, list) { |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 974 | /* skip "trusted." attributes for unprivileged callers */ |
| 975 | if (!trusted && xattr_is_trusted(xattr->name)) |
| 976 | continue; |
| 977 | |
Andreas Gruenbacher | 786534b | 2015-12-02 14:44:39 +0100 | [diff] [blame] | 978 | err = xattr_list_one(&buffer, &remaining_size, xattr->name); |
| 979 | if (err) |
Mateusz Guzik | 0e9a7da | 2016-02-04 02:56:30 +0100 | [diff] [blame] | 980 | break; |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 981 | } |
| 982 | spin_unlock(&xattrs->lock); |
| 983 | |
Mateusz Guzik | 0e9a7da | 2016-02-04 02:56:30 +0100 | [diff] [blame] | 984 | return err ? err : size - remaining_size; |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Aristeu Rozanski | 4895768 | 2012-09-11 16:28:11 -0400 | [diff] [blame] | 987 | /* |
| 988 | * Adds an extended attribute to the list |
| 989 | */ |
Aristeu Rozanski | 38f3865 | 2012-08-23 16:53:28 -0400 | [diff] [blame] | 990 | void simple_xattr_list_add(struct simple_xattrs *xattrs, |
| 991 | struct simple_xattr *new_xattr) |
| 992 | { |
| 993 | spin_lock(&xattrs->lock); |
| 994 | list_add(&new_xattr->list, &xattrs->head); |
| 995 | spin_unlock(&xattrs->lock); |
| 996 | } |