11 #include <linux/slab.h>
13 #include <linux/xattr.h>
19 #include <linux/export.h>
21 #include <linux/audit.h>
25 #include <asm/uaccess.h>
95 struct inode *inode = dentry->
d_inode;
102 if (inode->
i_op->setxattr) {
103 error = inode->
i_op->setxattr(dentry, name, value, size, flags);
105 fsnotify_xattr(dentry);
114 fsnotify_xattr(dentry);
125 struct inode *inode = dentry->
d_inode;
128 error = xattr_permission(inode, name, MAY_WRITE);
152 if (!value || !size) {
164 memcpy(value, buffer, len);
184 struct inode *inode = dentry->
d_inode;
185 char *
value = *xattr_value;
188 error = xattr_permission(inode, name,
MAY_READ);
192 if (!inode->
i_op->getxattr)
195 error = inode->
i_op->getxattr(dentry, name,
NULL, 0);
199 if (!value || (error > xattr_size)) {
200 value =
krealloc(*xattr_value, error + 1, flags);
203 memset(value, 0, error + 1);
206 error = inode->
i_op->getxattr(dentry, name, value, error);
207 *xattr_value =
value;
215 char *xattr_value =
NULL;
222 if ((rc != size) || (
memcmp(xattr_value, value, rc) != 0))
233 struct inode *inode = dentry->
d_inode;
236 error = xattr_permission(inode, name,
MAY_READ);
257 if (inode->
i_op->getxattr)
258 error = inode->
i_op->getxattr(dentry, name, value, size);
275 if (d->
d_inode->i_op->listxattr) {
276 error = d->
d_inode->i_op->listxattr(d, list, size);
279 if (size && error > size)
289 struct inode *inode = dentry->
d_inode;
292 if (!inode->
i_op->removexattr)
295 error = xattr_permission(inode, name, MAY_WRITE);
306 error = inode->
i_op->removexattr(dentry, name);
310 fsnotify_xattr(dentry);
322 setxattr(
struct dentry *
d,
const char __user *name,
const void __user *
value,
334 if (error == 0 || error ==
sizeof(kname))
368 const char __user *, name,
const void __user *, value,
369 size_t, size,
int, flags)
379 error = setxattr(path.
dentry, name, value, size, flags);
387 const char __user *, name,
const void __user *, value,
388 size_t, size,
int, flags)
398 error = setxattr(path.
dentry, name, value, size, flags);
406 const void __user *,value,
size_t, size,
int, flags)
408 struct fd f = fdget(
fd);
414 dentry = f.
file->f_path.dentry;
415 audit_inode(
NULL, dentry, 0);
418 error = setxattr(dentry, name, value, size, flags);
429 getxattr(
struct dentry *d,
const char __user *name,
void __user *value,
438 if (error == 0 || error ==
sizeof(kname))
475 const char __user *, name,
void __user *, value,
size_t, size)
483 error = getxattr(path.
dentry, name, value, size);
489 const char __user *, name,
void __user *, value,
size_t, size)
497 error = getxattr(path.
dentry, name, value, size);
503 void __user *, value,
size_t, size)
505 struct fd f = fdget(
fd);
510 audit_inode(
NULL, f.
file->f_path.dentry, 0);
511 error = getxattr(f.
file->f_path.dentry, name, value, size);
520 listxattr(
struct dentry *d,
char __user *
list,
size_t size)
563 error = listxattr(path.
dentry, list, size);
577 error = listxattr(path.
dentry, list, size);
584 struct fd f = fdget(
fd);
589 audit_inode(
NULL, f.
file->f_path.dentry, 0);
590 error = listxattr(f.
file->f_path.dentry, list, size);
599 removexattr(
struct dentry *d,
const char __user *name)
605 if (error == 0 || error ==
sizeof(kname))
614 const char __user *, name)
624 error = removexattr(path.
dentry, name);
632 const char __user *, name)
642 error = removexattr(path.
dentry, name);
651 struct fd f = fdget(
fd);
657 dentry = f.
file->f_path.dentry;
658 audit_inode(
NULL, dentry, 0);
661 error = removexattr(dentry, name);
670 strcmp_prefix(
const char *
a,
const char *a_prefix)
672 while (*a_prefix && *a == *a_prefix) {
676 return *a_prefix ?
NULL :
a;
688 #define for_each_xattr_handler(handlers, handler) \
689 for ((handler) = *(handlers)++; \
691 (handler) = *(handlers)++)
697 xattr_resolve_name(
const struct xattr_handler **handlers,
const char **name)
705 const char *
n = strcmp_prefix(*name, handler->
prefix);
722 handler = xattr_resolve_name(dentry->
d_sb->s_xattr, &name);
725 return handler->
get(dentry, name, buffer, size, handler->
flags);
736 unsigned int size = 0;
747 size = handler->
list(dentry, buf, buffer_size,
749 if (size > buffer_size)
769 handler = xattr_resolve_name(dentry->
d_sb->s_xattr, &name);
772 return handler->
set(dentry, name, value, size, flags, handler->
flags);
784 handler = xattr_resolve_name(dentry->
d_sb->s_xattr, &name);
787 return handler->
set(dentry, name,
NULL, 0,
805 len =
sizeof(*new_xattr) +
size;
806 if (len <=
sizeof(*new_xattr))
822 void *
buffer,
size_t size)
827 spin_lock(&xattrs->
lock);
834 if (size < xattr->size)
841 spin_unlock(&xattrs->
lock);
845 static int __simple_xattr_set(
struct simple_xattrs *xattrs,
const char *name,
846 const void *value,
size_t size,
int flags)
859 if (!new_xattr->
name) {
865 spin_lock(&xattrs->
lock);
871 }
else if (new_xattr) {
872 list_replace(&xattr->
list, &new_xattr->
list);
883 list_add(&new_xattr->
list, &xattrs->
head);
887 spin_unlock(&xattrs->
lock);
911 const void *value,
size_t size,
int flags)
915 return __simple_xattr_set(xattrs, name, value, size, flags);
923 return __simple_xattr_set(xattrs, name,
NULL, 0, XATTR_REPLACE);
926 static bool xattr_is_trusted(
const char *name)
941 spin_lock(&xattrs->
lock);
946 if (!trusted && xattr_is_trusted(xattr->
name))
960 spin_unlock(&xattrs->
lock);
971 spin_lock(&xattrs->
lock);
972 list_add(&new_xattr->
list, &xattrs->
head);
973 spin_unlock(&xattrs->
lock);