diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-18 13:08:45 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-18 13:08:45 -0400 |
commit | ba5a2655c270f59dea2d9b4d764aec2f6e7f5f41 (patch) | |
tree | 72b60e6899dfd156b2e9033818f894381da9355c /fs/ubifs | |
parent | 8908c94d6cd7513ba4512295abc945a6ff7f979c (diff) | |
parent | e0d46f5c6e0ba3a79e64cd60e62b7b7191ed93f3 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull remaining vfs xattr work from Al Viro:
"The rest of work.xattr (non-cifs conversions)"
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
btrfs: Switch to generic xattr handlers
ubifs: Switch to generic xattr handlers
jfs: Switch to generic xattr handlers
jfs: Clean up xattr name mapping
gfs2: Switch to generic xattr handlers
ceph: kill __ceph_removexattr()
ceph: Switch to generic xattr handlers
ceph: Get rid of d_find_alias in ceph_set_acl
Diffstat (limited to 'fs/ubifs')
-rw-r--r-- | fs/ubifs/dir.c | 6 | ||||
-rw-r--r-- | fs/ubifs/file.c | 12 | ||||
-rw-r--r-- | fs/ubifs/super.c | 1 | ||||
-rw-r--r-- | fs/ubifs/ubifs.h | 7 | ||||
-rw-r--r-- | fs/ubifs/xattr.c | 143 |
5 files changed, 79 insertions, 90 deletions
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 34a5356d0ce7..4b86d3a738e1 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c | |||
@@ -1182,10 +1182,10 @@ const struct inode_operations ubifs_dir_inode_operations = { | |||
1182 | .rename = ubifs_rename, | 1182 | .rename = ubifs_rename, |
1183 | .setattr = ubifs_setattr, | 1183 | .setattr = ubifs_setattr, |
1184 | .getattr = ubifs_getattr, | 1184 | .getattr = ubifs_getattr, |
1185 | .setxattr = ubifs_setxattr, | 1185 | .setxattr = generic_setxattr, |
1186 | .getxattr = ubifs_getxattr, | 1186 | .getxattr = generic_getxattr, |
1187 | .listxattr = ubifs_listxattr, | 1187 | .listxattr = ubifs_listxattr, |
1188 | .removexattr = ubifs_removexattr, | 1188 | .removexattr = generic_removexattr, |
1189 | #ifdef CONFIG_UBIFS_ATIME_SUPPORT | 1189 | #ifdef CONFIG_UBIFS_ATIME_SUPPORT |
1190 | .update_time = ubifs_update_time, | 1190 | .update_time = ubifs_update_time, |
1191 | #endif | 1191 | #endif |
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 446753d8ac34..08316972ff93 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -1597,10 +1597,10 @@ const struct address_space_operations ubifs_file_address_operations = { | |||
1597 | const struct inode_operations ubifs_file_inode_operations = { | 1597 | const struct inode_operations ubifs_file_inode_operations = { |
1598 | .setattr = ubifs_setattr, | 1598 | .setattr = ubifs_setattr, |
1599 | .getattr = ubifs_getattr, | 1599 | .getattr = ubifs_getattr, |
1600 | .setxattr = ubifs_setxattr, | 1600 | .setxattr = generic_setxattr, |
1601 | .getxattr = ubifs_getxattr, | 1601 | .getxattr = generic_getxattr, |
1602 | .listxattr = ubifs_listxattr, | 1602 | .listxattr = ubifs_listxattr, |
1603 | .removexattr = ubifs_removexattr, | 1603 | .removexattr = generic_removexattr, |
1604 | #ifdef CONFIG_UBIFS_ATIME_SUPPORT | 1604 | #ifdef CONFIG_UBIFS_ATIME_SUPPORT |
1605 | .update_time = ubifs_update_time, | 1605 | .update_time = ubifs_update_time, |
1606 | #endif | 1606 | #endif |
@@ -1611,10 +1611,10 @@ const struct inode_operations ubifs_symlink_inode_operations = { | |||
1611 | .get_link = simple_get_link, | 1611 | .get_link = simple_get_link, |
1612 | .setattr = ubifs_setattr, | 1612 | .setattr = ubifs_setattr, |
1613 | .getattr = ubifs_getattr, | 1613 | .getattr = ubifs_getattr, |
1614 | .setxattr = ubifs_setxattr, | 1614 | .setxattr = generic_setxattr, |
1615 | .getxattr = ubifs_getxattr, | 1615 | .getxattr = generic_getxattr, |
1616 | .listxattr = ubifs_listxattr, | 1616 | .listxattr = ubifs_listxattr, |
1617 | .removexattr = ubifs_removexattr, | 1617 | .removexattr = generic_removexattr, |
1618 | #ifdef CONFIG_UBIFS_ATIME_SUPPORT | 1618 | #ifdef CONFIG_UBIFS_ATIME_SUPPORT |
1619 | .update_time = ubifs_update_time, | 1619 | .update_time = ubifs_update_time, |
1620 | #endif | 1620 | #endif |
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index e98c24ee25a1..70349954e78b 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -2040,6 +2040,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) | |||
2040 | if (c->max_inode_sz > MAX_LFS_FILESIZE) | 2040 | if (c->max_inode_sz > MAX_LFS_FILESIZE) |
2041 | sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE; | 2041 | sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE; |
2042 | sb->s_op = &ubifs_super_operations; | 2042 | sb->s_op = &ubifs_super_operations; |
2043 | sb->s_xattr = ubifs_xattr_handlers; | ||
2043 | 2044 | ||
2044 | mutex_lock(&c->umount_mutex); | 2045 | mutex_lock(&c->umount_mutex); |
2045 | err = mount_ubifs(c); | 2046 | err = mount_ubifs(c); |
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 12e79e60c176..ddf9f6b9eee2 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/pagemap.h> | 37 | #include <linux/pagemap.h> |
38 | #include <linux/backing-dev.h> | 38 | #include <linux/backing-dev.h> |
39 | #include <linux/security.h> | 39 | #include <linux/security.h> |
40 | #include <linux/xattr.h> | ||
40 | #include "ubifs-media.h" | 41 | #include "ubifs-media.h" |
41 | 42 | ||
42 | /* Version of this UBIFS implementation */ | 43 | /* Version of this UBIFS implementation */ |
@@ -1732,12 +1733,8 @@ int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
1732 | struct kstat *stat); | 1733 | struct kstat *stat); |
1733 | 1734 | ||
1734 | /* xattr.c */ | 1735 | /* xattr.c */ |
1735 | int ubifs_setxattr(struct dentry *dentry, const char *name, | 1736 | extern const struct xattr_handler *ubifs_xattr_handlers[]; |
1736 | const void *value, size_t size, int flags); | ||
1737 | ssize_t ubifs_getxattr(struct dentry *dentry, struct inode *host, | ||
1738 | const char *name, void *buf, size_t size); | ||
1739 | ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size); | 1737 | ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
1740 | int ubifs_removexattr(struct dentry *dentry, const char *name); | ||
1741 | int ubifs_init_security(struct inode *dentry, struct inode *inode, | 1738 | int ubifs_init_security(struct inode *dentry, struct inode *inode, |
1742 | const struct qstr *qstr); | 1739 | const struct qstr *qstr); |
1743 | 1740 | ||
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c index 413d650c9476..6c277eb6aef9 100644 --- a/fs/ubifs/xattr.c +++ b/fs/ubifs/xattr.c | |||
@@ -249,42 +249,6 @@ out_free: | |||
249 | return err; | 249 | return err; |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | ||
253 | * check_namespace - check extended attribute name-space. | ||
254 | * @nm: extended attribute name | ||
255 | * | ||
256 | * This function makes sure the extended attribute name belongs to one of the | ||
257 | * supported extended attribute name-spaces. Returns name-space index in case | ||
258 | * of success and a negative error code in case of failure. | ||
259 | */ | ||
260 | static int check_namespace(const struct qstr *nm) | ||
261 | { | ||
262 | int type; | ||
263 | |||
264 | if (nm->len > UBIFS_MAX_NLEN) | ||
265 | return -ENAMETOOLONG; | ||
266 | |||
267 | if (!strncmp(nm->name, XATTR_TRUSTED_PREFIX, | ||
268 | XATTR_TRUSTED_PREFIX_LEN)) { | ||
269 | if (nm->name[XATTR_TRUSTED_PREFIX_LEN] == '\0') | ||
270 | return -EINVAL; | ||
271 | type = TRUSTED_XATTR; | ||
272 | } else if (!strncmp(nm->name, XATTR_USER_PREFIX, | ||
273 | XATTR_USER_PREFIX_LEN)) { | ||
274 | if (nm->name[XATTR_USER_PREFIX_LEN] == '\0') | ||
275 | return -EINVAL; | ||
276 | type = USER_XATTR; | ||
277 | } else if (!strncmp(nm->name, XATTR_SECURITY_PREFIX, | ||
278 | XATTR_SECURITY_PREFIX_LEN)) { | ||
279 | if (nm->name[XATTR_SECURITY_PREFIX_LEN] == '\0') | ||
280 | return -EINVAL; | ||
281 | type = SECURITY_XATTR; | ||
282 | } else | ||
283 | return -EOPNOTSUPP; | ||
284 | |||
285 | return type; | ||
286 | } | ||
287 | |||
288 | static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum) | 252 | static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum) |
289 | { | 253 | { |
290 | struct inode *inode; | 254 | struct inode *inode; |
@@ -302,24 +266,23 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum) | |||
302 | return ERR_PTR(-EINVAL); | 266 | return ERR_PTR(-EINVAL); |
303 | } | 267 | } |
304 | 268 | ||
305 | static int setxattr(struct inode *host, const char *name, const void *value, | 269 | static int __ubifs_setxattr(struct inode *host, const char *name, |
306 | size_t size, int flags) | 270 | const void *value, size_t size, int flags) |
307 | { | 271 | { |
308 | struct inode *inode; | 272 | struct inode *inode; |
309 | struct ubifs_info *c = host->i_sb->s_fs_info; | 273 | struct ubifs_info *c = host->i_sb->s_fs_info; |
310 | struct qstr nm = QSTR_INIT(name, strlen(name)); | 274 | struct qstr nm = QSTR_INIT(name, strlen(name)); |
311 | struct ubifs_dent_node *xent; | 275 | struct ubifs_dent_node *xent; |
312 | union ubifs_key key; | 276 | union ubifs_key key; |
313 | int err, type; | 277 | int err; |
314 | 278 | ||
315 | ubifs_assert(inode_is_locked(host)); | 279 | ubifs_assert(inode_is_locked(host)); |
316 | 280 | ||
317 | if (size > UBIFS_MAX_INO_DATA) | 281 | if (size > UBIFS_MAX_INO_DATA) |
318 | return -ERANGE; | 282 | return -ERANGE; |
319 | 283 | ||
320 | type = check_namespace(&nm); | 284 | if (nm.len > UBIFS_MAX_NLEN) |
321 | if (type < 0) | 285 | return -ENAMETOOLONG; |
322 | return type; | ||
323 | 286 | ||
324 | xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); | 287 | xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); |
325 | if (!xent) | 288 | if (!xent) |
@@ -363,17 +326,8 @@ out_free: | |||
363 | return err; | 326 | return err; |
364 | } | 327 | } |
365 | 328 | ||
366 | int ubifs_setxattr(struct dentry *dentry, const char *name, | 329 | static ssize_t __ubifs_getxattr(struct inode *host, const char *name, |
367 | const void *value, size_t size, int flags) | 330 | void *buf, size_t size) |
368 | { | ||
369 | dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd", | ||
370 | name, d_inode(dentry)->i_ino, dentry, size); | ||
371 | |||
372 | return setxattr(d_inode(dentry), name, value, size, flags); | ||
373 | } | ||
374 | |||
375 | ssize_t ubifs_getxattr(struct dentry *dentry, struct inode *host, | ||
376 | const char *name, void *buf, size_t size) | ||
377 | { | 331 | { |
378 | struct inode *inode; | 332 | struct inode *inode; |
379 | struct ubifs_info *c = host->i_sb->s_fs_info; | 333 | struct ubifs_info *c = host->i_sb->s_fs_info; |
@@ -383,12 +337,8 @@ ssize_t ubifs_getxattr(struct dentry *dentry, struct inode *host, | |||
383 | union ubifs_key key; | 337 | union ubifs_key key; |
384 | int err; | 338 | int err; |
385 | 339 | ||
386 | dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name, | 340 | if (nm.len > UBIFS_MAX_NLEN) |
387 | host->i_ino, dentry, size); | 341 | return -ENAMETOOLONG; |
388 | |||
389 | err = check_namespace(&nm); | ||
390 | if (err < 0) | ||
391 | return err; | ||
392 | 342 | ||
393 | xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); | 343 | xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); |
394 | if (!xent) | 344 | if (!xent) |
@@ -460,8 +410,6 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
460 | 410 | ||
461 | lowest_xent_key(c, &key, host->i_ino); | 411 | lowest_xent_key(c, &key, host->i_ino); |
462 | while (1) { | 412 | while (1) { |
463 | int type; | ||
464 | |||
465 | xent = ubifs_tnc_next_ent(c, &key, &nm); | 413 | xent = ubifs_tnc_next_ent(c, &key, &nm); |
466 | if (IS_ERR(xent)) { | 414 | if (IS_ERR(xent)) { |
467 | err = PTR_ERR(xent); | 415 | err = PTR_ERR(xent); |
@@ -471,14 +419,10 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
471 | nm.name = xent->name; | 419 | nm.name = xent->name; |
472 | nm.len = le16_to_cpu(xent->nlen); | 420 | nm.len = le16_to_cpu(xent->nlen); |
473 | 421 | ||
474 | type = check_namespace(&nm); | ||
475 | if (unlikely(type < 0)) { | ||
476 | err = type; | ||
477 | break; | ||
478 | } | ||
479 | |||
480 | /* Show trusted namespace only for "power" users */ | 422 | /* Show trusted namespace only for "power" users */ |
481 | if (type != TRUSTED_XATTR || capable(CAP_SYS_ADMIN)) { | 423 | if (strncmp(xent->name, XATTR_TRUSTED_PREFIX, |
424 | XATTR_TRUSTED_PREFIX_LEN) || | ||
425 | capable(CAP_SYS_ADMIN)) { | ||
482 | memcpy(buffer + written, nm.name, nm.len + 1); | 426 | memcpy(buffer + written, nm.name, nm.len + 1); |
483 | written += nm.len + 1; | 427 | written += nm.len + 1; |
484 | } | 428 | } |
@@ -538,22 +482,19 @@ out_cancel: | |||
538 | return err; | 482 | return err; |
539 | } | 483 | } |
540 | 484 | ||
541 | int ubifs_removexattr(struct dentry *dentry, const char *name) | 485 | static int __ubifs_removexattr(struct inode *host, const char *name) |
542 | { | 486 | { |
543 | struct inode *inode, *host = d_inode(dentry); | 487 | struct inode *inode; |
544 | struct ubifs_info *c = host->i_sb->s_fs_info; | 488 | struct ubifs_info *c = host->i_sb->s_fs_info; |
545 | struct qstr nm = QSTR_INIT(name, strlen(name)); | 489 | struct qstr nm = QSTR_INIT(name, strlen(name)); |
546 | struct ubifs_dent_node *xent; | 490 | struct ubifs_dent_node *xent; |
547 | union ubifs_key key; | 491 | union ubifs_key key; |
548 | int err; | 492 | int err; |
549 | 493 | ||
550 | dbg_gen("xattr '%s', ino %lu ('%pd')", name, | ||
551 | host->i_ino, dentry); | ||
552 | ubifs_assert(inode_is_locked(host)); | 494 | ubifs_assert(inode_is_locked(host)); |
553 | 495 | ||
554 | err = check_namespace(&nm); | 496 | if (nm.len > UBIFS_MAX_NLEN) |
555 | if (err < 0) | 497 | return -ENAMETOOLONG; |
556 | return err; | ||
557 | 498 | ||
558 | xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); | 499 | xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS); |
559 | if (!xent) | 500 | if (!xent) |
@@ -603,7 +544,7 @@ static int init_xattrs(struct inode *inode, const struct xattr *xattr_array, | |||
603 | } | 544 | } |
604 | strcpy(name, XATTR_SECURITY_PREFIX); | 545 | strcpy(name, XATTR_SECURITY_PREFIX); |
605 | strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name); | 546 | strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name); |
606 | err = setxattr(inode, name, xattr->value, xattr->value_len, 0); | 547 | err = __ubifs_setxattr(inode, name, xattr->value, xattr->value_len, 0); |
607 | kfree(name); | 548 | kfree(name); |
608 | if (err < 0) | 549 | if (err < 0) |
609 | break; | 550 | break; |
@@ -626,3 +567,53 @@ int ubifs_init_security(struct inode *dentry, struct inode *inode, | |||
626 | } | 567 | } |
627 | return err; | 568 | return err; |
628 | } | 569 | } |
570 | |||
571 | static int ubifs_xattr_get(const struct xattr_handler *handler, | ||
572 | struct dentry *dentry, struct inode *inode, | ||
573 | const char *name, void *buffer, size_t size) | ||
574 | { | ||
575 | dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name, | ||
576 | inode->i_ino, dentry, size); | ||
577 | |||
578 | return __ubifs_getxattr(inode, name, buffer, size); | ||
579 | } | ||
580 | |||
581 | static int ubifs_xattr_set(const struct xattr_handler *handler, | ||
582 | struct dentry *dentry, const char *name, | ||
583 | const void *value, size_t size, int flags) | ||
584 | { | ||
585 | struct inode *inode = d_inode(dentry); | ||
586 | |||
587 | dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd", | ||
588 | name, inode->i_ino, dentry, size); | ||
589 | |||
590 | if (value) | ||
591 | return __ubifs_setxattr(inode, name, value, size, flags); | ||
592 | else | ||
593 | return __ubifs_removexattr(inode, name); | ||
594 | } | ||
595 | |||
596 | const struct xattr_handler ubifs_user_xattr_handler = { | ||
597 | .prefix = XATTR_USER_PREFIX, | ||
598 | .get = ubifs_xattr_get, | ||
599 | .set = ubifs_xattr_set, | ||
600 | }; | ||
601 | |||
602 | const struct xattr_handler ubifs_trusted_xattr_handler = { | ||
603 | .prefix = XATTR_TRUSTED_PREFIX, | ||
604 | .get = ubifs_xattr_get, | ||
605 | .set = ubifs_xattr_set, | ||
606 | }; | ||
607 | |||
608 | const struct xattr_handler ubifs_security_xattr_handler = { | ||
609 | .prefix = XATTR_SECURITY_PREFIX, | ||
610 | .get = ubifs_xattr_get, | ||
611 | .set = ubifs_xattr_set, | ||
612 | }; | ||
613 | |||
614 | const struct xattr_handler *ubifs_xattr_handlers[] = { | ||
615 | &ubifs_user_xattr_handler, | ||
616 | &ubifs_trusted_xattr_handler, | ||
617 | &ubifs_security_xattr_handler, | ||
618 | NULL | ||
619 | }; | ||