summaryrefslogtreecommitdiffstats
path: root/fs/ext2
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-01-11 16:32:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-11 16:32:10 -0500
commitddf1d6238dd13a3bd948e8fcb1109798ef0af49b (patch)
treedaa25447e4b791b2868a0338f872975ec480862b /fs/ext2
parent32fb378437a1d716e72a442237d7ead1f435ecf0 (diff)
parent764a5c6b1fa4306dd7573c1d80914254909cd036 (diff)
Merge branch 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs xattr updates from Al Viro: "Andreas' xattr cleanup series. It's a followup to his xattr work that went in last cycle; -0.5KLoC" * 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: xattr handlers: Simplify list operation ocfs2: Replace list xattr handler operations nfs: Move call to security_inode_listsecurity into nfs_listxattr xfs: Change how listxattr generates synthetic attributes tmpfs: listxattr should include POSIX ACL xattrs tmpfs: Use xattr handler infrastructure btrfs: Use xattr handler infrastructure vfs: Distinguish between full xattr names and proper prefixes posix acls: Remove duplicate xattr name definitions gfs2: Remove gfs2_xattr_acl_chmod vfs: Remove vfs_xattr_cmp
Diffstat (limited to 'fs/ext2')
-rw-r--r--fs/ext2/xattr.c15
-rw-r--r--fs/ext2/xattr_security.c21
-rw-r--r--fs/ext2/xattr_trusted.c23
-rw-r--r--fs/ext2/xattr_user.c23
4 files changed, 16 insertions, 66 deletions
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index fa70848afa8f..cd95d14f9cc2 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -292,16 +292,21 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
292 const struct xattr_handler *handler = 292 const struct xattr_handler *handler =
293 ext2_xattr_handler(entry->e_name_index); 293 ext2_xattr_handler(entry->e_name_index);
294 294
295 if (handler) { 295 if (handler && (!handler->list || handler->list(dentry))) {
296 size_t size = handler->list(handler, dentry, buffer, 296 const char *prefix = handler->prefix ?: handler->name;
297 rest, entry->e_name, 297 size_t prefix_len = strlen(prefix);
298 entry->e_name_len); 298 size_t size = prefix_len + entry->e_name_len + 1;
299
299 if (buffer) { 300 if (buffer) {
300 if (size > rest) { 301 if (size > rest) {
301 error = -ERANGE; 302 error = -ERANGE;
302 goto cleanup; 303 goto cleanup;
303 } 304 }
304 buffer += size; 305 memcpy(buffer, prefix, prefix_len);
306 buffer += prefix_len;
307 memcpy(buffer, entry->e_name, entry->e_name_len);
308 buffer += entry->e_name_len;
309 *buffer++ = 0;
305 } 310 }
306 rest -= size; 311 rest -= size;
307 } 312 }
diff --git a/fs/ext2/xattr_security.c b/fs/ext2/xattr_security.c
index dfb08750370d..ba97f243b050 100644
--- a/fs/ext2/xattr_security.c
+++ b/fs/ext2/xattr_security.c
@@ -7,29 +7,11 @@
7#include <linux/security.h> 7#include <linux/security.h>
8#include "xattr.h" 8#include "xattr.h"
9 9
10static size_t
11ext2_xattr_security_list(const struct xattr_handler *handler,
12 struct dentry *dentry, char *list, size_t list_size,
13 const char *name, size_t name_len)
14{
15 const int prefix_len = XATTR_SECURITY_PREFIX_LEN;
16 const size_t total_len = prefix_len + name_len + 1;
17
18 if (list && total_len <= list_size) {
19 memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
20 memcpy(list+prefix_len, name, name_len);
21 list[prefix_len + name_len] = '\0';
22 }
23 return total_len;
24}
25
26static int 10static int
27ext2_xattr_security_get(const struct xattr_handler *handler, 11ext2_xattr_security_get(const struct xattr_handler *handler,
28 struct dentry *dentry, const char *name, 12 struct dentry *dentry, const char *name,
29 void *buffer, size_t size) 13 void *buffer, size_t size)
30{ 14{
31 if (strcmp(name, "") == 0)
32 return -EINVAL;
33 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name, 15 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name,
34 buffer, size); 16 buffer, size);
35} 17}
@@ -39,8 +21,6 @@ ext2_xattr_security_set(const struct xattr_handler *handler,
39 struct dentry *dentry, const char *name, 21 struct dentry *dentry, const char *name,
40 const void *value, size_t size, int flags) 22 const void *value, size_t size, int flags)
41{ 23{
42 if (strcmp(name, "") == 0)
43 return -EINVAL;
44 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name, 24 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name,
45 value, size, flags); 25 value, size, flags);
46} 26}
@@ -71,7 +51,6 @@ ext2_init_security(struct inode *inode, struct inode *dir,
71 51
72const struct xattr_handler ext2_xattr_security_handler = { 52const struct xattr_handler ext2_xattr_security_handler = {
73 .prefix = XATTR_SECURITY_PREFIX, 53 .prefix = XATTR_SECURITY_PREFIX,
74 .list = ext2_xattr_security_list,
75 .get = ext2_xattr_security_get, 54 .get = ext2_xattr_security_get,
76 .set = ext2_xattr_security_set, 55 .set = ext2_xattr_security_set,
77}; 56};
diff --git a/fs/ext2/xattr_trusted.c b/fs/ext2/xattr_trusted.c
index 3150dd3a7859..2c94d1930626 100644
--- a/fs/ext2/xattr_trusted.c
+++ b/fs/ext2/xattr_trusted.c
@@ -8,23 +8,10 @@
8#include "ext2.h" 8#include "ext2.h"
9#include "xattr.h" 9#include "xattr.h"
10 10
11static size_t 11static bool
12ext2_xattr_trusted_list(const struct xattr_handler *handler, 12ext2_xattr_trusted_list(struct dentry *dentry)
13 struct dentry *dentry, char *list, size_t list_size,
14 const char *name, size_t name_len)
15{ 13{
16 const int prefix_len = XATTR_TRUSTED_PREFIX_LEN; 14 return capable(CAP_SYS_ADMIN);
17 const size_t total_len = prefix_len + name_len + 1;
18
19 if (!capable(CAP_SYS_ADMIN))
20 return 0;
21
22 if (list && total_len <= list_size) {
23 memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
24 memcpy(list+prefix_len, name, name_len);
25 list[prefix_len + name_len] = '\0';
26 }
27 return total_len;
28} 15}
29 16
30static int 17static int
@@ -32,8 +19,6 @@ ext2_xattr_trusted_get(const struct xattr_handler *handler,
32 struct dentry *dentry, const char *name, 19 struct dentry *dentry, const char *name,
33 void *buffer, size_t size) 20 void *buffer, size_t size)
34{ 21{
35 if (strcmp(name, "") == 0)
36 return -EINVAL;
37 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name, 22 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
38 buffer, size); 23 buffer, size);
39} 24}
@@ -43,8 +28,6 @@ ext2_xattr_trusted_set(const struct xattr_handler *handler,
43 struct dentry *dentry, const char *name, 28 struct dentry *dentry, const char *name,
44 const void *value, size_t size, int flags) 29 const void *value, size_t size, int flags)
45{ 30{
46 if (strcmp(name, "") == 0)
47 return -EINVAL;
48 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name, 31 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
49 value, size, flags); 32 value, size, flags);
50} 33}
diff --git a/fs/ext2/xattr_user.c b/fs/ext2/xattr_user.c
index 339a49bbb8ef..72a2a96d677f 100644
--- a/fs/ext2/xattr_user.c
+++ b/fs/ext2/xattr_user.c
@@ -10,23 +10,10 @@
10#include "ext2.h" 10#include "ext2.h"
11#include "xattr.h" 11#include "xattr.h"
12 12
13static size_t 13static bool
14ext2_xattr_user_list(const struct xattr_handler *handler, 14ext2_xattr_user_list(struct dentry *dentry)
15 struct dentry *dentry, char *list, size_t list_size,
16 const char *name, size_t name_len)
17{ 15{
18 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 16 return test_opt(dentry->d_sb, XATTR_USER);
19 const size_t total_len = prefix_len + name_len + 1;
20
21 if (!test_opt(dentry->d_sb, XATTR_USER))
22 return 0;
23
24 if (list && total_len <= list_size) {
25 memcpy(list, XATTR_USER_PREFIX, prefix_len);
26 memcpy(list+prefix_len, name, name_len);
27 list[prefix_len + name_len] = '\0';
28 }
29 return total_len;
30} 17}
31 18
32static int 19static int
@@ -34,8 +21,6 @@ ext2_xattr_user_get(const struct xattr_handler *handler,
34 struct dentry *dentry, const char *name, 21 struct dentry *dentry, const char *name,
35 void *buffer, size_t size) 22 void *buffer, size_t size)
36{ 23{
37 if (strcmp(name, "") == 0)
38 return -EINVAL;
39 if (!test_opt(dentry->d_sb, XATTR_USER)) 24 if (!test_opt(dentry->d_sb, XATTR_USER))
40 return -EOPNOTSUPP; 25 return -EOPNOTSUPP;
41 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_USER, 26 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_USER,
@@ -47,8 +32,6 @@ ext2_xattr_user_set(const struct xattr_handler *handler,
47 struct dentry *dentry, const char *name, 32 struct dentry *dentry, const char *name,
48 const void *value, size_t size, int flags) 33 const void *value, size_t size, int flags)
49{ 34{
50 if (strcmp(name, "") == 0)
51 return -EINVAL;
52 if (!test_opt(dentry->d_sb, XATTR_USER)) 35 if (!test_opt(dentry->d_sb, XATTR_USER))
53 return -EOPNOTSUPP; 36 return -EOPNOTSUPP;
54 37