Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: log recovery needs to validate against sb_meta_uuid

Now that sb_uuid can be changed by the user, we cannot use this to
validate the metadata blocks being recovered belong to this
filesystem. We must check against the sb_meta_uuid as that will
remain unchanged.

There is a complication in this code - the superblock itself. We can
not check the sb_meta_uuid unconditionally, as that may not be set
on disk. Hence we must verify the superblock sb_uuid matches between
the log record and the in-core superblock.

Found by inspection after the previous two problems were found.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>

authored by

Dave Chinner and committed by
Dave Chinner
fcfbe2c4 ac383de2

+12 -2
+12 -2
fs/xfs/xfs_log_recover.c
··· 1890 1890 uuid = &((struct xfs_attr3_rmt_hdr *)blk)->rm_uuid; 1891 1891 break; 1892 1892 case XFS_SB_MAGIC: 1893 + /* 1894 + * superblock uuids are magic. We may or may not have a 1895 + * sb_meta_uuid on disk, but it will be set in the in-core 1896 + * superblock. We set the uuid pointer for verification 1897 + * according to the superblock feature mask to ensure we check 1898 + * the relevant UUID in the superblock. 1899 + */ 1893 1900 lsn = be64_to_cpu(((struct xfs_dsb *)blk)->sb_lsn); 1894 - uuid = &((struct xfs_dsb *)blk)->sb_uuid; 1901 + if (xfs_sb_version_hasmetauuid(&mp->m_sb)) 1902 + uuid = &((struct xfs_dsb *)blk)->sb_meta_uuid; 1903 + else 1904 + uuid = &((struct xfs_dsb *)blk)->sb_uuid; 1895 1905 break; 1896 1906 default: 1897 1907 break; 1898 1908 } 1899 1909 1900 1910 if (lsn != (xfs_lsn_t)-1) { 1901 - if (!uuid_equal(&mp->m_sb.sb_uuid, uuid)) 1911 + if (!uuid_equal(&mp->m_sb.sb_meta_uuid, uuid)) 1902 1912 goto recover_immediately; 1903 1913 return lsn; 1904 1914 }