xfs: inode recovery does not validate the recovered inode
[platform/kernel/linux-starfive.git] / fs / xfs / xfs_inode_item_recover.c
index 0e5dba2..144198a 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;
@@ -369,24 +370,26 @@ xlog_recover_inode_commit_pass2(
         * superblock flag to determine whether we need to look at di_flushiter
         * to skip replay when the on disk inode is newer than the log one
         */
-       if (!xfs_has_v3inodes(mp) &&
-           ldip->di_flushiter < be16_to_cpu(dip->di_flushiter)) {
-               /*
-                * Deal with the wrap case, DI_MAX_FLUSH is less
-                * than smaller numbers
-                */
-               if (be16_to_cpu(dip->di_flushiter) == DI_MAX_FLUSH &&
-                   ldip->di_flushiter < (DI_MAX_FLUSH >> 1)) {
-                       /* do nothing */
-               } else {
-                       trace_xfs_log_recover_inode_skip(log, in_f);
-                       error = 0;
-                       goto out_release;
+       if (!xfs_has_v3inodes(mp)) {
+               if (ldip->di_flushiter < be16_to_cpu(dip->di_flushiter)) {
+                       /*
+                        * Deal with the wrap case, DI_MAX_FLUSH is less
+                        * than smaller numbers
+                        */
+                       if (be16_to_cpu(dip->di_flushiter) == DI_MAX_FLUSH &&
+                           ldip->di_flushiter < (DI_MAX_FLUSH >> 1)) {
+                               /* do nothing */
+                       } else {
+                               trace_xfs_log_recover_inode_skip(log, in_f);
+                               error = 0;
+                               goto out_release;
+                       }
                }
+
+               /* Take the opportunity to reset the flush iteration count */
+               ldip->di_flushiter = 0;
        }
 
-       /* Take the opportunity to reset the flush iteration count */
-       ldip->di_flushiter = 0;
 
        if (unlikely(S_ISREG(ldip->di_mode))) {
                if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) &&
@@ -528,8 +531,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;