aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/libxfs/xfs_ialloc_btree.c
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2019-02-07 13:45:46 -0500
committerDarrick J. Wong <darrick.wong@oracle.com>2019-02-11 19:07:01 -0500
commit8473fee340e37711b9ac6a5cc591305ccaaa4778 (patch)
treea6e4eb63b46dfe5837960d8dbc69a578db45aae9 /fs/xfs/libxfs/xfs_ialloc_btree.c
parent01e68f40bf7846b58d2734aa11b0cbcaadbeaa3e (diff)
xfs: distinguish between inobt and finobt magic values
The inode btree verifier code is shared between the inode btree and free inode btree because the underlying metadata formats are essentially equivalent. A side effect of this is that the verifier cannot determine whether a particular btree block should have an inobt or finobt magic value. This logic allows an unfortunate xfs_repair bug to escape detection where certain level > 0 nodes of the finobt are stamped with inobt magic by xfs_repair finobt reconstruction. This is fortunately not a severe problem since the inode btree magic values do not contribute to any changes in kernel behavior, but we do need a means to detect and prevent this problem in the future. Add a field to xfs_buf_ops to store the v4 and v5 superblock magic values expected by a particular verifier. Add a helper to check an on-disk magic value against the value expected by the verifier. Call the helper from the shared [f]inobt verifier code for magic value verification. This ensures that the inode btree blocks each have the appropriate magic value based on specific tree type and superblock version. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs/xfs/libxfs/xfs_ialloc_btree.c')
-rw-r--r--fs/xfs/libxfs/xfs_ialloc_btree.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c
index 798269eb4767..c2df1f89eec8 100644
--- a/fs/xfs/libxfs/xfs_ialloc_btree.c
+++ b/fs/xfs/libxfs/xfs_ialloc_btree.c
@@ -260,6 +260,9 @@ xfs_inobt_verify(
260 xfs_failaddr_t fa; 260 xfs_failaddr_t fa;
261 unsigned int level; 261 unsigned int level;
262 262
263 if (!xfs_verify_magic(bp, block->bb_magic))
264 return __this_address;
265
263 /* 266 /*
264 * During growfs operations, we can't verify the exact owner as the 267 * During growfs operations, we can't verify the exact owner as the
265 * perag is not fully initialised and hence not attached to the buffer. 268 * perag is not fully initialised and hence not attached to the buffer.
@@ -270,18 +273,10 @@ xfs_inobt_verify(
270 * but beware of the landmine (i.e. need to check pag->pagi_init) if we 273 * but beware of the landmine (i.e. need to check pag->pagi_init) if we
271 * ever do. 274 * ever do.
272 */ 275 */
273 switch (block->bb_magic) { 276 if (xfs_sb_version_hascrc(&mp->m_sb)) {
274 case cpu_to_be32(XFS_IBT_CRC_MAGIC):
275 case cpu_to_be32(XFS_FIBT_CRC_MAGIC):
276 fa = xfs_btree_sblock_v5hdr_verify(bp); 277 fa = xfs_btree_sblock_v5hdr_verify(bp);
277 if (fa) 278 if (fa)
278 return fa; 279 return fa;
279 /* fall through */
280 case cpu_to_be32(XFS_IBT_MAGIC):
281 case cpu_to_be32(XFS_FIBT_MAGIC):
282 break;
283 default:
284 return __this_address;
285 } 280 }
286 281
287 /* level verification */ 282 /* level verification */
@@ -328,6 +323,7 @@ xfs_inobt_write_verify(
328 323
329const struct xfs_buf_ops xfs_inobt_buf_ops = { 324const struct xfs_buf_ops xfs_inobt_buf_ops = {
330 .name = "xfs_inobt", 325 .name = "xfs_inobt",
326 .magic = { cpu_to_be32(XFS_IBT_MAGIC), cpu_to_be32(XFS_IBT_CRC_MAGIC) },
331 .verify_read = xfs_inobt_read_verify, 327 .verify_read = xfs_inobt_read_verify,
332 .verify_write = xfs_inobt_write_verify, 328 .verify_write = xfs_inobt_write_verify,
333 .verify_struct = xfs_inobt_verify, 329 .verify_struct = xfs_inobt_verify,
@@ -335,6 +331,8 @@ const struct xfs_buf_ops xfs_inobt_buf_ops = {
335 331
336const struct xfs_buf_ops xfs_finobt_buf_ops = { 332const struct xfs_buf_ops xfs_finobt_buf_ops = {
337 .name = "xfs_finobt", 333 .name = "xfs_finobt",
334 .magic = { cpu_to_be32(XFS_FIBT_MAGIC),
335 cpu_to_be32(XFS_FIBT_CRC_MAGIC) },
338 .verify_read = xfs_inobt_read_verify, 336 .verify_read = xfs_inobt_read_verify,
339 .verify_write = xfs_inobt_write_verify, 337 .verify_write = xfs_inobt_write_verify,
340 .verify_struct = xfs_inobt_verify, 338 .verify_struct = xfs_inobt_verify,