From: Darrick J. Wong Date: Tue, 27 Feb 2018 04:43:17 +0000 (-0600) Subject: xfs: verify dinode header first X-Git-Tag: v4.16.0-rc1~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98703400d0a4c4c56874705ab692b14398068650;p=thirdparty%2Fxfsprogs-dev.git xfs: verify dinode header first Source kernel commit: 50aa90ef03007beca2c9108993f5b4f2bb4f0a66 Move the v3 inode integrity information (crc, owner, metauuid) before we look at anything else in the inode so that we don't waste time on a torn write or a totally garbled block. This makes xfs_dinode_verify more consistent with the other verifiers. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Eric Sandeen --- diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index e82e56d92..ba75e9aa4 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -391,6 +391,19 @@ xfs_dinode_verify( if (dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC)) return __this_address; + /* Verify v3 integrity information first */ + if (dip->di_version >= 3) { + if (!xfs_sb_version_hascrc(&mp->m_sb)) + return __this_address; + if (!xfs_verify_cksum((char *)dip, mp->m_sb.sb_inodesize, + XFS_DINODE_CRC_OFF)) + return __this_address; + if (be64_to_cpu(dip->di_ino) != ino) + return __this_address; + if (!uuid_equal(&dip->di_uuid, &mp->m_sb.sb_meta_uuid)) + return __this_address; + } + /* don't allow invalid i_size */ if (be64_to_cpu(dip->di_size) & (1ULL << 63)) return __this_address; @@ -407,16 +420,6 @@ xfs_dinode_verify( if (dip->di_version < 3) return NULL; - if (!xfs_sb_version_hascrc(&mp->m_sb)) - return __this_address; - if (!xfs_verify_cksum((char *)dip, mp->m_sb.sb_inodesize, - XFS_DINODE_CRC_OFF)) - return __this_address; - if (be64_to_cpu(dip->di_ino) != ino) - return __this_address; - if (!uuid_equal(&dip->di_uuid, &mp->m_sb.sb_meta_uuid)) - return __this_address; - flags = be16_to_cpu(dip->di_flags); flags2 = be64_to_cpu(dip->di_flags2);