1 // SPDX-License-Identifier: GPL-2.0-only
5 Extended attribute handling.
7 Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
8 Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
9 Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
12 #include <linux/slab.h>
13 #include <linux/file.h>
14 #include <linux/xattr.h>
15 #include <linux/mount.h>
16 #include <linux/namei.h>
17 #include <linux/security.h>
18 #include <linux/evm.h>
19 #include <linux/syscalls.h>
20 #include <linux/export.h>
21 #include <linux/fsnotify.h>
22 #include <linux/audit.h>
23 #include <linux/vmalloc.h>
24 #include <linux/posix_acl_xattr.h>
26 #include <linux/uaccess.h>
29 strcmp_prefix(const char *a, const char *a_prefix)
31 while (*a_prefix && *a == *a_prefix) {
35 return *a_prefix ? NULL : a;
39 * In order to implement different sets of xattr operations for each xattr
40 * prefix, a filesystem should create a null-terminated array of struct
41 * xattr_handler (one for each prefix) and hang a pointer to it off of the
42 * s_xattr field of the superblock.
44 #define for_each_xattr_handler(handlers, handler) \
46 for ((handler) = *(handlers)++; \
48 (handler) = *(handlers)++)
51 * Find the xattr_handler with the matching prefix.
53 static const struct xattr_handler *
54 xattr_resolve_name(struct inode *inode, const char **name)
56 const struct xattr_handler **handlers = inode->i_sb->s_xattr;
57 const struct xattr_handler *handler;
59 if (!(inode->i_opflags & IOP_XATTR)) {
60 if (unlikely(is_bad_inode(inode)))
62 return ERR_PTR(-EOPNOTSUPP);
64 for_each_xattr_handler(handlers, handler) {
67 n = strcmp_prefix(*name, xattr_prefix(handler));
69 if (!handler->prefix ^ !*n) {
72 return ERR_PTR(-EINVAL);
78 return ERR_PTR(-EOPNOTSUPP);
82 * Check permissions for extended attribute access. This is a bit complicated
83 * because different namespaces have very different rules.
86 xattr_permission(struct inode *inode, const char *name, int mask)
89 * We can never set or remove an extended attribute on a read-only
90 * filesystem or on an immutable / append-only inode.
92 if (mask & MAY_WRITE) {
93 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
96 * Updating an xattr will likely cause i_uid and i_gid
97 * to be writen back improperly if their true value is
100 if (HAS_UNMAPPED_ID(inode))
105 * No restriction for security.* and system.* from the VFS. Decision
106 * on these is left to the underlying filesystem / security module.
108 if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) ||
109 !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
113 * The trusted.* namespace can only be accessed by privileged users.
115 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
116 if (!capable(CAP_SYS_ADMIN))
117 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
122 * In the user.* namespace, only regular files and directories can have
123 * extended attributes. For sticky directories, only the owner and
124 * privileged users can write attributes.
126 if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
127 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
128 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
129 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
130 (mask & MAY_WRITE) &&
131 !inode_owner_or_capable(&init_user_ns, inode))
135 return inode_permission(&init_user_ns, inode, mask);
139 * Look for any handler that deals with the specified namespace.
142 xattr_supported_namespace(struct inode *inode, const char *prefix)
144 const struct xattr_handler **handlers = inode->i_sb->s_xattr;
145 const struct xattr_handler *handler;
148 if (!(inode->i_opflags & IOP_XATTR)) {
149 if (unlikely(is_bad_inode(inode)))
154 preflen = strlen(prefix);
156 for_each_xattr_handler(handlers, handler) {
157 if (!strncmp(xattr_prefix(handler), prefix, preflen))
163 EXPORT_SYMBOL(xattr_supported_namespace);
166 __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
167 const void *value, size_t size, int flags)
169 const struct xattr_handler *handler;
171 handler = xattr_resolve_name(inode, &name);
173 return PTR_ERR(handler);
177 value = ""; /* empty EA, do not remove */
178 return handler->set(handler, &init_user_ns, dentry, inode, name, value,
181 EXPORT_SYMBOL(__vfs_setxattr);
184 * __vfs_setxattr_noperm - perform setxattr operation without performing
187 * @dentry - object to perform setxattr on
188 * @name - xattr name to set
189 * @value - value to set @name to
190 * @size - size of @value
191 * @flags - flags to pass into filesystem operations
193 * returns the result of the internal setxattr or setsecurity operations.
195 * This function requires the caller to lock the inode's i_mutex before it
196 * is executed. It also assumes that the caller will make the appropriate
199 int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
200 const void *value, size_t size, int flags)
202 struct inode *inode = dentry->d_inode;
204 int issec = !strncmp(name, XATTR_SECURITY_PREFIX,
205 XATTR_SECURITY_PREFIX_LEN);
208 inode->i_flags &= ~S_NOSEC;
209 if (inode->i_opflags & IOP_XATTR) {
210 error = __vfs_setxattr(dentry, inode, name, value, size, flags);
212 fsnotify_xattr(dentry);
213 security_inode_post_setxattr(dentry, name, value,
217 if (unlikely(is_bad_inode(inode)))
220 if (error == -EAGAIN) {
224 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
226 error = security_inode_setsecurity(inode, suffix, value,
229 fsnotify_xattr(dentry);
237 * __vfs_setxattr_locked - set an extended attribute while holding the inode
240 * @dentry: object to perform setxattr on
241 * @name: xattr name to set
242 * @value: value to set @name to
243 * @size: size of @value
244 * @flags: flags to pass into filesystem operations
245 * @delegated_inode: on return, will contain an inode pointer that
246 * a delegation was broken on, NULL if none.
249 __vfs_setxattr_locked(struct dentry *dentry, const char *name,
250 const void *value, size_t size, int flags,
251 struct inode **delegated_inode)
253 struct inode *inode = dentry->d_inode;
256 error = xattr_permission(inode, name, MAY_WRITE);
260 error = security_inode_setxattr(dentry, name, value, size, flags);
264 error = try_break_deleg(inode, delegated_inode);
268 error = __vfs_setxattr_noperm(dentry, name, value, size, flags);
273 EXPORT_SYMBOL_GPL(__vfs_setxattr_locked);
276 vfs_setxattr(struct dentry *dentry, const char *name, const void *value,
277 size_t size, int flags)
279 struct inode *inode = dentry->d_inode;
280 struct inode *delegated_inode = NULL;
281 const void *orig_value = value;
284 if (size && strcmp(name, XATTR_NAME_CAPS) == 0) {
285 error = cap_convert_nscap(&init_user_ns, dentry, &value, size);
293 error = __vfs_setxattr_locked(dentry, name, value, size, flags,
297 if (delegated_inode) {
298 error = break_deleg_wait(&delegated_inode);
302 if (value != orig_value)
307 EXPORT_SYMBOL_GPL(vfs_setxattr);
310 xattr_getsecurity(struct inode *inode, const char *name, void *value,
316 if (!value || !size) {
317 len = security_inode_getsecurity(inode, name, &buffer, false);
321 len = security_inode_getsecurity(inode, name, &buffer, true);
328 memcpy(value, buffer, len);
336 * vfs_getxattr_alloc - allocate memory, if necessary, before calling getxattr
338 * Allocate memory, if not already allocated, or re-allocate correct size,
339 * before retrieving the extended attribute.
341 * Returns the result of alloc, if failed, or the getxattr operation.
344 vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
345 size_t xattr_size, gfp_t flags)
347 const struct xattr_handler *handler;
348 struct inode *inode = dentry->d_inode;
349 char *value = *xattr_value;
352 error = xattr_permission(inode, name, MAY_READ);
356 handler = xattr_resolve_name(inode, &name);
358 return PTR_ERR(handler);
361 error = handler->get(handler, dentry, inode, name, NULL, 0);
365 if (!value || (error > xattr_size)) {
366 value = krealloc(*xattr_value, error + 1, flags);
369 memset(value, 0, error + 1);
372 error = handler->get(handler, dentry, inode, name, value, error);
373 *xattr_value = value;
378 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
379 void *value, size_t size)
381 const struct xattr_handler *handler;
383 handler = xattr_resolve_name(inode, &name);
385 return PTR_ERR(handler);
388 return handler->get(handler, dentry, inode, name, value, size);
390 EXPORT_SYMBOL(__vfs_getxattr);
393 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
395 struct inode *inode = dentry->d_inode;
398 error = xattr_permission(inode, name, MAY_READ);
402 error = security_inode_getxattr(dentry, name);
406 if (!strncmp(name, XATTR_SECURITY_PREFIX,
407 XATTR_SECURITY_PREFIX_LEN)) {
408 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
409 int ret = xattr_getsecurity(inode, suffix, value, size);
411 * Only overwrite the return value if a security module
412 * is actually active.
414 if (ret == -EOPNOTSUPP)
419 return __vfs_getxattr(dentry, inode, name, value, size);
421 EXPORT_SYMBOL_GPL(vfs_getxattr);
424 vfs_listxattr(struct dentry *dentry, char *list, size_t size)
426 struct inode *inode = d_inode(dentry);
429 error = security_inode_listxattr(dentry);
432 if (inode->i_op->listxattr && (inode->i_opflags & IOP_XATTR)) {
433 error = inode->i_op->listxattr(dentry, list, size);
435 error = security_inode_listsecurity(inode, list, size);
436 if (size && error > size)
441 EXPORT_SYMBOL_GPL(vfs_listxattr);
444 __vfs_removexattr(struct dentry *dentry, const char *name)
446 struct inode *inode = d_inode(dentry);
447 const struct xattr_handler *handler;
449 handler = xattr_resolve_name(inode, &name);
451 return PTR_ERR(handler);
454 return handler->set(handler, &init_user_ns, dentry, inode, name, NULL,
457 EXPORT_SYMBOL(__vfs_removexattr);
460 * __vfs_removexattr_locked - set an extended attribute while holding the inode
463 * @dentry: object to perform setxattr on
464 * @name: name of xattr to remove
465 * @delegated_inode: on return, will contain an inode pointer that
466 * a delegation was broken on, NULL if none.
469 __vfs_removexattr_locked(struct dentry *dentry, const char *name,
470 struct inode **delegated_inode)
472 struct inode *inode = dentry->d_inode;
475 error = xattr_permission(inode, name, MAY_WRITE);
479 error = security_inode_removexattr(dentry, name);
483 error = try_break_deleg(inode, delegated_inode);
487 error = __vfs_removexattr(dentry, name);
490 fsnotify_xattr(dentry);
491 evm_inode_post_removexattr(dentry, name);
497 EXPORT_SYMBOL_GPL(__vfs_removexattr_locked);
500 vfs_removexattr(struct dentry *dentry, const char *name)
502 struct inode *inode = dentry->d_inode;
503 struct inode *delegated_inode = NULL;
508 error = __vfs_removexattr_locked(dentry, name, &delegated_inode);
511 if (delegated_inode) {
512 error = break_deleg_wait(&delegated_inode);
519 EXPORT_SYMBOL_GPL(vfs_removexattr);
522 * Extended attribute SET operations
525 setxattr(struct dentry *d, const char __user *name, const void __user *value,
526 size_t size, int flags)
530 char kname[XATTR_NAME_MAX + 1];
532 if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
535 error = strncpy_from_user(kname, name, sizeof(kname));
536 if (error == 0 || error == sizeof(kname))
542 if (size > XATTR_SIZE_MAX)
544 kvalue = kvmalloc(size, GFP_KERNEL);
547 if (copy_from_user(kvalue, value, size)) {
551 if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
552 (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
553 posix_acl_fix_xattr_from_user(&init_user_ns, kvalue,
557 error = vfs_setxattr(d, kname, kvalue, size, flags);
564 static int path_setxattr(const char __user *pathname,
565 const char __user *name, const void __user *value,
566 size_t size, int flags, unsigned int lookup_flags)
571 error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
574 error = mnt_want_write(path.mnt);
576 error = setxattr(path.dentry, name, value, size, flags);
577 mnt_drop_write(path.mnt);
580 if (retry_estale(error, lookup_flags)) {
581 lookup_flags |= LOOKUP_REVAL;
587 SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
588 const char __user *, name, const void __user *, value,
589 size_t, size, int, flags)
591 return path_setxattr(pathname, name, value, size, flags, LOOKUP_FOLLOW);
594 SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
595 const char __user *, name, const void __user *, value,
596 size_t, size, int, flags)
598 return path_setxattr(pathname, name, value, size, flags, 0);
601 SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
602 const void __user *,value, size_t, size, int, flags)
604 struct fd f = fdget(fd);
610 error = mnt_want_write_file(f.file);
612 error = setxattr(f.file->f_path.dentry, name, value, size, flags);
613 mnt_drop_write_file(f.file);
620 * Extended attribute GET operations
623 getxattr(struct dentry *d, const char __user *name, void __user *value,
628 char kname[XATTR_NAME_MAX + 1];
630 error = strncpy_from_user(kname, name, sizeof(kname));
631 if (error == 0 || error == sizeof(kname))
637 if (size > XATTR_SIZE_MAX)
638 size = XATTR_SIZE_MAX;
639 kvalue = kvzalloc(size, GFP_KERNEL);
644 error = vfs_getxattr(d, kname, kvalue, size);
646 if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
647 (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
648 posix_acl_fix_xattr_to_user(&init_user_ns, kvalue,
650 if (size && copy_to_user(value, kvalue, error))
652 } else if (error == -ERANGE && size >= XATTR_SIZE_MAX) {
653 /* The file system tried to returned a value bigger
654 than XATTR_SIZE_MAX bytes. Not possible. */
663 static ssize_t path_getxattr(const char __user *pathname,
664 const char __user *name, void __user *value,
665 size_t size, unsigned int lookup_flags)
670 error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
673 error = getxattr(path.dentry, name, value, size);
675 if (retry_estale(error, lookup_flags)) {
676 lookup_flags |= LOOKUP_REVAL;
682 SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
683 const char __user *, name, void __user *, value, size_t, size)
685 return path_getxattr(pathname, name, value, size, LOOKUP_FOLLOW);
688 SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
689 const char __user *, name, void __user *, value, size_t, size)
691 return path_getxattr(pathname, name, value, size, 0);
694 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
695 void __user *, value, size_t, size)
697 struct fd f = fdget(fd);
698 ssize_t error = -EBADF;
703 error = getxattr(f.file->f_path.dentry, name, value, size);
709 * Extended attribute LIST operations
712 listxattr(struct dentry *d, char __user *list, size_t size)
718 if (size > XATTR_LIST_MAX)
719 size = XATTR_LIST_MAX;
720 klist = kvmalloc(size, GFP_KERNEL);
725 error = vfs_listxattr(d, klist, size);
727 if (size && copy_to_user(list, klist, error))
729 } else if (error == -ERANGE && size >= XATTR_LIST_MAX) {
730 /* The file system tried to returned a list bigger
731 than XATTR_LIST_MAX bytes. Not possible. */
740 static ssize_t path_listxattr(const char __user *pathname, char __user *list,
741 size_t size, unsigned int lookup_flags)
746 error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
749 error = listxattr(path.dentry, list, size);
751 if (retry_estale(error, lookup_flags)) {
752 lookup_flags |= LOOKUP_REVAL;
758 SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
761 return path_listxattr(pathname, list, size, LOOKUP_FOLLOW);
764 SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
767 return path_listxattr(pathname, list, size, 0);
770 SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
772 struct fd f = fdget(fd);
773 ssize_t error = -EBADF;
778 error = listxattr(f.file->f_path.dentry, list, size);
784 * Extended attribute REMOVE operations
787 removexattr(struct dentry *d, const char __user *name)
790 char kname[XATTR_NAME_MAX + 1];
792 error = strncpy_from_user(kname, name, sizeof(kname));
793 if (error == 0 || error == sizeof(kname))
798 return vfs_removexattr(d, kname);
801 static int path_removexattr(const char __user *pathname,
802 const char __user *name, unsigned int lookup_flags)
807 error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
810 error = mnt_want_write(path.mnt);
812 error = removexattr(path.dentry, name);
813 mnt_drop_write(path.mnt);
816 if (retry_estale(error, lookup_flags)) {
817 lookup_flags |= LOOKUP_REVAL;
823 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
824 const char __user *, name)
826 return path_removexattr(pathname, name, LOOKUP_FOLLOW);
829 SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
830 const char __user *, name)
832 return path_removexattr(pathname, name, 0);
835 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
837 struct fd f = fdget(fd);
843 error = mnt_want_write_file(f.file);
845 error = removexattr(f.file->f_path.dentry, name);
846 mnt_drop_write_file(f.file);
853 * Combine the results of the list() operation from every xattr_handler in the
857 generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
859 const struct xattr_handler *handler, **handlers = dentry->d_sb->s_xattr;
860 unsigned int size = 0;
863 for_each_xattr_handler(handlers, handler) {
864 if (!handler->name ||
865 (handler->list && !handler->list(dentry)))
867 size += strlen(handler->name) + 1;
873 for_each_xattr_handler(handlers, handler) {
874 if (!handler->name ||
875 (handler->list && !handler->list(dentry)))
877 len = strlen(handler->name);
878 if (len + 1 > buffer_size)
880 memcpy(buf, handler->name, len + 1);
882 buffer_size -= len + 1;
888 EXPORT_SYMBOL(generic_listxattr);
891 * xattr_full_name - Compute full attribute name from suffix
893 * @handler: handler of the xattr_handler operation
894 * @name: name passed to the xattr_handler operation
896 * The get and set xattr handler operations are called with the remainder of
897 * the attribute name after skipping the handler's prefix: for example, "foo"
898 * is passed to the get operation of a handler with prefix "user." to get
899 * attribute "user.foo". The full name is still "there" in the name though.
901 * Note: the list xattr handler operation when called from the vfs is passed a
902 * NULL name; some file systems use this operation internally, with varying
905 const char *xattr_full_name(const struct xattr_handler *handler,
908 size_t prefix_len = strlen(xattr_prefix(handler));
910 return name - prefix_len;
912 EXPORT_SYMBOL(xattr_full_name);
915 * Allocate new xattr and copy in the value; but leave the name to callers.
917 struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
919 struct simple_xattr *new_xattr;
923 len = sizeof(*new_xattr) + size;
924 if (len < sizeof(*new_xattr))
927 new_xattr = kvmalloc(len, GFP_KERNEL);
931 new_xattr->size = size;
932 memcpy(new_xattr->value, value, size);
937 * xattr GET operation for in-memory/pseudo filesystems
939 int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
940 void *buffer, size_t size)
942 struct simple_xattr *xattr;
945 spin_lock(&xattrs->lock);
946 list_for_each_entry(xattr, &xattrs->head, list) {
947 if (strcmp(name, xattr->name))
952 if (size < xattr->size)
955 memcpy(buffer, xattr->value, xattr->size);
959 spin_unlock(&xattrs->lock);
964 * simple_xattr_set - xattr SET operation for in-memory/pseudo filesystems
965 * @xattrs: target simple_xattr list
966 * @name: name of the extended attribute
967 * @value: value of the xattr. If %NULL, will remove the attribute.
968 * @size: size of the new xattr
969 * @flags: %XATTR_{CREATE|REPLACE}
970 * @removed_size: returns size of the removed xattr, -1 if none removed
972 * %XATTR_CREATE is set, the xattr shouldn't exist already; otherwise fails
973 * with -EEXIST. If %XATTR_REPLACE is set, the xattr should exist;
974 * otherwise, fails with -ENODATA.
976 * Returns 0 on success, -errno on failure.
978 int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
979 const void *value, size_t size, int flags,
980 ssize_t *removed_size)
982 struct simple_xattr *xattr;
983 struct simple_xattr *new_xattr = NULL;
989 /* value == NULL means remove */
991 new_xattr = simple_xattr_alloc(value, size);
995 new_xattr->name = kstrdup(name, GFP_KERNEL);
996 if (!new_xattr->name) {
1002 spin_lock(&xattrs->lock);
1003 list_for_each_entry(xattr, &xattrs->head, list) {
1004 if (!strcmp(name, xattr->name)) {
1005 if (flags & XATTR_CREATE) {
1008 } else if (new_xattr) {
1009 list_replace(&xattr->list, &new_xattr->list);
1011 *removed_size = xattr->size;
1013 list_del(&xattr->list);
1015 *removed_size = xattr->size;
1020 if (flags & XATTR_REPLACE) {
1024 list_add(&new_xattr->list, &xattrs->head);
1028 spin_unlock(&xattrs->lock);
1037 static bool xattr_is_trusted(const char *name)
1039 return !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
1042 static int xattr_list_one(char **buffer, ssize_t *remaining_size,
1045 size_t len = strlen(name) + 1;
1047 if (*remaining_size < len)
1049 memcpy(*buffer, name, len);
1052 *remaining_size -= len;
1057 * xattr LIST operation for in-memory/pseudo filesystems
1059 ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs,
1060 char *buffer, size_t size)
1062 bool trusted = capable(CAP_SYS_ADMIN);
1063 struct simple_xattr *xattr;
1064 ssize_t remaining_size = size;
1067 #ifdef CONFIG_FS_POSIX_ACL
1068 if (IS_POSIXACL(inode)) {
1070 err = xattr_list_one(&buffer, &remaining_size,
1071 XATTR_NAME_POSIX_ACL_ACCESS);
1075 if (inode->i_default_acl) {
1076 err = xattr_list_one(&buffer, &remaining_size,
1077 XATTR_NAME_POSIX_ACL_DEFAULT);
1084 spin_lock(&xattrs->lock);
1085 list_for_each_entry(xattr, &xattrs->head, list) {
1086 /* skip "trusted." attributes for unprivileged callers */
1087 if (!trusted && xattr_is_trusted(xattr->name))
1090 err = xattr_list_one(&buffer, &remaining_size, xattr->name);
1094 spin_unlock(&xattrs->lock);
1096 return err ? err : size - remaining_size;
1100 * Adds an extended attribute to the list
1102 void simple_xattr_list_add(struct simple_xattrs *xattrs,
1103 struct simple_xattr *new_xattr)
1105 spin_lock(&xattrs->lock);
1106 list_add(&new_xattr->list, &xattrs->head);
1107 spin_unlock(&xattrs->lock);