| @@ -70,6 +70,20 @@ static int ea_check_size(struct gfs2_sbd *sdp, unsigned int nsize, size_t dsize) · 69 unmodified lines |
| 70 | 70 | return 0; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | +static 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 | + |
| 73 | 87 | typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh, |
| 74 | 88 | struct gfs2_ea_header *ea, |
| 75 | 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 |
| 77 | 91 | static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, |
| 78 | 92 | ea_call_t ea_call, void *data) |
| 79 | 93 | { |
| 94 | + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
| 80 | 95 | struct gfs2_ea_header *ea, *prev = NULL; |
| 81 | 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 | 104 | if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <= |
| 90 | 105 | bh->b_data + bh->b_size)) |
| 91 | 106 | goto fail; |
| 92 | | − if (!GFS2_EATYPE_VALID(ea->ea_type)) |
| 107 | + if (!gfs2_eatype_valid(sdp, ea->ea_type)) |
| 93 | 108 | goto fail; |
| 94 | | − |
| 95 | 109 | error = ea_call(ip, bh, ea, prev, data); |
| 96 | 110 | if (error) |
| 97 | 111 | return error; |
| @@ -344,6 +358,7 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, · 246 unmodified lines |
| 344 | 358 | struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, |
| 345 | 359 | void *private) |
| 346 | 360 | { |
| 361 | + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
| 347 | 362 | struct ea_list *ei = private; |
| 348 | 363 | struct gfs2_ea_request *er = ei->ei_er; |
| 349 | 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 | 368 | if (ea->ea_type == GFS2_EATYPE_UNUSED) |
| 354 | 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 | 373 | switch (ea->ea_type) { |
| 357 | 374 | case GFS2_EATYPE_USR: |
| 358 | 375 | prefix = "user."; |
| @@ -366,8 +383,12 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, · 7 unmodified lines |
| 366 | 383 | prefix = "security."; |
| 367 | 384 | l = 9; |
| 368 | 385 | break; |
| 386 | + case GFS2_EATYPE_TRUSTED: |
| 387 | + prefix = "trusted."; |
| 388 | + l = 8; |
| 389 | + break; |
| 369 | 390 | default: |
| 370 | | − BUG(); |
| 391 | + return 0; |
| 371 | 392 | } |
| 372 | 393 | |
| 373 | 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 | 1484 | .set = gfs2_xattr_set, |
| 1464 | 1485 | }; |
| 1465 | 1486 | |
| 1466 | | −const struct xattr_handler *gfs2_xattr_handlers[] = { |
| 1487 | +static bool |
| 1488 | +gfs2_xattr_trusted_list(struct dentry *dentry) |
| 1489 | +{ |
| 1490 | + return capable(CAP_SYS_ADMIN); |
| 1491 | +} |
| 1492 | + |
| 1493 | +static 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 | + |
| 1501 | +const struct xattr_handler *gfs2_xattr_handlers_max[] = { |
| 1502 | + /* GFS2_FS_FORMAT_MAX */ |
| 1503 | + &gfs2_xattr_trusted_handler, |
| 1504 | + |
| 1505 | + /* GFS2_FS_FORMAT_MIN */ |
| 1467 | 1506 | &gfs2_xattr_user_handler, |
| 1468 | 1507 | &gfs2_xattr_security_handler, |
| 1469 | 1508 | &posix_acl_access_xattr_handler, |
| @@ -1471,3 +1510,4 @@ const struct xattr_handler *gfs2_xattr_handlers[] = { · 1 unmodified line |
| 1471 | 1510 | NULL, |
| 1472 | 1511 | }; |
| 1473 | 1512 | |
| 1513 | +const struct xattr_handler **gfs2_xattr_handlers_min = gfs2_xattr_handlers_max + 1; |