diff options
Diffstat (limited to 'fs/hfsplus')
-rw-r--r-- | fs/hfsplus/attributes.c | 11 | ||||
-rw-r--r-- | fs/hfsplus/xattr.c | 36 | ||||
-rw-r--r-- | fs/hfsplus/xattr_security.c | 49 | ||||
-rw-r--r-- | fs/hfsplus/xattr_trusted.c | 32 | ||||
-rw-r--r-- | fs/hfsplus/xattr_user.c | 32 |
5 files changed, 94 insertions, 66 deletions
diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c index caf89a7be0a1..f3345c0b1c62 100644 --- a/fs/hfsplus/attributes.c +++ b/fs/hfsplus/attributes.c | |||
@@ -54,14 +54,11 @@ int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key, | |||
54 | memset(key, 0, sizeof(struct hfsplus_attr_key)); | 54 | memset(key, 0, sizeof(struct hfsplus_attr_key)); |
55 | key->attr.cnid = cpu_to_be32(cnid); | 55 | key->attr.cnid = cpu_to_be32(cnid); |
56 | if (name) { | 56 | if (name) { |
57 | len = strlen(name); | 57 | int res = hfsplus_asc2uni(sb, |
58 | if (len > HFSPLUS_ATTR_MAX_STRLEN) { | ||
59 | pr_err("invalid xattr name's length\n"); | ||
60 | return -EINVAL; | ||
61 | } | ||
62 | hfsplus_asc2uni(sb, | ||
63 | (struct hfsplus_unistr *)&key->attr.key_name, | 58 | (struct hfsplus_unistr *)&key->attr.key_name, |
64 | HFSPLUS_ATTR_MAX_STRLEN, name, len); | 59 | HFSPLUS_ATTR_MAX_STRLEN, name, strlen(name)); |
60 | if (res) | ||
61 | return res; | ||
65 | len = be16_to_cpu(key->attr.key_name.length); | 62 | len = be16_to_cpu(key->attr.key_name.length); |
66 | } else { | 63 | } else { |
67 | key->attr.key_name.length = 0; | 64 | key->attr.key_name.length = 0; |
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c index e2b3c9ea1c71..c03c94611cce 100644 --- a/fs/hfsplus/xattr.c +++ b/fs/hfsplus/xattr.c | |||
@@ -806,47 +806,55 @@ end_removexattr: | |||
806 | static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, | 806 | static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, |
807 | void *buffer, size_t size, int type) | 807 | void *buffer, size_t size, int type) |
808 | { | 808 | { |
809 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + | 809 | char *xattr_name; |
810 | XATTR_MAC_OSX_PREFIX_LEN + 1] = {0}; | 810 | int res; |
811 | size_t len = strlen(name); | ||
812 | 811 | ||
813 | if (!strcmp(name, "")) | 812 | if (!strcmp(name, "")) |
814 | return -EINVAL; | 813 | return -EINVAL; |
815 | 814 | ||
816 | if (len > HFSPLUS_ATTR_MAX_STRLEN) | ||
817 | return -EOPNOTSUPP; | ||
818 | |||
819 | /* | 815 | /* |
820 | * Don't allow retrieving properly prefixed attributes | 816 | * Don't allow retrieving properly prefixed attributes |
821 | * by prepending them with "osx." | 817 | * by prepending them with "osx." |
822 | */ | 818 | */ |
823 | if (is_known_namespace(name)) | 819 | if (is_known_namespace(name)) |
824 | return -EOPNOTSUPP; | 820 | return -EOPNOTSUPP; |
821 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN | ||
822 | + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); | ||
823 | if (!xattr_name) | ||
824 | return -ENOMEM; | ||
825 | strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); | ||
826 | strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); | ||
825 | 827 | ||
826 | return hfsplus_getxattr(dentry, xattr_name, buffer, size); | 828 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); |
829 | kfree(xattr_name); | ||
830 | return res; | ||
827 | } | 831 | } |
828 | 832 | ||
829 | static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, | 833 | static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, |
830 | const void *buffer, size_t size, int flags, int type) | 834 | const void *buffer, size_t size, int flags, int type) |
831 | { | 835 | { |
832 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + | 836 | char *xattr_name; |
833 | XATTR_MAC_OSX_PREFIX_LEN + 1] = {0}; | 837 | int res; |
834 | size_t len = strlen(name); | ||
835 | 838 | ||
836 | if (!strcmp(name, "")) | 839 | if (!strcmp(name, "")) |
837 | return -EINVAL; | 840 | return -EINVAL; |
838 | 841 | ||
839 | if (len > HFSPLUS_ATTR_MAX_STRLEN) | ||
840 | return -EOPNOTSUPP; | ||
841 | |||
842 | /* | 842 | /* |
843 | * Don't allow setting properly prefixed attributes | 843 | * Don't allow setting properly prefixed attributes |
844 | * by prepending them with "osx." | 844 | * by prepending them with "osx." |
845 | */ | 845 | */ |
846 | if (is_known_namespace(name)) | 846 | if (is_known_namespace(name)) |
847 | return -EOPNOTSUPP; | 847 | return -EOPNOTSUPP; |
848 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN | ||
849 | + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); | ||
850 | if (!xattr_name) | ||
851 | return -ENOMEM; | ||
852 | strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); | ||
853 | strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); | ||
848 | 854 | ||
849 | return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); | 855 | res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); |
856 | kfree(xattr_name); | ||
857 | return res; | ||
850 | } | 858 | } |
851 | 859 | ||
852 | static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list, | 860 | static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list, |
diff --git a/fs/hfsplus/xattr_security.c b/fs/hfsplus/xattr_security.c index 00722765ea79..6ec5e107691f 100644 --- a/fs/hfsplus/xattr_security.c +++ b/fs/hfsplus/xattr_security.c | |||
@@ -7,6 +7,8 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/security.h> | 9 | #include <linux/security.h> |
10 | #include <linux/nls.h> | ||
11 | |||
10 | #include "hfsplus_fs.h" | 12 | #include "hfsplus_fs.h" |
11 | #include "xattr.h" | 13 | #include "xattr.h" |
12 | #include "acl.h" | 14 | #include "acl.h" |
@@ -14,37 +16,43 @@ | |||
14 | static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, | 16 | static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, |
15 | void *buffer, size_t size, int type) | 17 | void *buffer, size_t size, int type) |
16 | { | 18 | { |
17 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 19 | char *xattr_name; |
18 | size_t len = strlen(name); | 20 | int res; |
19 | 21 | ||
20 | if (!strcmp(name, "")) | 22 | if (!strcmp(name, "")) |
21 | return -EINVAL; | 23 | return -EINVAL; |
22 | 24 | ||
23 | if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | 25 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
24 | return -EOPNOTSUPP; | 26 | GFP_KERNEL); |
25 | 27 | if (!xattr_name) | |
28 | return -ENOMEM; | ||
26 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); | 29 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); |
27 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); | 30 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); |
28 | 31 | ||
29 | return hfsplus_getxattr(dentry, xattr_name, buffer, size); | 32 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); |
33 | kfree(xattr_name); | ||
34 | return res; | ||
30 | } | 35 | } |
31 | 36 | ||
32 | static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, | 37 | static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, |
33 | const void *buffer, size_t size, int flags, int type) | 38 | const void *buffer, size_t size, int flags, int type) |
34 | { | 39 | { |
35 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 40 | char *xattr_name; |
36 | size_t len = strlen(name); | 41 | int res; |
37 | 42 | ||
38 | if (!strcmp(name, "")) | 43 | if (!strcmp(name, "")) |
39 | return -EINVAL; | 44 | return -EINVAL; |
40 | 45 | ||
41 | if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | 46 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
42 | return -EOPNOTSUPP; | 47 | GFP_KERNEL); |
43 | 48 | if (!xattr_name) | |
49 | return -ENOMEM; | ||
44 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); | 50 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); |
45 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); | 51 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); |
46 | 52 | ||
47 | return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); | 53 | res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); |
54 | kfree(xattr_name); | ||
55 | return res; | ||
48 | } | 56 | } |
49 | 57 | ||
50 | static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list, | 58 | static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list, |
@@ -62,31 +70,30 @@ static int hfsplus_initxattrs(struct inode *inode, | |||
62 | void *fs_info) | 70 | void *fs_info) |
63 | { | 71 | { |
64 | const struct xattr *xattr; | 72 | const struct xattr *xattr; |
65 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 73 | char *xattr_name; |
66 | size_t xattr_name_len; | ||
67 | int err = 0; | 74 | int err = 0; |
68 | 75 | ||
76 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, | ||
77 | GFP_KERNEL); | ||
78 | if (!xattr_name) | ||
79 | return -ENOMEM; | ||
69 | for (xattr = xattr_array; xattr->name != NULL; xattr++) { | 80 | for (xattr = xattr_array; xattr->name != NULL; xattr++) { |
70 | xattr_name_len = strlen(xattr->name); | ||
71 | 81 | ||
72 | if (xattr_name_len == 0) | 82 | if (!strcmp(xattr->name, "")) |
73 | continue; | 83 | continue; |
74 | 84 | ||
75 | if (xattr_name_len + XATTR_SECURITY_PREFIX_LEN > | ||
76 | HFSPLUS_ATTR_MAX_STRLEN) | ||
77 | return -EOPNOTSUPP; | ||
78 | |||
79 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); | 85 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); |
80 | strcpy(xattr_name + | 86 | strcpy(xattr_name + |
81 | XATTR_SECURITY_PREFIX_LEN, xattr->name); | 87 | XATTR_SECURITY_PREFIX_LEN, xattr->name); |
82 | memset(xattr_name + | 88 | memset(xattr_name + |
83 | XATTR_SECURITY_PREFIX_LEN + xattr_name_len, 0, 1); | 89 | XATTR_SECURITY_PREFIX_LEN + strlen(xattr->name), 0, 1); |
84 | 90 | ||
85 | err = __hfsplus_setxattr(inode, xattr_name, | 91 | err = __hfsplus_setxattr(inode, xattr_name, |
86 | xattr->value, xattr->value_len, 0); | 92 | xattr->value, xattr->value_len, 0); |
87 | if (err) | 93 | if (err) |
88 | break; | 94 | break; |
89 | } | 95 | } |
96 | kfree(xattr_name); | ||
90 | return err; | 97 | return err; |
91 | } | 98 | } |
92 | 99 | ||
diff --git a/fs/hfsplus/xattr_trusted.c b/fs/hfsplus/xattr_trusted.c index 426cee277542..3c5f27e4746a 100644 --- a/fs/hfsplus/xattr_trusted.c +++ b/fs/hfsplus/xattr_trusted.c | |||
@@ -6,43 +6,51 @@ | |||
6 | * Handler for trusted extended attributes. | 6 | * Handler for trusted extended attributes. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/nls.h> | ||
10 | |||
9 | #include "hfsplus_fs.h" | 11 | #include "hfsplus_fs.h" |
10 | #include "xattr.h" | 12 | #include "xattr.h" |
11 | 13 | ||
12 | static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, | 14 | static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, |
13 | void *buffer, size_t size, int type) | 15 | void *buffer, size_t size, int type) |
14 | { | 16 | { |
15 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 17 | char *xattr_name; |
16 | size_t len = strlen(name); | 18 | int res; |
17 | 19 | ||
18 | if (!strcmp(name, "")) | 20 | if (!strcmp(name, "")) |
19 | return -EINVAL; | 21 | return -EINVAL; |
20 | 22 | ||
21 | if (len + XATTR_TRUSTED_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | 23 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
22 | return -EOPNOTSUPP; | 24 | GFP_KERNEL); |
23 | 25 | if (!xattr_name) | |
26 | return -ENOMEM; | ||
24 | strcpy(xattr_name, XATTR_TRUSTED_PREFIX); | 27 | strcpy(xattr_name, XATTR_TRUSTED_PREFIX); |
25 | strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); | 28 | strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); |
26 | 29 | ||
27 | return hfsplus_getxattr(dentry, xattr_name, buffer, size); | 30 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); |
31 | kfree(xattr_name); | ||
32 | return res; | ||
28 | } | 33 | } |
29 | 34 | ||
30 | static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, | 35 | static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, |
31 | const void *buffer, size_t size, int flags, int type) | 36 | const void *buffer, size_t size, int flags, int type) |
32 | { | 37 | { |
33 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 38 | char *xattr_name; |
34 | size_t len = strlen(name); | 39 | int res; |
35 | 40 | ||
36 | if (!strcmp(name, "")) | 41 | if (!strcmp(name, "")) |
37 | return -EINVAL; | 42 | return -EINVAL; |
38 | 43 | ||
39 | if (len + XATTR_TRUSTED_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | 44 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
40 | return -EOPNOTSUPP; | 45 | GFP_KERNEL); |
41 | 46 | if (!xattr_name) | |
47 | return -ENOMEM; | ||
42 | strcpy(xattr_name, XATTR_TRUSTED_PREFIX); | 48 | strcpy(xattr_name, XATTR_TRUSTED_PREFIX); |
43 | strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); | 49 | strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); |
44 | 50 | ||
45 | return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); | 51 | res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); |
52 | kfree(xattr_name); | ||
53 | return res; | ||
46 | } | 54 | } |
47 | 55 | ||
48 | static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list, | 56 | static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list, |
diff --git a/fs/hfsplus/xattr_user.c b/fs/hfsplus/xattr_user.c index e34016561ae0..2b625a538b64 100644 --- a/fs/hfsplus/xattr_user.c +++ b/fs/hfsplus/xattr_user.c | |||
@@ -6,43 +6,51 @@ | |||
6 | * Handler for user extended attributes. | 6 | * Handler for user extended attributes. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/nls.h> | ||
10 | |||
9 | #include "hfsplus_fs.h" | 11 | #include "hfsplus_fs.h" |
10 | #include "xattr.h" | 12 | #include "xattr.h" |
11 | 13 | ||
12 | static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, | 14 | static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, |
13 | void *buffer, size_t size, int type) | 15 | void *buffer, size_t size, int type) |
14 | { | 16 | { |
15 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 17 | char *xattr_name; |
16 | size_t len = strlen(name); | 18 | int res; |
17 | 19 | ||
18 | if (!strcmp(name, "")) | 20 | if (!strcmp(name, "")) |
19 | return -EINVAL; | 21 | return -EINVAL; |
20 | 22 | ||
21 | if (len + XATTR_USER_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | 23 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
22 | return -EOPNOTSUPP; | 24 | GFP_KERNEL); |
23 | 25 | if (!xattr_name) | |
26 | return -ENOMEM; | ||
24 | strcpy(xattr_name, XATTR_USER_PREFIX); | 27 | strcpy(xattr_name, XATTR_USER_PREFIX); |
25 | strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); | 28 | strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); |
26 | 29 | ||
27 | return hfsplus_getxattr(dentry, xattr_name, buffer, size); | 30 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); |
31 | kfree(xattr_name); | ||
32 | return res; | ||
28 | } | 33 | } |
29 | 34 | ||
30 | static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, | 35 | static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, |
31 | const void *buffer, size_t size, int flags, int type) | 36 | const void *buffer, size_t size, int flags, int type) |
32 | { | 37 | { |
33 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | 38 | char *xattr_name; |
34 | size_t len = strlen(name); | 39 | int res; |
35 | 40 | ||
36 | if (!strcmp(name, "")) | 41 | if (!strcmp(name, "")) |
37 | return -EINVAL; | 42 | return -EINVAL; |
38 | 43 | ||
39 | if (len + XATTR_USER_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | 44 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
40 | return -EOPNOTSUPP; | 45 | GFP_KERNEL); |
41 | 46 | if (!xattr_name) | |
47 | return -ENOMEM; | ||
42 | strcpy(xattr_name, XATTR_USER_PREFIX); | 48 | strcpy(xattr_name, XATTR_USER_PREFIX); |
43 | strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); | 49 | strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); |
44 | 50 | ||
45 | return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); | 51 | res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); |
52 | kfree(xattr_name); | ||
53 | return res; | ||
46 | } | 54 | } |
47 | 55 | ||
48 | static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list, | 56 | static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list, |