Skip to content

Commit 25b1e9d

Browse files
Darrick J. Wongdchinner
authored andcommitted
xfs: validate xattr name earlier in recovery
When we're validating a recovered xattr log item during log recovery, we should check the name before starting to allocate resources. This isn't strictly necessary on its own, but it means that we won't bother with huge memory allocations during recovery if the attr name is garbage, which will simplify the changes in the next patch. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Allison Henderson <[email protected]> Signed-off-by: Dave Chinner <[email protected]>
1 parent 85d76ae commit 25b1e9d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/xfs/xfs_attr_item.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,23 @@ xlog_recover_attri_commit_pass2(
688688
struct xfs_mount *mp = log->l_mp;
689689
struct xfs_attri_log_item *attrip;
690690
struct xfs_attri_log_format *attri_formatp;
691+
const void *attr_name;
691692
int region = 0;
692693

693694
attri_formatp = item->ri_buf[region].i_addr;
695+
attr_name = item->ri_buf[1].i_addr;
694696

695-
/* Validate xfs_attri_log_format */
697+
/* Validate xfs_attri_log_format before the large memory allocation */
696698
if (!xfs_attri_validate(mp, attri_formatp)) {
697699
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
698700
return -EFSCORRUPTED;
699701
}
700702

703+
if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) {
704+
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
705+
return -EFSCORRUPTED;
706+
}
707+
701708
/* memory alloc failure will cause replay to abort */
702709
attrip = xfs_attri_init(mp, attri_formatp->alfi_name_len,
703710
attri_formatp->alfi_value_len);
@@ -713,12 +720,6 @@ xlog_recover_attri_commit_pass2(
713720
memcpy(attrip->attri_name, item->ri_buf[region].i_addr,
714721
attrip->attri_name_len);
715722

716-
if (!xfs_attr_namecheck(attrip->attri_name, attrip->attri_name_len)) {
717-
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
718-
error = -EFSCORRUPTED;
719-
goto out;
720-
}
721-
722723
if (attrip->attri_value_len > 0) {
723724
region++;
724725
memcpy(attrip->attri_value, item->ri_buf[region].i_addr,

0 commit comments

Comments
 (0)