History

gfs2: Add trusted xattr support

Add support for an additional filesystem version (sb_fs_format = 1802). When a filesystem with the new version is mounted, the filesystem supports "trusted.*" xattrs. In addition, version 1802 filesystems implement a form of forward compatibility for xattrs: when xattrs with an unknown prefix (ea_type) are found on a version 1802 filesystem, those attributes are not shown by listxattr, and they are not accessible by getxattr, setxattr, or removexattr. This mechanism might turn out to be what we need in the future, but if not, we can always bump the filesystem version and break compatibility instead.

Andreas Gruenbacher committed 5 years ago

Commit 866eef41 parent 47b7ec14 files · +63 −8Browse files

Unified · Split

4 files
  1. fs/gfs2/ops_fstype.c +13 −1
  2. fs/gfs2/super.h +3 −1
  3. fs/gfs2/xattr.c +44 −4
  4. include/uapi/linux/gfs2_ondisk.h +3 −2
fs/gfs2/ops_fstype.c+13−1
@@ -489,6 +489,19 @@ static int init_sb(struct gfs2_sbd *sdp, int silent) · 488 unmodified lines
489 goto out;489 goto out;
490 }490 }
491 491
492 switch(sdp->sd_sb.sb_fs_format) {
493 case GFS2_FS_FORMAT_MAX:
494 sb->s_xattr = gfs2_xattr_handlers_max;
495 break;
496
497 case GFS2_FS_FORMAT_MIN:
498 sb->s_xattr = gfs2_xattr_handlers_min;
499 break;
500
501 default:
502 BUG();
503 }
504
492 /* Set up the buffer cache and SB for real */505 /* Set up the buffer cache and SB for real */
493 if (sdp->sd_sb.sb_bsize < bdev_logical_block_size(sb->s_bdev)) {506 if (sdp->sd_sb.sb_bsize < bdev_logical_block_size(sb->s_bdev)) {
494 ret = -EINVAL;507 ret = -EINVAL;
@@ -1110,7 +1123,6 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc) · 615 unmodified lines
1110 sb->s_op = &gfs2_super_ops;1123 sb->s_op = &gfs2_super_ops;
1111 sb->s_d_op = &gfs2_dops;1124 sb->s_d_op = &gfs2_dops;
1112 sb->s_export_op = &gfs2_export_ops;1125 sb->s_export_op = &gfs2_export_ops;
1113 sb->s_xattr = gfs2_xattr_handlers;
1114 sb->s_qcop = &gfs2_quotactl_ops;1126 sb->s_qcop = &gfs2_quotactl_ops;
1115 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;1127 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
1116 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;1128 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
fs/gfs2/super.h+3−1
@@ -58,7 +58,9 @@ extern struct file_system_type gfs2meta_fs_type; · 57 unmodified lines
58extern const struct export_operations gfs2_export_ops;58extern const struct export_operations gfs2_export_ops;
59extern const struct super_operations gfs2_super_ops;59extern const struct super_operations gfs2_super_ops;
60extern const struct dentry_operations gfs2_dops;60extern const struct dentry_operations gfs2_dops;
61extern const struct xattr_handler *gfs2_xattr_handlers[];61
62extern const struct xattr_handler *gfs2_xattr_handlers_max[];
63extern const struct xattr_handler **gfs2_xattr_handlers_min;
62 64
63#endif /* __SUPER_DOT_H__ */65#endif /* __SUPER_DOT_H__ */
64 66
fs/gfs2/xattr.c+44−4
@@ -70,6 +70,20 @@ static int ea_check_size(struct gfs2_sbd *sdp, unsigned int nsize, size_t dsize) · 69 unmodified lines
70 return 0;70 return 0;
71}71}
72 72
73static bool gfs2_eatype_valid(struct gfs2_sbd *sdp, u8 type)
74{
75 switch(sdp->sd_sb.sb_fs_format) {
76 case GFS2_FS_FORMAT_MAX:
77 return true;
78
79 case GFS2_FS_FORMAT_MIN:
80 return type <= GFS2_EATYPE_SECURITY;
81
82 default:
83 return false;
84 }
85}
86
73typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh,87typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh,
74 struct gfs2_ea_header *ea,88 struct gfs2_ea_header *ea,
75 struct gfs2_ea_header *prev, void *private);89 struct gfs2_ea_header *prev, void *private);
@@ -77,6 +91,7 @@ typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh, · 1 unmodified line
77static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,91static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
78 ea_call_t ea_call, void *data)92 ea_call_t ea_call, void *data)
79{93{
94 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
80 struct gfs2_ea_header *ea, *prev = NULL;95 struct gfs2_ea_header *ea, *prev = NULL;
81 int error = 0;96 int error = 0;
82 97
@@ -89,9 +104,8 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, · 6 unmodified lines
89 if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <=104 if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <=
90 bh->b_data + bh->b_size))105 bh->b_data + bh->b_size))
91 goto fail;106 goto fail;
92 if (!GFS2_EATYPE_VALID(ea->ea_type))107 if (!gfs2_eatype_valid(sdp, ea->ea_type))
93 goto fail;108 goto fail;
94
95 error = ea_call(ip, bh, ea, prev, data);109 error = ea_call(ip, bh, ea, prev, data);
96 if (error)110 if (error)
97 return error;111 return error;
@@ -344,6 +358,7 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, · 246 unmodified lines
344 struct gfs2_ea_header *ea, struct gfs2_ea_header *prev,358 struct gfs2_ea_header *ea, struct gfs2_ea_header *prev,
345 void *private)359 void *private)
346{360{
361 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
347 struct ea_list *ei = private;362 struct ea_list *ei = private;
348 struct gfs2_ea_request *er = ei->ei_er;363 struct gfs2_ea_request *er = ei->ei_er;
349 unsigned int ea_size;364 unsigned int ea_size;
@@ -353,6 +368,8 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, · 3 unmodified lines
353 if (ea->ea_type == GFS2_EATYPE_UNUSED)368 if (ea->ea_type == GFS2_EATYPE_UNUSED)
354 return 0;369 return 0;
355 370
371 BUG_ON(ea->ea_type > GFS2_EATYPE_SECURITY &&
372 sdp->sd_sb.sb_fs_format == GFS2_FS_FORMAT_MIN);
356 switch (ea->ea_type) {373 switch (ea->ea_type) {
357 case GFS2_EATYPE_USR:374 case GFS2_EATYPE_USR:
358 prefix = "user.";375 prefix = "user.";
@@ -366,8 +383,12 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, · 7 unmodified lines
366 prefix = "security.";383 prefix = "security.";
367 l = 9;384 l = 9;
368 break;385 break;
386 case GFS2_EATYPE_TRUSTED:
387 prefix = "trusted.";
388 l = 8;
389 break;
369 default:390 default:
370 BUG();391 return 0;
371 }392 }
372 393
373 ea_size = l + ea->ea_name_len + 1;394 ea_size = l + ea->ea_name_len + 1;
@@ -1463,7 +1484,25 @@ static const struct xattr_handler gfs2_xattr_security_handler = { · 1089 unmodified lines
1463 .set = gfs2_xattr_set,1484 .set = gfs2_xattr_set,
1464};1485};
1465 1486
1466const struct xattr_handler *gfs2_xattr_handlers[] = {1487static bool
1488gfs2_xattr_trusted_list(struct dentry *dentry)
1489{
1490 return capable(CAP_SYS_ADMIN);
1491}
1492
1493static const struct xattr_handler gfs2_xattr_trusted_handler = {
1494 .prefix = XATTR_TRUSTED_PREFIX,
1495 .flags = GFS2_EATYPE_TRUSTED,
1496 .list = gfs2_xattr_trusted_list,
1497 .get = gfs2_xattr_get,
1498 .set = gfs2_xattr_set,
1499};
1500
1501const struct xattr_handler *gfs2_xattr_handlers_max[] = {
1502 /* GFS2_FS_FORMAT_MAX */
1503 &gfs2_xattr_trusted_handler,
1504
1505 /* GFS2_FS_FORMAT_MIN */
1467 &gfs2_xattr_user_handler,1506 &gfs2_xattr_user_handler,
1468 &gfs2_xattr_security_handler,1507 &gfs2_xattr_security_handler,
1469 &posix_acl_access_xattr_handler,1508 &posix_acl_access_xattr_handler,
@@ -1471,3 +1510,4 @@ const struct xattr_handler *gfs2_xattr_handlers[] = { · 1 unmodified line
1471 NULL,1510 NULL,
1472};1511};
1473 1512
1513const struct xattr_handler **gfs2_xattr_handlers_min = gfs2_xattr_handlers_max + 1;
include/uapi/linux/gfs2_ondisk.h+3−2
@@ -47,7 +47,7 @@ · 46 unmodified lines
47#define GFS2_FORMAT_DE 120047#define GFS2_FORMAT_DE 1200
48#define GFS2_FORMAT_QU 150048#define GFS2_FORMAT_QU 1500
49/* These are part of the superblock */49/* These are part of the superblock */
50#define GFS2_FORMAT_FS 180150#define GFS2_FORMAT_FS 1802
51#define GFS2_FORMAT_MULTI 190051#define GFS2_FORMAT_MULTI 1900
52 52
53/*53/*
@@ -389,8 +389,9 @@ struct gfs2_leaf { · 335 unmodified lines
389#define GFS2_EATYPE_USR 1389#define GFS2_EATYPE_USR 1
390#define GFS2_EATYPE_SYS 2390#define GFS2_EATYPE_SYS 2
391#define GFS2_EATYPE_SECURITY 3391#define GFS2_EATYPE_SECURITY 3
392#define GFS2_EATYPE_TRUSTED 4
392 393
393#define GFS2_EATYPE_LAST 3394#define GFS2_EATYPE_LAST 4
394#define GFS2_EATYPE_VALID(x) ((x) <= GFS2_EATYPE_LAST)395#define GFS2_EATYPE_VALID(x) ((x) <= GFS2_EATYPE_LAST)
395 396
396#define GFS2_EAFLAG_LAST 0x01 /* last ea in block */397#define GFS2_EAFLAG_LAST 0x01 /* last ea in block */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t