Skip to content

Commit 318cac2

Browse files
Dave Chinnergregkh
authored andcommitted
xfs: inode recovery does not validate the recovered inode
[ Upstream commit 038ca189c0d2c1570b4d922f25b524007c85cf94 ] 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]> Signed-off-by: Leah Rumancik <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6e78262 commit 318cac2

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
@@ -507,6 +507,9 @@ xfs_dinode_verify(
507507
if (mode && nextents + naextents > nblocks)
508508
return __this_address;
509509

510+
if (nextents + naextents == 0 && nblocks != 0)
511+
return __this_address;
512+
510513
if (S_ISDIR(mode) && nextents > mp->m_dir_geo->max_extents)
511514
return __this_address;
512515

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;
@@ -530,8 +531,19 @@ xlog_recover_inode_commit_pass2(
530531
(dip->di_mode != 0))
531532
error = xfs_recover_inode_owner_change(mp, dip, in_f,
532533
buffer_list);
533-
/* re-generate the checksum. */
534+
/* re-generate the checksum and validate the recovered inode. */
534535
xfs_dinode_calc_crc(log->l_mp, dip);
536+
fa = xfs_dinode_verify(log->l_mp, in_f->ilf_ino, dip);
537+
if (fa) {
538+
XFS_CORRUPTION_ERROR(
539+
"Bad dinode after recovery",
540+
XFS_ERRLEVEL_LOW, mp, dip, sizeof(*dip));
541+
xfs_alert(mp,
542+
"Metadata corruption detected at %pS, inode 0x%llx",
543+
fa, in_f->ilf_ino);
544+
error = -EFSCORRUPTED;
545+
goto out_release;
546+
}
535547

536548
ASSERT(bp->b_mount == mp);
537549
bp->b_flags |= _XBF_LOGRECOVERY;

0 commit comments

Comments
 (0)