Commit 96686888 authored by James Morris's avatar James Morris Committed by Linus Torvalds

[PATCH] xattr consolidation v3 - ext3

This patch converts the ext3 xattr and acl code to the generic xattr API.
Signed-off-by: default avatarJames Morris <jmorris@redhat.com>
Signed-off-by: default avatarStephen Smalley <sds@epoch.ncsc.mil>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 65199af6
...@@ -416,27 +416,27 @@ ext3_acl_chmod(struct inode *inode) ...@@ -416,27 +416,27 @@ ext3_acl_chmod(struct inode *inode)
* Extended attribute handlers * Extended attribute handlers
*/ */
static size_t static size_t
ext3_xattr_list_acl_access(char *list, struct inode *inode, ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len,
const char *name, int name_len) const char *name, size_t name_len)
{ {
const size_t size = sizeof(XATTR_NAME_ACL_ACCESS); const size_t size = sizeof(XATTR_NAME_ACL_ACCESS);
if (!test_opt(inode->i_sb, POSIX_ACL)) if (!test_opt(inode->i_sb, POSIX_ACL))
return 0; return 0;
if (list) if (list && (size <= list_len))
memcpy(list, XATTR_NAME_ACL_ACCESS, size); memcpy(list, XATTR_NAME_ACL_ACCESS, size);
return size; return size;
} }
static size_t static size_t
ext3_xattr_list_acl_default(char *list, struct inode *inode, ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len,
const char *name, int name_len) const char *name, size_t name_len)
{ {
const size_t size = sizeof(XATTR_NAME_ACL_DEFAULT); const size_t size = sizeof(XATTR_NAME_ACL_DEFAULT);
if (!test_opt(inode->i_sb, POSIX_ACL)) if (!test_opt(inode->i_sb, POSIX_ACL))
return 0; return 0;
if (list) if (list && (size <= list_len))
memcpy(list, XATTR_NAME_ACL_DEFAULT, size); memcpy(list, XATTR_NAME_ACL_DEFAULT, size);
return size; return size;
} }
...@@ -536,45 +536,16 @@ ext3_xattr_set_acl_default(struct inode *inode, const char *name, ...@@ -536,45 +536,16 @@ ext3_xattr_set_acl_default(struct inode *inode, const char *name,
return ext3_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); return ext3_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
} }
struct ext3_xattr_handler ext3_xattr_acl_access_handler = { struct xattr_handler ext3_xattr_acl_access_handler = {
.prefix = XATTR_NAME_ACL_ACCESS, .prefix = XATTR_NAME_ACL_ACCESS,
.list = ext3_xattr_list_acl_access, .list = ext3_xattr_list_acl_access,
.get = ext3_xattr_get_acl_access, .get = ext3_xattr_get_acl_access,
.set = ext3_xattr_set_acl_access, .set = ext3_xattr_set_acl_access,
}; };
struct ext3_xattr_handler ext3_xattr_acl_default_handler = { struct xattr_handler ext3_xattr_acl_default_handler = {
.prefix = XATTR_NAME_ACL_DEFAULT, .prefix = XATTR_NAME_ACL_DEFAULT,
.list = ext3_xattr_list_acl_default, .list = ext3_xattr_list_acl_default,
.get = ext3_xattr_get_acl_default, .get = ext3_xattr_get_acl_default,
.set = ext3_xattr_set_acl_default, .set = ext3_xattr_set_acl_default,
}; };
void
exit_ext3_acl(void)
{
ext3_xattr_unregister(EXT3_XATTR_INDEX_POSIX_ACL_ACCESS,
&ext3_xattr_acl_access_handler);
ext3_xattr_unregister(EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT,
&ext3_xattr_acl_default_handler);
}
int __init
init_ext3_acl(void)
{
int error;
error = ext3_xattr_register(EXT3_XATTR_INDEX_POSIX_ACL_ACCESS,
&ext3_xattr_acl_access_handler);
if (error)
goto fail;
error = ext3_xattr_register(EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT,
&ext3_xattr_acl_default_handler);
if (error)
goto fail;
return 0;
fail:
exit_ext3_acl();
return error;
}
...@@ -132,10 +132,12 @@ struct file_operations ext3_file_operations = { ...@@ -132,10 +132,12 @@ struct file_operations ext3_file_operations = {
struct inode_operations ext3_file_inode_operations = { struct inode_operations ext3_file_inode_operations = {
.truncate = ext3_truncate, .truncate = ext3_truncate,
.setattr = ext3_setattr, .setattr = ext3_setattr,
.setxattr = ext3_setxattr, #ifdef CONFIG_EXT3_FS_XATTR
.getxattr = ext3_getxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext3_listxattr,
.removexattr = ext3_removexattr, .removexattr = generic_removexattr,
#endif
.permission = ext3_permission, .permission = ext3_permission,
}; };
...@@ -2352,18 +2352,22 @@ struct inode_operations ext3_dir_inode_operations = { ...@@ -2352,18 +2352,22 @@ struct inode_operations ext3_dir_inode_operations = {
.mknod = ext3_mknod, .mknod = ext3_mknod,
.rename = ext3_rename, .rename = ext3_rename,
.setattr = ext3_setattr, .setattr = ext3_setattr,
.setxattr = ext3_setxattr, #ifdef CONFIG_EXT3_FS_XATTR
.getxattr = ext3_getxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext3_listxattr,
.removexattr = ext3_removexattr, .removexattr = generic_removexattr,
#endif
.permission = ext3_permission, .permission = ext3_permission,
}; };
struct inode_operations ext3_special_inode_operations = { struct inode_operations ext3_special_inode_operations = {
.setattr = ext3_setattr, .setattr = ext3_setattr,
.setxattr = ext3_setxattr, #ifdef CONFIG_EXT3_FS_XATTR
.getxattr = ext3_getxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext3_listxattr,
.removexattr = ext3_removexattr, .removexattr = generic_removexattr,
#endif
.permission = ext3_permission, .permission = ext3_permission,
}; };
...@@ -1474,6 +1474,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1474,6 +1474,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
*/ */
sb->s_op = &ext3_sops; sb->s_op = &ext3_sops;
sb->s_export_op = &ext3_export_ops; sb->s_export_op = &ext3_export_ops;
sb->s_xattr = ext3_xattr_handlers;
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
sb->s_qcop = &ext3_qctl_operations; sb->s_qcop = &ext3_qctl_operations;
sb->dq_op = &ext3_quota_operations; sb->dq_op = &ext3_quota_operations;
......
...@@ -34,17 +34,21 @@ struct inode_operations ext3_symlink_inode_operations = { ...@@ -34,17 +34,21 @@ struct inode_operations ext3_symlink_inode_operations = {
.readlink = generic_readlink, .readlink = generic_readlink,
.follow_link = page_follow_link_light, .follow_link = page_follow_link_light,
.put_link = page_put_link, .put_link = page_put_link,
.setxattr = ext3_setxattr, #ifdef CONFIG_EXT3_FS_XATTR
.getxattr = ext3_getxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext3_listxattr,
.removexattr = ext3_removexattr, .removexattr = generic_removexattr,
#endif
}; };
struct inode_operations ext3_fast_symlink_inode_operations = { struct inode_operations ext3_fast_symlink_inode_operations = {
.readlink = generic_readlink, .readlink = generic_readlink,
.follow_link = ext3_follow_link, .follow_link = ext3_follow_link,
.setxattr = ext3_setxattr, #ifdef CONFIG_EXT3_FS_XATTR
.getxattr = ext3_getxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext3_listxattr,
.removexattr = ext3_removexattr, .removexattr = generic_removexattr,
#endif
}; };
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
* Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>. * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
* Extended attributes for symlinks and special files added per * Extended attributes for symlinks and special files added per
* suggestion of Luka Renko <luka.renko@hermes.si>. * suggestion of Luka Renko <luka.renko@hermes.si>.
* xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>,
* Red Hat Inc.
*/ */
/* /*
...@@ -100,101 +102,40 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *, ...@@ -100,101 +102,40 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *,
struct ext3_xattr_entry *); struct ext3_xattr_entry *);
static struct mb_cache *ext3_xattr_cache; static struct mb_cache *ext3_xattr_cache;
static struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
static rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
int static struct xattr_handler *ext3_xattr_handler_map[EXT3_XATTR_INDEX_MAX] = {
ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler) [EXT3_XATTR_INDEX_USER] = &ext3_xattr_user_handler,
{ #ifdef CONFIG_EXT3_FS_POSIX_ACL
int error = -EINVAL; [EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext3_xattr_acl_access_handler,
[EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext3_xattr_acl_default_handler,
if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) { #endif
write_lock(&ext3_handler_lock); [EXT3_XATTR_INDEX_TRUSTED] = &ext3_xattr_trusted_handler,
if (!ext3_xattr_handlers[name_index-1]) { #ifdef CONFIG_EXT3_FS_SECURITY
ext3_xattr_handlers[name_index-1] = handler; [EXT3_XATTR_INDEX_SECURITY] = &ext3_xattr_security_handler,
error = 0; #endif
} };
write_unlock(&ext3_handler_lock);
}
return error;
}
void
ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
{
if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
write_lock(&ext3_handler_lock);
ext3_xattr_handlers[name_index-1] = NULL;
write_unlock(&ext3_handler_lock);
}
}
static inline const char *
strcmp_prefix(const char *a, const char *a_prefix)
{
while (*a_prefix && *a == *a_prefix) {
a++;
a_prefix++;
}
return *a_prefix ? NULL : a;
}
/*
* Decode the extended attribute name, and translate it into
* the name_index and name suffix.
*/
static inline struct ext3_xattr_handler *
ext3_xattr_resolve_name(const char **name)
{
struct ext3_xattr_handler *handler = NULL;
int i;
if (!*name) struct xattr_handler *ext3_xattr_handlers[] = {
return NULL; &ext3_xattr_user_handler,
read_lock(&ext3_handler_lock); &ext3_xattr_trusted_handler,
for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) { #ifdef CONFIG_EXT3_FS_POSIX_ACL
if (ext3_xattr_handlers[i]) { &ext3_xattr_acl_access_handler,
const char *n = strcmp_prefix(*name, &ext3_xattr_acl_default_handler,
ext3_xattr_handlers[i]->prefix); #endif
if (n) { #ifdef CONFIG_EXT3_FS_SECURITY
handler = ext3_xattr_handlers[i]; &ext3_xattr_security_handler,
*name = n; #endif
break; NULL
} };
}
}
read_unlock(&ext3_handler_lock);
return handler;
}
static inline struct ext3_xattr_handler * static inline struct xattr_handler *
ext3_xattr_handler(int name_index) ext3_xattr_handler(int name_index)
{ {
struct ext3_xattr_handler *handler = NULL; struct xattr_handler *handler = NULL;
if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
read_lock(&ext3_handler_lock);
handler = ext3_xattr_handlers[name_index-1];
read_unlock(&ext3_handler_lock);
}
return handler;
}
/* if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX)
* Inode operation getxattr() handler = ext3_xattr_handler_map[name_index];
* return handler;
* dentry->d_inode->i_sem: don't care
*/
ssize_t
ext3_getxattr(struct dentry *dentry, const char *name,
void *buffer, size_t size)
{
struct ext3_xattr_handler *handler;
struct inode *inode = dentry->d_inode;
handler = ext3_xattr_resolve_name(&name);
if (!handler)
return -EOPNOTSUPP;
return handler->get(inode, name, buffer, size);
} }
/* /*
...@@ -208,43 +149,6 @@ ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) ...@@ -208,43 +149,6 @@ ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
return ext3_xattr_list(dentry->d_inode, buffer, size); return ext3_xattr_list(dentry->d_inode, buffer, size);
} }
/*
* Inode operation setxattr()
*
* dentry->d_inode->i_sem: down
*/
int
ext3_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{
struct ext3_xattr_handler *handler;
struct inode *inode = dentry->d_inode;
if (size == 0)
value = ""; /* empty EA, do not remove */
handler = ext3_xattr_resolve_name(&name);
if (!handler)
return -EOPNOTSUPP;
return handler->set(inode, name, value, size, flags);
}
/*
* Inode operation removexattr()
*
* dentry->d_inode->i_sem: down
*/
int
ext3_removexattr(struct dentry *dentry, const char *name)
{
struct ext3_xattr_handler *handler;
struct inode *inode = dentry->d_inode;
handler = ext3_xattr_resolve_name(&name);
if (!handler)
return -EOPNOTSUPP;
return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
}
/* /*
* ext3_xattr_get() * ext3_xattr_get()
* *
...@@ -363,7 +267,7 @@ ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) ...@@ -363,7 +267,7 @@ ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
{ {
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
struct ext3_xattr_entry *entry; struct ext3_xattr_entry *entry;
size_t size = 0; size_t total_size = 0;
char *buf, *end; char *buf, *end;
int error; int error;
...@@ -390,44 +294,37 @@ bad_block: ext3_error(inode->i_sb, "ext3_xattr_list", ...@@ -390,44 +294,37 @@ bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
error = -EIO; error = -EIO;
goto cleanup; goto cleanup;
} }
/* compute the size required for the list of attribute names */
for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
entry = EXT3_XATTR_NEXT(entry)) {
struct ext3_xattr_handler *handler;
struct ext3_xattr_entry *next =
EXT3_XATTR_NEXT(entry);
if ((char *)next >= end)
goto bad_block;
handler = ext3_xattr_handler(entry->e_name_index);
if (handler)
size += handler->list(NULL, inode, entry->e_name,
entry->e_name_len);
}
if (ext3_xattr_cache_insert(bh)) if (ext3_xattr_cache_insert(bh))
ea_idebug(inode, "cache insert failed"); ea_idebug(inode, "cache insert failed");
if (!buffer) {
error = size;
goto cleanup;
} else {
error = -ERANGE;
if (size > buffer_size)
goto cleanup;
}
/* list the attribute names */ /* list the attribute names */
buf = buffer; buf = buffer;
for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry); for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
entry = EXT3_XATTR_NEXT(entry)) { entry = EXT3_XATTR_NEXT(entry)) {
struct ext3_xattr_handler *handler; struct xattr_handler *handler;
struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(entry);
if ((char *)next >= end)
goto bad_block;
handler = ext3_xattr_handler(entry->e_name_index); handler = ext3_xattr_handler(entry->e_name_index);
if (handler) if (handler) {
buf += handler->list(buf, inode, entry->e_name, size_t size = handler->list(inode, buf, buffer_size,
entry->e_name,
entry->e_name_len); entry->e_name_len);
if (buf) {
if (size > buffer_size) {
error = -ERANGE;
goto cleanup;
} }
error = size; buf += size;
buffer_size -= size;
}
total_size += size;
}
}
error = total_size;
cleanup: cleanup:
brelse(bh); brelse(bh);
...@@ -1179,51 +1076,12 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header, ...@@ -1179,51 +1076,12 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
int __init int __init
init_ext3_xattr(void) init_ext3_xattr(void)
{ {
int err;
err = ext3_xattr_register(EXT3_XATTR_INDEX_USER,
&ext3_xattr_user_handler);
if (err)
return err;
err = ext3_xattr_register(EXT3_XATTR_INDEX_TRUSTED,
&ext3_xattr_trusted_handler);
if (err)
goto out;
#ifdef CONFIG_EXT3_FS_SECURITY
err = ext3_xattr_register(EXT3_XATTR_INDEX_SECURITY,
&ext3_xattr_security_handler);
if (err)
goto out1;
#endif
#ifdef CONFIG_EXT3_FS_POSIX_ACL
err = init_ext3_acl();
if (err)
goto out2;
#endif
ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL, ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
sizeof(struct mb_cache_entry) + sizeof(struct mb_cache_entry) +
sizeof(struct mb_cache_entry_index), 1, 6); sizeof(struct mb_cache_entry_index), 1, 6);
if (!ext3_xattr_cache) { if (!ext3_xattr_cache)
err = -ENOMEM; return -ENOMEM;
goto out3;
}
return 0; return 0;
out3:
#ifdef CONFIG_EXT3_FS_POSIX_ACL
exit_ext3_acl();
out2:
#endif
#ifdef CONFIG_EXT3_FS_SECURITY
ext3_xattr_unregister(EXT3_XATTR_INDEX_SECURITY,
&ext3_xattr_security_handler);
out1:
#endif
ext3_xattr_unregister(EXT3_XATTR_INDEX_TRUSTED,
&ext3_xattr_trusted_handler);
out:
ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
&ext3_xattr_user_handler);
return err;
} }
void void
...@@ -1232,15 +1090,4 @@ exit_ext3_xattr(void) ...@@ -1232,15 +1090,4 @@ exit_ext3_xattr(void)
if (ext3_xattr_cache) if (ext3_xattr_cache)
mb_cache_destroy(ext3_xattr_cache); mb_cache_destroy(ext3_xattr_cache);
ext3_xattr_cache = NULL; ext3_xattr_cache = NULL;
#ifdef CONFIG_EXT3_FS_POSIX_ACL
exit_ext3_acl();
#endif
#ifdef CONFIG_EXT3_FS_SECURITY
ext3_xattr_unregister(EXT3_XATTR_INDEX_SECURITY,
&ext3_xattr_security_handler);
#endif
ext3_xattr_unregister(EXT3_XATTR_INDEX_TRUSTED,
&ext3_xattr_trusted_handler);
ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
&ext3_xattr_user_handler);
} }
...@@ -56,23 +56,13 @@ struct ext3_xattr_entry { ...@@ -56,23 +56,13 @@ struct ext3_xattr_entry {
# ifdef CONFIG_EXT3_FS_XATTR # ifdef CONFIG_EXT3_FS_XATTR
struct ext3_xattr_handler { extern struct xattr_handler ext3_xattr_user_handler;
char *prefix; extern struct xattr_handler ext3_xattr_trusted_handler;
size_t (*list)(char *list, struct inode *inode, const char *name, extern struct xattr_handler ext3_xattr_acl_access_handler;
int name_len); extern struct xattr_handler ext3_xattr_acl_default_handler;
int (*get)(struct inode *inode, const char *name, void *buffer, extern struct xattr_handler ext3_xattr_security_handler;
size_t size);
int (*set)(struct inode *inode, const char *name, const void *buffer,
size_t size, int flags);
};
extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
extern ssize_t ext3_listxattr(struct dentry *, char *, size_t); extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
extern int ext3_removexattr(struct dentry *, const char *);
extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t); extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
extern int ext3_xattr_list(struct inode *, char *, size_t); extern int ext3_xattr_list(struct inode *, char *, size_t);
...@@ -85,11 +75,9 @@ extern void ext3_xattr_put_super(struct super_block *); ...@@ -85,11 +75,9 @@ extern void ext3_xattr_put_super(struct super_block *);
extern int init_ext3_xattr(void); extern int init_ext3_xattr(void);
extern void exit_ext3_xattr(void); extern void exit_ext3_xattr(void);
extern struct xattr_handler *ext3_xattr_handlers[];
# else /* CONFIG_EXT3_FS_XATTR */ # else /* CONFIG_EXT3_FS_XATTR */
# define ext3_setxattr NULL
# define ext3_getxattr NULL
# define ext3_listxattr NULL
# define ext3_removexattr NULL
static inline int static inline int
ext3_xattr_get(struct inode *inode, int name_index, const char *name, ext3_xattr_get(struct inode *inode, int name_index, const char *name,
...@@ -139,8 +127,6 @@ exit_ext3_xattr(void) ...@@ -139,8 +127,6 @@ exit_ext3_xattr(void)
{ {
} }
# endif /* CONFIG_EXT3_FS_XATTR */ #define ext3_xattr_handlers NULL
extern struct ext3_xattr_handler ext3_xattr_user_handler; # endif /* CONFIG_EXT3_FS_XATTR */
extern struct ext3_xattr_handler ext3_xattr_trusted_handler;
extern struct ext3_xattr_handler ext3_xattr_security_handler;
...@@ -12,17 +12,19 @@ ...@@ -12,17 +12,19 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext3_xattr_security_list(char *list, struct inode *inode, ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size,
const char *name, int name_len) const char *name, size_t name_len)
{ {
const int prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1; const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1;
if (list) {
if (list && (total_len <= list_size)) {
memcpy(list, XATTR_SECURITY_PREFIX, prefix_len); memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len); memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0'; list[prefix_len + name_len] = '\0';
} }
return prefix_len + name_len + 1; return total_len;
} }
static int static int
...@@ -45,7 +47,7 @@ ext3_xattr_security_set(struct inode *inode, const char *name, ...@@ -45,7 +47,7 @@ ext3_xattr_security_set(struct inode *inode, const char *name,
value, size, flags); value, size, flags);
} }
struct ext3_xattr_handler ext3_xattr_security_handler = { struct xattr_handler ext3_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX, .prefix = XATTR_SECURITY_PREFIX,
.list = ext3_xattr_security_list, .list = ext3_xattr_security_list,
.get = ext3_xattr_security_get, .get = ext3_xattr_security_get,
......
...@@ -16,20 +16,21 @@ ...@@ -16,20 +16,21 @@
#define XATTR_TRUSTED_PREFIX "trusted." #define XATTR_TRUSTED_PREFIX "trusted."
static size_t static size_t
ext3_xattr_trusted_list(char *list, struct inode *inode, ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
const char *name, int name_len) const char *name, size_t name_len)
{ {
const int prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1; const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return 0; return 0;
if (list) { if (list && (total_len <= list_size)) {
memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len); memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len); memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0'; list[prefix_len + name_len] = '\0';
} }
return prefix_len + name_len + 1; return total_len;
} }
static int static int
...@@ -56,7 +57,7 @@ ext3_xattr_trusted_set(struct inode *inode, const char *name, ...@@ -56,7 +57,7 @@ ext3_xattr_trusted_set(struct inode *inode, const char *name,
value, size, flags); value, size, flags);
} }
struct ext3_xattr_handler ext3_xattr_trusted_handler = { struct xattr_handler ext3_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX, .prefix = XATTR_TRUSTED_PREFIX,
.list = ext3_xattr_trusted_list, .list = ext3_xattr_trusted_list,
.get = ext3_xattr_trusted_get, .get = ext3_xattr_trusted_get,
......
...@@ -16,20 +16,21 @@ ...@@ -16,20 +16,21 @@
#define XATTR_USER_PREFIX "user." #define XATTR_USER_PREFIX "user."
static size_t static size_t
ext3_xattr_user_list(char *list, struct inode *inode, ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size,
const char *name, int name_len) const char *name, size_t name_len)
{ {
const int prefix_len = sizeof(XATTR_USER_PREFIX)-1; const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1;
if (!test_opt(inode->i_sb, XATTR_USER)) if (!test_opt(inode->i_sb, XATTR_USER))
return 0; return 0;
if (list) { if (list && (total_len <= list_size)) {
memcpy(list, XATTR_USER_PREFIX, prefix_len); memcpy(list, XATTR_USER_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len); memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0'; list[prefix_len + name_len] = '\0';
} }
return prefix_len + name_len + 1; return total_len;
} }
static int static int
...@@ -70,7 +71,7 @@ ext3_xattr_user_set(struct inode *inode, const char *name, ...@@ -70,7 +71,7 @@ ext3_xattr_user_set(struct inode *inode, const char *name,
value, size, flags); value, size, flags);
} }
struct ext3_xattr_handler ext3_xattr_user_handler = { struct xattr_handler ext3_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX, .prefix = XATTR_USER_PREFIX,
.list = ext3_xattr_user_list, .list = ext3_xattr_user_list,
.get = ext3_xattr_user_get, .get = ext3_xattr_user_get,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment