Skip to content

Commit 038ca18

Browse files
Dave ChinnerChandan Babu R
authored andcommitted
xfs: inode recovery does not validate the recovered inode
Discovered when trying to track down a weird recovery corruption issue that wasn't detected at recovery time. The specific corruption was a zero extent count field when big extent counts are in use, and it turns out the dinode verifier doesn't detect that specific corruption case, either. So fix it too. Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent a2e4388 commit 038ca18

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

fs/xfs/libxfs/xfs_inode_buf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ xfs_dinode_verify(
510510
if (mode && nextents + naextents > nblocks)
511511
return __this_address;
512512

513+
if (nextents + naextents == 0 && nblocks != 0)
514+
return __this_address;
515+
513516
if (S_ISDIR(mode) && nextents > mp->m_dir_geo->max_extents)
514517
return __this_address;
515518

fs/xfs/xfs_inode_item_recover.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ xlog_recover_inode_commit_pass2(
286286
struct xfs_log_dinode *ldip;
287287
uint isize;
288288
int need_free = 0;
289+
xfs_failaddr_t fa;
289290

290291
if (item->ri_buf[0].i_len == sizeof(struct xfs_inode_log_format)) {
291292
in_f = item->ri_buf[0].i_addr;
@@ -528,8 +529,19 @@ xlog_recover_inode_commit_pass2(
528529
(dip->di_mode != 0))
529530
error = xfs_recover_inode_owner_change(mp, dip, in_f,
530531
buffer_list);
531-
/* re-generate the checksum. */
532+
/* re-generate the checksum and validate the recovered inode. */
532533
xfs_dinode_calc_crc(log->l_mp, dip);
534+
fa = xfs_dinode_verify(log->l_mp, in_f->ilf_ino, dip);
535+
if (fa) {
536+
XFS_CORRUPTION_ERROR(
537+
"Bad dinode after recovery",
538+
XFS_ERRLEVEL_LOW, mp, dip, sizeof(*dip));
539+
xfs_alert(mp,
540+
"Metadata corruption detected at %pS, inode 0x%llx",
541+
fa, in_f->ilf_ino);
542+
error = -EFSCORRUPTED;
543+
goto out_release;
544+
}
533545

534546
ASSERT(bp->b_mount == mp);
535547
bp->b_flags |= _XBF_LOGRECOVERY;

0 commit comments

Comments
 (0)