Skip to content

Commit 2796e4c

Browse files
Christoph HellwigAl Viro
authored andcommitted
hfsplus: remove can_set_xattr
When using the per-superblock xattr handlers permission checking is done by the generic code. hfsplus just needs to check for the magic osx attribute not to leak into protected namespaces. Also given that the code was obviously copied from JFS the proper attribution was missing. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 4ac7249 commit 2796e4c

File tree

1 file changed

+3
-84
lines changed

1 file changed

+3
-84
lines changed

fs/hfsplus/xattr.c

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -52,82 +52,6 @@ static inline int is_known_namespace(const char *name)
5252
return true;
5353
}
5454

55-
static int can_set_system_xattr(struct inode *inode, const char *name,
56-
const void *value, size_t size)
57-
{
58-
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
59-
struct posix_acl *acl;
60-
int err;
61-
62-
if (!inode_owner_or_capable(inode))
63-
return -EPERM;
64-
65-
/*
66-
* POSIX_ACL_XATTR_ACCESS is tied to i_mode
67-
*/
68-
if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) {
69-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
70-
if (IS_ERR(acl))
71-
return PTR_ERR(acl);
72-
if (acl) {
73-
err = posix_acl_equiv_mode(acl, &inode->i_mode);
74-
posix_acl_release(acl);
75-
if (err < 0)
76-
return err;
77-
mark_inode_dirty(inode);
78-
}
79-
/*
80-
* We're changing the ACL. Get rid of the cached one
81-
*/
82-
forget_cached_acl(inode, ACL_TYPE_ACCESS);
83-
84-
return 0;
85-
} else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) {
86-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
87-
if (IS_ERR(acl))
88-
return PTR_ERR(acl);
89-
posix_acl_release(acl);
90-
91-
/*
92-
* We're changing the default ACL. Get rid of the cached one
93-
*/
94-
forget_cached_acl(inode, ACL_TYPE_DEFAULT);
95-
96-
return 0;
97-
}
98-
#endif /* CONFIG_HFSPLUS_FS_POSIX_ACL */
99-
return -EOPNOTSUPP;
100-
}
101-
102-
static int can_set_xattr(struct inode *inode, const char *name,
103-
const void *value, size_t value_len)
104-
{
105-
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
106-
return can_set_system_xattr(inode, name, value, value_len);
107-
108-
if (!strncmp(name, XATTR_MAC_OSX_PREFIX, XATTR_MAC_OSX_PREFIX_LEN)) {
109-
/*
110-
* This makes sure that we aren't trying to set an
111-
* attribute in a different namespace by prefixing it
112-
* with "osx."
113-
*/
114-
if (is_known_namespace(name + XATTR_MAC_OSX_PREFIX_LEN))
115-
return -EOPNOTSUPP;
116-
117-
return 0;
118-
}
119-
120-
/*
121-
* Don't allow setting an attribute in an unknown namespace.
122-
*/
123-
if (strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
124-
strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
125-
strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
126-
return -EOPNOTSUPP;
127-
128-
return 0;
129-
}
130-
13155
static void hfsplus_init_header_node(struct inode *attr_file,
13256
u32 clump_size,
13357
char *buf, u16 node_size)
@@ -350,10 +274,6 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
350274
HFSPLUS_IS_RSRC(inode))
351275
return -EOPNOTSUPP;
352276

353-
err = can_set_xattr(inode, name, value, size);
354-
if (err)
355-
return err;
356-
357277
if (strncmp(name, XATTR_MAC_OSX_PREFIX,
358278
XATTR_MAC_OSX_PREFIX_LEN) == 0)
359279
name += XATTR_MAC_OSX_PREFIX_LEN;
@@ -841,10 +761,6 @@ int hfsplus_removexattr(struct dentry *dentry, const char *name)
841761
if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
842762
return -EOPNOTSUPP;
843763

844-
err = can_set_xattr(inode, name, NULL, 0);
845-
if (err)
846-
return err;
847-
848764
if (strncmp(name, XATTR_MAC_OSX_PREFIX,
849765
XATTR_MAC_OSX_PREFIX_LEN) == 0)
850766
name += XATTR_MAC_OSX_PREFIX_LEN;
@@ -941,6 +857,9 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
941857
if (len > HFSPLUS_ATTR_MAX_STRLEN)
942858
return -EOPNOTSUPP;
943859

860+
if (is_known_namespace(name))
861+
return -EOPNOTSUPP;
862+
944863
strcpy(xattr_name, XATTR_MAC_OSX_PREFIX);
945864
strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name);
946865

0 commit comments

Comments
 (0)