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

xfs: miscellaneous verifier magic value fixups

Most buffer verifiers have hardcoded magic value checks
conditionalized on the version of the filesystem. The magic value
field of the verifier structure facilitates abstraction of some of
this code. Populate the ->magic field of various verifiers to take
advantage of this abstraction. No functional changes.

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>

authored by

Brian Foster and committed by
Darrick J. Wong
39708c20 09f42019

+57 -46
+8 -4
fs/xfs/libxfs/xfs_alloc.c
··· 568 568 if (!xfs_sb_version_hascrc(&mp->m_sb)) 569 569 return NULL; 570 570 571 - if (!uuid_equal(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid)) 571 + if (!xfs_verify_magic(bp, agfl->agfl_magicnum)) 572 572 return __this_address; 573 - if (agfl->agfl_magicnum != cpu_to_be32(XFS_AGFL_MAGIC)) 573 + if (!uuid_equal(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid)) 574 574 return __this_address; 575 575 /* 576 576 * during growfs operations, the perag is not fully initialised, ··· 643 643 644 644 const struct xfs_buf_ops xfs_agfl_buf_ops = { 645 645 .name = "xfs_agfl", 646 + .magic = { cpu_to_be32(XFS_AGFL_MAGIC), cpu_to_be32(XFS_AGFL_MAGIC) }, 646 647 .verify_read = xfs_agfl_read_verify, 647 648 .verify_write = xfs_agfl_write_verify, 648 649 .verify_struct = xfs_agfl_verify, ··· 2588 2587 return __this_address; 2589 2588 } 2590 2589 2591 - if (!(agf->agf_magicnum == cpu_to_be32(XFS_AGF_MAGIC) && 2592 - XFS_AGF_GOOD_VERSION(be32_to_cpu(agf->agf_versionnum)) && 2590 + if (!xfs_verify_magic(bp, agf->agf_magicnum)) 2591 + return __this_address; 2592 + 2593 + if (!(XFS_AGF_GOOD_VERSION(be32_to_cpu(agf->agf_versionnum)) && 2593 2594 be32_to_cpu(agf->agf_freeblks) <= be32_to_cpu(agf->agf_length) && 2594 2595 be32_to_cpu(agf->agf_flfirst) < xfs_agfl_size(mp) && 2595 2596 be32_to_cpu(agf->agf_fllast) < xfs_agfl_size(mp) && ··· 2673 2670 2674 2671 const struct xfs_buf_ops xfs_agf_buf_ops = { 2675 2672 .name = "xfs_agf", 2673 + .magic = { cpu_to_be32(XFS_AGF_MAGIC), cpu_to_be32(XFS_AGF_MAGIC) }, 2676 2674 .verify_read = xfs_agf_read_verify, 2677 2675 .verify_write = xfs_agf_write_verify, 2678 2676 .verify_struct = xfs_agf_verify,
+5 -6
fs/xfs/libxfs/xfs_attr_leaf.c
··· 248 248 249 249 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf); 250 250 251 + if (!xfs_verify_magic(bp, leaf->hdr.info.magic)) 252 + return __this_address; 253 + 251 254 if (xfs_sb_version_hascrc(&mp->m_sb)) { 252 255 struct xfs_da3_node_hdr *hdr3 = bp->b_addr; 253 - 254 - if (hdr3->info.hdr.magic != cpu_to_be16(XFS_ATTR3_LEAF_MAGIC)) 255 - return __this_address; 256 256 257 257 if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) 258 258 return __this_address; 259 259 if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn) 260 260 return __this_address; 261 261 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn))) 262 - return __this_address; 263 - } else { 264 - if (leaf->hdr.info.magic != cpu_to_be16(XFS_ATTR_LEAF_MAGIC)) 265 262 return __this_address; 266 263 } 267 264 /* ··· 366 369 367 370 const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = { 368 371 .name = "xfs_attr3_leaf", 372 + .magic = { cpu_to_be16(XFS_ATTR_LEAF_MAGIC), 373 + cpu_to_be16(XFS_ATTR3_LEAF_MAGIC) }, 369 374 .verify_read = xfs_attr3_leaf_read_verify, 370 375 .verify_write = xfs_attr3_leaf_write_verify, 371 376 .verify_struct = xfs_attr3_leaf_verify,
+5 -3
fs/xfs/libxfs/xfs_attr_remote.c
··· 79 79 static xfs_failaddr_t 80 80 xfs_attr3_rmt_verify( 81 81 struct xfs_mount *mp, 82 + struct xfs_buf *bp, 82 83 void *ptr, 83 84 int fsbsize, 84 85 xfs_daddr_t bno) ··· 88 87 89 88 if (!xfs_sb_version_hascrc(&mp->m_sb)) 90 89 return __this_address; 91 - if (rmt->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC)) 90 + if (!xfs_verify_magic(bp, rmt->rm_magic)) 92 91 return __this_address; 93 92 if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid)) 94 93 return __this_address; ··· 132 131 *failaddr = __this_address; 133 132 return -EFSBADCRC; 134 133 } 135 - *failaddr = xfs_attr3_rmt_verify(mp, ptr, blksize, bno); 134 + *failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno); 136 135 if (*failaddr) 137 136 return -EFSCORRUPTED; 138 137 len -= blksize; ··· 194 193 while (len > 0) { 195 194 struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; 196 195 197 - fa = xfs_attr3_rmt_verify(mp, ptr, blksize, bno); 196 + fa = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno); 198 197 if (fa) { 199 198 xfs_verifier_error(bp, -EFSCORRUPTED, fa); 200 199 return; ··· 221 220 222 221 const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = { 223 222 .name = "xfs_attr3_rmt", 223 + .magic = { 0, cpu_to_be32(XFS_ATTR3_RMT_MAGIC) }, 224 224 .verify_read = xfs_attr3_rmt_read_verify, 225 225 .verify_write = xfs_attr3_rmt_write_verify, 226 226 .verify_struct = xfs_attr3_rmt_verify_struct,
+6 -7
fs/xfs/libxfs/xfs_bmap_btree.c
··· 416 416 xfs_failaddr_t fa; 417 417 unsigned int level; 418 418 419 - switch (block->bb_magic) { 420 - case cpu_to_be32(XFS_BMAP_CRC_MAGIC): 419 + if (!xfs_verify_magic(bp, block->bb_magic)) 420 + return __this_address; 421 + 422 + if (xfs_sb_version_hascrc(&mp->m_sb)) { 421 423 /* 422 424 * XXX: need a better way of verifying the owner here. Right now 423 425 * just make sure there has been one set. ··· 427 425 fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN); 428 426 if (fa) 429 427 return fa; 430 - /* fall through */ 431 - case cpu_to_be32(XFS_BMAP_MAGIC): 432 - break; 433 - default: 434 - return __this_address; 435 428 } 436 429 437 430 /* ··· 478 481 479 482 const struct xfs_buf_ops xfs_bmbt_buf_ops = { 480 483 .name = "xfs_bmbt", 484 + .magic = { cpu_to_be32(XFS_BMAP_MAGIC), 485 + cpu_to_be32(XFS_BMAP_CRC_MAGIC) }, 481 486 .verify_read = xfs_bmbt_read_verify, 482 487 .verify_write = xfs_bmbt_write_verify, 483 488 .verify_struct = xfs_bmbt_verify,
+5 -6
fs/xfs/libxfs/xfs_da_btree.c
··· 129 129 130 130 ops->node_hdr_from_disk(&ichdr, hdr); 131 131 132 + if (!xfs_verify_magic(bp, hdr->hdr.info.magic)) 133 + return __this_address; 134 + 132 135 if (xfs_sb_version_hascrc(&mp->m_sb)) { 133 136 struct xfs_da3_node_hdr *hdr3 = bp->b_addr; 134 - 135 - if (hdr3->info.hdr.magic != cpu_to_be16(XFS_DA3_NODE_MAGIC)) 136 - return __this_address; 137 137 138 138 if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) 139 139 return __this_address; 140 140 if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn) 141 141 return __this_address; 142 142 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn))) 143 - return __this_address; 144 - } else { 145 - if (hdr->hdr.info.magic != cpu_to_be16(XFS_DA_NODE_MAGIC)) 146 143 return __this_address; 147 144 } 148 145 if (ichdr.level == 0) ··· 254 257 255 258 const struct xfs_buf_ops xfs_da3_node_buf_ops = { 256 259 .name = "xfs_da3_node", 260 + .magic = { cpu_to_be16(XFS_DA_NODE_MAGIC), 261 + cpu_to_be16(XFS_DA3_NODE_MAGIC) }, 257 262 .verify_read = xfs_da3_node_read_verify, 258 263 .verify_write = xfs_da3_node_write_verify, 259 264 .verify_struct = xfs_da3_node_verify_struct,
+5 -5
fs/xfs/libxfs/xfs_dir2_block.c
··· 53 53 struct xfs_mount *mp = bp->b_target->bt_mount; 54 54 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; 55 55 56 + if (!xfs_verify_magic(bp, hdr3->magic)) 57 + return __this_address; 58 + 56 59 if (xfs_sb_version_hascrc(&mp->m_sb)) { 57 - if (hdr3->magic != cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) 58 - return __this_address; 59 60 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) 60 61 return __this_address; 61 62 if (be64_to_cpu(hdr3->blkno) != bp->b_bn) 62 63 return __this_address; 63 64 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) 64 - return __this_address; 65 - } else { 66 - if (hdr3->magic != cpu_to_be32(XFS_DIR2_BLOCK_MAGIC)) 67 65 return __this_address; 68 66 } 69 67 return __xfs_dir3_data_check(NULL, bp); ··· 110 112 111 113 const struct xfs_buf_ops xfs_dir3_block_buf_ops = { 112 114 .name = "xfs_dir3_block", 115 + .magic = { cpu_to_be32(XFS_DIR2_BLOCK_MAGIC), 116 + cpu_to_be32(XFS_DIR3_BLOCK_MAGIC) }, 113 117 .verify_read = xfs_dir3_block_read_verify, 114 118 .verify_write = xfs_dir3_block_write_verify, 115 119 .verify_struct = xfs_dir3_block_verify,
+7 -5
fs/xfs/libxfs/xfs_dir2_data.c
··· 252 252 struct xfs_mount *mp = bp->b_target->bt_mount; 253 253 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; 254 254 255 + if (!xfs_verify_magic(bp, hdr3->magic)) 256 + return __this_address; 257 + 255 258 if (xfs_sb_version_hascrc(&mp->m_sb)) { 256 - if (hdr3->magic != cpu_to_be32(XFS_DIR3_DATA_MAGIC)) 257 - return __this_address; 258 259 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) 259 260 return __this_address; 260 261 if (be64_to_cpu(hdr3->blkno) != bp->b_bn) 261 262 return __this_address; 262 263 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) 263 - return __this_address; 264 - } else { 265 - if (hdr3->magic != cpu_to_be32(XFS_DIR2_DATA_MAGIC)) 266 264 return __this_address; 267 265 } 268 266 return __xfs_dir3_data_check(NULL, bp); ··· 337 339 338 340 const struct xfs_buf_ops xfs_dir3_data_buf_ops = { 339 341 .name = "xfs_dir3_data", 342 + .magic = { cpu_to_be32(XFS_DIR2_DATA_MAGIC), 343 + cpu_to_be32(XFS_DIR3_DATA_MAGIC) }, 340 344 .verify_read = xfs_dir3_data_read_verify, 341 345 .verify_write = xfs_dir3_data_write_verify, 342 346 .verify_struct = xfs_dir3_data_verify, ··· 346 346 347 347 static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = { 348 348 .name = "xfs_dir3_data_reada", 349 + .magic = { cpu_to_be32(XFS_DIR2_DATA_MAGIC), 350 + cpu_to_be32(XFS_DIR3_DATA_MAGIC) }, 349 351 .verify_read = xfs_dir3_data_reada_verify, 350 352 .verify_write = xfs_dir3_data_write_verify, 351 353 };
+5 -5
fs/xfs/libxfs/xfs_dir2_node.c
··· 87 87 struct xfs_mount *mp = bp->b_target->bt_mount; 88 88 struct xfs_dir2_free_hdr *hdr = bp->b_addr; 89 89 90 + if (!xfs_verify_magic(bp, hdr->magic)) 91 + return __this_address; 92 + 90 93 if (xfs_sb_version_hascrc(&mp->m_sb)) { 91 94 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; 92 95 93 - if (hdr3->magic != cpu_to_be32(XFS_DIR3_FREE_MAGIC)) 94 - return __this_address; 95 96 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) 96 97 return __this_address; 97 98 if (be64_to_cpu(hdr3->blkno) != bp->b_bn) 98 99 return __this_address; 99 100 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) 100 - return __this_address; 101 - } else { 102 - if (hdr->magic != cpu_to_be32(XFS_DIR2_FREE_MAGIC)) 103 101 return __this_address; 104 102 } 105 103 ··· 149 151 150 152 const struct xfs_buf_ops xfs_dir3_free_buf_ops = { 151 153 .name = "xfs_dir3_free", 154 + .magic = { cpu_to_be32(XFS_DIR2_FREE_MAGIC), 155 + cpu_to_be32(XFS_DIR3_FREE_MAGIC) }, 152 156 .verify_read = xfs_dir3_free_read_verify, 153 157 .verify_write = xfs_dir3_free_write_verify, 154 158 .verify_struct = xfs_dir3_free_verify,
+2 -1
fs/xfs/libxfs/xfs_ialloc.c
··· 2508 2508 /* 2509 2509 * Validate the magic number of the agi block. 2510 2510 */ 2511 - if (agi->agi_magicnum != cpu_to_be32(XFS_AGI_MAGIC)) 2511 + if (!xfs_verify_magic(bp, agi->agi_magicnum)) 2512 2512 return __this_address; 2513 2513 if (!XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum))) 2514 2514 return __this_address; ··· 2582 2582 2583 2583 const struct xfs_buf_ops xfs_agi_buf_ops = { 2584 2584 .name = "xfs_agi", 2585 + .magic = { cpu_to_be32(XFS_AGI_MAGIC), cpu_to_be32(XFS_AGI_MAGIC) }, 2585 2586 .verify_read = xfs_agi_read_verify, 2586 2587 .verify_write = xfs_agi_write_verify, 2587 2588 .verify_struct = xfs_agi_verify,
+2 -1
fs/xfs/libxfs/xfs_refcount_btree.c
··· 209 209 xfs_failaddr_t fa; 210 210 unsigned int level; 211 211 212 - if (block->bb_magic != cpu_to_be32(XFS_REFC_CRC_MAGIC)) 212 + if (!xfs_verify_magic(bp, block->bb_magic)) 213 213 return __this_address; 214 214 215 215 if (!xfs_sb_version_hasreflink(&mp->m_sb)) ··· 264 264 265 265 const struct xfs_buf_ops xfs_refcountbt_buf_ops = { 266 266 .name = "xfs_refcountbt", 267 + .magic = { 0, cpu_to_be32(XFS_REFC_CRC_MAGIC) }, 267 268 .verify_read = xfs_refcountbt_read_verify, 268 269 .verify_write = xfs_refcountbt_write_verify, 269 270 .verify_struct = xfs_refcountbt_verify,
+2 -1
fs/xfs/libxfs/xfs_rmap_btree.c
··· 310 310 * from the on disk AGF. Again, we can only check against maximum limits 311 311 * in this case. 312 312 */ 313 - if (block->bb_magic != cpu_to_be32(XFS_RMAP_CRC_MAGIC)) 313 + if (!xfs_verify_magic(bp, block->bb_magic)) 314 314 return __this_address; 315 315 316 316 if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) ··· 365 365 366 366 const struct xfs_buf_ops xfs_rmapbt_buf_ops = { 367 367 .name = "xfs_rmapbt", 368 + .magic = { 0, cpu_to_be32(XFS_RMAP_CRC_MAGIC) }, 368 369 .verify_read = xfs_rmapbt_read_verify, 369 370 .verify_write = xfs_rmapbt_write_verify, 370 371 .verify_struct = xfs_rmapbt_verify,
+3 -1
fs/xfs/libxfs/xfs_sb.c
··· 229 229 uint32_t agcount = 0; 230 230 uint32_t rem; 231 231 232 - if (dsb->sb_magicnum != cpu_to_be32(XFS_SB_MAGIC)) { 232 + if (!xfs_verify_magic(bp, dsb->sb_magicnum)) { 233 233 xfs_warn(mp, "bad magic number"); 234 234 return -EWRONGFS; 235 235 } ··· 782 782 783 783 const struct xfs_buf_ops xfs_sb_buf_ops = { 784 784 .name = "xfs_sb", 785 + .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) }, 785 786 .verify_read = xfs_sb_read_verify, 786 787 .verify_write = xfs_sb_write_verify, 787 788 }; 788 789 789 790 const struct xfs_buf_ops xfs_sb_quiet_buf_ops = { 790 791 .name = "xfs_sb_quiet", 792 + .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) }, 791 793 .verify_read = xfs_sb_quiet_read_verify, 792 794 .verify_write = xfs_sb_write_verify, 793 795 };