xfs: inode recovery does not validate the recovered inode
authorDave Chinner <dchinner@redhat.com>
Fri, 10 Nov 2023 04:33:13 +0000 (15:33 +1100)
committerChandan Babu R <chandanbabu@kernel.org>
Mon, 13 Nov 2023 03:41:41 +0000 (09:11 +0530)
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 <dchinner@redhat.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/xfs_inode_item_recover.c

index 543f3748c2a35334c7c95fda0bbea1d4f5d2bbdf..137a65bda95dc1922d5ecab62ec9c7d358ac1b4a 100644 (file)
@@ -510,6 +510,9 @@ xfs_dinode_verify(
        if (mode && nextents + naextents > nblocks)
                return __this_address;
 
+       if (nextents + naextents == 0 && nblocks != 0)
+               return __this_address;
+
        if (S_ISDIR(mode) && nextents > mp->m_dir_geo->max_extents)
                return __this_address;
 
index 0e5dba2343ea13e2e0451178097f6ad247371724..1c5ba2a732b0597509f4c3f601581b7f71875807 100644 (file)
@@ -286,6 +286,7 @@ xlog_recover_inode_commit_pass2(
        struct xfs_log_dinode           *ldip;
        uint                            isize;
        int                             need_free = 0;
+       xfs_failaddr_t                  fa;
 
        if (item->ri_buf[0].i_len == sizeof(struct xfs_inode_log_format)) {
                in_f = item->ri_buf[0].i_addr;
@@ -528,8 +529,19 @@ out_owner_change:
            (dip->di_mode != 0))
                error = xfs_recover_inode_owner_change(mp, dip, in_f,
                                                       buffer_list);
-       /* re-generate the checksum. */
+       /* re-generate the checksum and validate the recovered inode. */
        xfs_dinode_calc_crc(log->l_mp, dip);
+       fa = xfs_dinode_verify(log->l_mp, in_f->ilf_ino, dip);
+       if (fa) {
+               XFS_CORRUPTION_ERROR(
+                       "Bad dinode after recovery",
+                               XFS_ERRLEVEL_LOW, mp, dip, sizeof(*dip));
+               xfs_alert(mp,
+                       "Metadata corruption detected at %pS, inode 0x%llx",
+                       fa, in_f->ilf_ino);
+               error = -EFSCORRUPTED;
+               goto out_release;
+       }
 
        ASSERT(bp->b_mount == mp);
        bp->b_flags |= _XBF_LOGRECOVERY;