aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/xfs/libxfs/xfs_alloc.c12
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.c11
-rw-r--r--fs/xfs/libxfs/xfs_attr_remote.c8
-rw-r--r--fs/xfs/libxfs/xfs_bmap_btree.c13
-rw-r--r--fs/xfs/libxfs/xfs_da_btree.c11
-rw-r--r--fs/xfs/libxfs/xfs_dir2_block.c10
-rw-r--r--fs/xfs/libxfs/xfs_dir2_data.c12
-rw-r--r--fs/xfs/libxfs/xfs_dir2_node.c10
-rw-r--r--fs/xfs/libxfs/xfs_ialloc.c3
-rw-r--r--fs/xfs/libxfs/xfs_refcount_btree.c3
-rw-r--r--fs/xfs/libxfs/xfs_rmap_btree.c3
-rw-r--r--fs/xfs/libxfs/xfs_sb.c4
-rw-r--r--fs/xfs/libxfs/xfs_symlink_remote.c3
13 files changed, 57 insertions, 46 deletions
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 48aab07e7138..bc3367b8b7bb 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -568,9 +568,9 @@ xfs_agfl_verify(
568 if (!xfs_sb_version_hascrc(&mp->m_sb)) 568 if (!xfs_sb_version_hascrc(&mp->m_sb))
569 return NULL; 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 return __this_address; 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 return __this_address; 574 return __this_address;
575 /* 575 /*
576 * during growfs operations, the perag is not fully initialised, 576 * during growfs operations, the perag is not fully initialised,
@@ -643,6 +643,7 @@ xfs_agfl_write_verify(
643 643
644const struct xfs_buf_ops xfs_agfl_buf_ops = { 644const struct xfs_buf_ops xfs_agfl_buf_ops = {
645 .name = "xfs_agfl", 645 .name = "xfs_agfl",
646 .magic = { cpu_to_be32(XFS_AGFL_MAGIC), cpu_to_be32(XFS_AGFL_MAGIC) },
646 .verify_read = xfs_agfl_read_verify, 647 .verify_read = xfs_agfl_read_verify,
647 .verify_write = xfs_agfl_write_verify, 648 .verify_write = xfs_agfl_write_verify,
648 .verify_struct = xfs_agfl_verify, 649 .verify_struct = xfs_agfl_verify,
@@ -2587,8 +2588,10 @@ xfs_agf_verify(
2587 return __this_address; 2588 return __this_address;
2588 } 2589 }
2589 2590
2590 if (!(agf->agf_magicnum == cpu_to_be32(XFS_AGF_MAGIC) && 2591 if (!xfs_verify_magic(bp, agf->agf_magicnum))
2591 XFS_AGF_GOOD_VERSION(be32_to_cpu(agf->agf_versionnum)) && 2592 return __this_address;
2593
2594 if (!(XFS_AGF_GOOD_VERSION(be32_to_cpu(agf->agf_versionnum)) &&
2592 be32_to_cpu(agf->agf_freeblks) <= be32_to_cpu(agf->agf_length) && 2595 be32_to_cpu(agf->agf_freeblks) <= be32_to_cpu(agf->agf_length) &&
2593 be32_to_cpu(agf->agf_flfirst) < xfs_agfl_size(mp) && 2596 be32_to_cpu(agf->agf_flfirst) < xfs_agfl_size(mp) &&
2594 be32_to_cpu(agf->agf_fllast) < xfs_agfl_size(mp) && 2597 be32_to_cpu(agf->agf_fllast) < xfs_agfl_size(mp) &&
@@ -2670,6 +2673,7 @@ xfs_agf_write_verify(
2670 2673
2671const struct xfs_buf_ops xfs_agf_buf_ops = { 2674const struct xfs_buf_ops xfs_agf_buf_ops = {
2672 .name = "xfs_agf", 2675 .name = "xfs_agf",
2676 .magic = { cpu_to_be32(XFS_AGF_MAGIC), cpu_to_be32(XFS_AGF_MAGIC) },
2673 .verify_read = xfs_agf_read_verify, 2677 .verify_read = xfs_agf_read_verify,
2674 .verify_write = xfs_agf_write_verify, 2678 .verify_write = xfs_agf_write_verify,
2675 .verify_struct = xfs_agf_verify, 2679 .verify_struct = xfs_agf_verify,
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index e60eba7f129c..f164f296f1b8 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -248,21 +248,18 @@ xfs_attr3_leaf_verify(
248 248
249 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf); 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 if (xfs_sb_version_hascrc(&mp->m_sb)) { 254 if (xfs_sb_version_hascrc(&mp->m_sb)) {
252 struct xfs_da3_node_hdr *hdr3 = bp->b_addr; 255 struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
253 256
254 if (hdr3->info.hdr.magic != cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
255 return __this_address;
256
257 if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) 257 if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid))
258 return __this_address; 258 return __this_address;
259 if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn) 259 if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn)
260 return __this_address; 260 return __this_address;
261 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn))) 261 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn)))
262 return __this_address; 262 return __this_address;
263 } else {
264 if (leaf->hdr.info.magic != cpu_to_be16(XFS_ATTR_LEAF_MAGIC))
265 return __this_address;
266 } 263 }
267 /* 264 /*
268 * In recovery there is a transient state where count == 0 is valid 265 * In recovery there is a transient state where count == 0 is valid
@@ -369,6 +366,8 @@ xfs_attr3_leaf_read_verify(
369 366
370const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = { 367const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = {
371 .name = "xfs_attr3_leaf", 368 .name = "xfs_attr3_leaf",
369 .magic = { cpu_to_be16(XFS_ATTR_LEAF_MAGIC),
370 cpu_to_be16(XFS_ATTR3_LEAF_MAGIC) },
372 .verify_read = xfs_attr3_leaf_read_verify, 371 .verify_read = xfs_attr3_leaf_read_verify,
373 .verify_write = xfs_attr3_leaf_write_verify, 372 .verify_write = xfs_attr3_leaf_write_verify,
374 .verify_struct = xfs_attr3_leaf_verify, 373 .verify_struct = xfs_attr3_leaf_verify,
diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c
index d89363c6b523..65ff600a8067 100644
--- a/fs/xfs/libxfs/xfs_attr_remote.c
+++ b/fs/xfs/libxfs/xfs_attr_remote.c
@@ -79,6 +79,7 @@ xfs_attr3_rmt_hdr_ok(
79static xfs_failaddr_t 79static xfs_failaddr_t
80xfs_attr3_rmt_verify( 80xfs_attr3_rmt_verify(
81 struct xfs_mount *mp, 81 struct xfs_mount *mp,
82 struct xfs_buf *bp,
82 void *ptr, 83 void *ptr,
83 int fsbsize, 84 int fsbsize,
84 xfs_daddr_t bno) 85 xfs_daddr_t bno)
@@ -87,7 +88,7 @@ xfs_attr3_rmt_verify(
87 88
88 if (!xfs_sb_version_hascrc(&mp->m_sb)) 89 if (!xfs_sb_version_hascrc(&mp->m_sb))
89 return __this_address; 90 return __this_address;
90 if (rmt->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC)) 91 if (!xfs_verify_magic(bp, rmt->rm_magic))
91 return __this_address; 92 return __this_address;
92 if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid)) 93 if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid))
93 return __this_address; 94 return __this_address;
@@ -131,7 +132,7 @@ __xfs_attr3_rmt_read_verify(
131 *failaddr = __this_address; 132 *failaddr = __this_address;
132 return -EFSBADCRC; 133 return -EFSBADCRC;
133 } 134 }
134 *failaddr = xfs_attr3_rmt_verify(mp, ptr, blksize, bno); 135 *failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno);
135 if (*failaddr) 136 if (*failaddr)
136 return -EFSCORRUPTED; 137 return -EFSCORRUPTED;
137 len -= blksize; 138 len -= blksize;
@@ -193,7 +194,7 @@ xfs_attr3_rmt_write_verify(
193 while (len > 0) { 194 while (len > 0) {
194 struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; 195 struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr;
195 196
196 fa = xfs_attr3_rmt_verify(mp, ptr, blksize, bno); 197 fa = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno);
197 if (fa) { 198 if (fa) {
198 xfs_verifier_error(bp, -EFSCORRUPTED, fa); 199 xfs_verifier_error(bp, -EFSCORRUPTED, fa);
199 return; 200 return;
@@ -220,6 +221,7 @@ xfs_attr3_rmt_write_verify(
220 221
221const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = { 222const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = {
222 .name = "xfs_attr3_rmt", 223 .name = "xfs_attr3_rmt",
224 .magic = { 0, cpu_to_be32(XFS_ATTR3_RMT_MAGIC) },
223 .verify_read = xfs_attr3_rmt_read_verify, 225 .verify_read = xfs_attr3_rmt_read_verify,
224 .verify_write = xfs_attr3_rmt_write_verify, 226 .verify_write = xfs_attr3_rmt_write_verify,
225 .verify_struct = xfs_attr3_rmt_verify_struct, 227 .verify_struct = xfs_attr3_rmt_verify_struct,
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c
index cdb74d2e2a43..aff82ed112c9 100644
--- a/fs/xfs/libxfs/xfs_bmap_btree.c
+++ b/fs/xfs/libxfs/xfs_bmap_btree.c
@@ -416,8 +416,10 @@ xfs_bmbt_verify(
416 xfs_failaddr_t fa; 416 xfs_failaddr_t fa;
417 unsigned int level; 417 unsigned int level;
418 418
419 switch (block->bb_magic) { 419 if (!xfs_verify_magic(bp, block->bb_magic))
420 case cpu_to_be32(XFS_BMAP_CRC_MAGIC): 420 return __this_address;
421
422 if (xfs_sb_version_hascrc(&mp->m_sb)) {
421 /* 423 /*
422 * XXX: need a better way of verifying the owner here. Right now 424 * XXX: need a better way of verifying the owner here. Right now
423 * just make sure there has been one set. 425 * just make sure there has been one set.
@@ -425,11 +427,6 @@ xfs_bmbt_verify(
425 fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN); 427 fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN);
426 if (fa) 428 if (fa)
427 return fa; 429 return fa;
428 /* fall through */
429 case cpu_to_be32(XFS_BMAP_MAGIC):
430 break;
431 default:
432 return __this_address;
433 } 430 }
434 431
435 /* 432 /*
@@ -481,6 +478,8 @@ xfs_bmbt_write_verify(
481 478
482const struct xfs_buf_ops xfs_bmbt_buf_ops = { 479const struct xfs_buf_ops xfs_bmbt_buf_ops = {
483 .name = "xfs_bmbt", 480 .name = "xfs_bmbt",
481 .magic = { cpu_to_be32(XFS_BMAP_MAGIC),
482 cpu_to_be32(XFS_BMAP_CRC_MAGIC) },
484 .verify_read = xfs_bmbt_read_verify, 483 .verify_read = xfs_bmbt_read_verify,
485 .verify_write = xfs_bmbt_write_verify, 484 .verify_write = xfs_bmbt_write_verify,
486 .verify_struct = xfs_bmbt_verify, 485 .verify_struct = xfs_bmbt_verify,
diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 355322688c9f..e02d2f407e12 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -129,21 +129,18 @@ xfs_da3_node_verify(
129 129
130 ops->node_hdr_from_disk(&ichdr, hdr); 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 if (xfs_sb_version_hascrc(&mp->m_sb)) { 135 if (xfs_sb_version_hascrc(&mp->m_sb)) {
133 struct xfs_da3_node_hdr *hdr3 = bp->b_addr; 136 struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
134 137
135 if (hdr3->info.hdr.magic != cpu_to_be16(XFS_DA3_NODE_MAGIC))
136 return __this_address;
137
138 if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) 138 if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid))
139 return __this_address; 139 return __this_address;
140 if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn) 140 if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn)
141 return __this_address; 141 return __this_address;
142 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn))) 142 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn)))
143 return __this_address; 143 return __this_address;
144 } else {
145 if (hdr->hdr.info.magic != cpu_to_be16(XFS_DA_NODE_MAGIC))
146 return __this_address;
147 } 144 }
148 if (ichdr.level == 0) 145 if (ichdr.level == 0)
149 return __this_address; 146 return __this_address;
@@ -257,6 +254,8 @@ xfs_da3_node_verify_struct(
257 254
258const struct xfs_buf_ops xfs_da3_node_buf_ops = { 255const struct xfs_buf_ops xfs_da3_node_buf_ops = {
259 .name = "xfs_da3_node", 256 .name = "xfs_da3_node",
257 .magic = { cpu_to_be16(XFS_DA_NODE_MAGIC),
258 cpu_to_be16(XFS_DA3_NODE_MAGIC) },
260 .verify_read = xfs_da3_node_read_verify, 259 .verify_read = xfs_da3_node_read_verify,
261 .verify_write = xfs_da3_node_write_verify, 260 .verify_write = xfs_da3_node_write_verify,
262 .verify_struct = xfs_da3_node_verify_struct, 261 .verify_struct = xfs_da3_node_verify_struct,
diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c
index 30ed5919da72..b7d6d78f4ce2 100644
--- a/fs/xfs/libxfs/xfs_dir2_block.c
+++ b/fs/xfs/libxfs/xfs_dir2_block.c
@@ -53,18 +53,16 @@ xfs_dir3_block_verify(
53 struct xfs_mount *mp = bp->b_target->bt_mount; 53 struct xfs_mount *mp = bp->b_target->bt_mount;
54 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; 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 if (xfs_sb_version_hascrc(&mp->m_sb)) { 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 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) 60 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid))
60 return __this_address; 61 return __this_address;
61 if (be64_to_cpu(hdr3->blkno) != bp->b_bn) 62 if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
62 return __this_address; 63 return __this_address;
63 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) 64 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn)))
64 return __this_address; 65 return __this_address;
65 } else {
66 if (hdr3->magic != cpu_to_be32(XFS_DIR2_BLOCK_MAGIC))
67 return __this_address;
68 } 66 }
69 return __xfs_dir3_data_check(NULL, bp); 67 return __xfs_dir3_data_check(NULL, bp);
70} 68}
@@ -112,6 +110,8 @@ xfs_dir3_block_write_verify(
112 110
113const struct xfs_buf_ops xfs_dir3_block_buf_ops = { 111const struct xfs_buf_ops xfs_dir3_block_buf_ops = {
114 .name = "xfs_dir3_block", 112 .name = "xfs_dir3_block",
113 .magic = { cpu_to_be32(XFS_DIR2_BLOCK_MAGIC),
114 cpu_to_be32(XFS_DIR3_BLOCK_MAGIC) },
115 .verify_read = xfs_dir3_block_read_verify, 115 .verify_read = xfs_dir3_block_read_verify,
116 .verify_write = xfs_dir3_block_write_verify, 116 .verify_write = xfs_dir3_block_write_verify,
117 .verify_struct = xfs_dir3_block_verify, 117 .verify_struct = xfs_dir3_block_verify,
diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c
index 01162c62ec8f..b7b9ce002cb9 100644
--- a/fs/xfs/libxfs/xfs_dir2_data.c
+++ b/fs/xfs/libxfs/xfs_dir2_data.c
@@ -252,18 +252,16 @@ xfs_dir3_data_verify(
252 struct xfs_mount *mp = bp->b_target->bt_mount; 252 struct xfs_mount *mp = bp->b_target->bt_mount;
253 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; 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 if (xfs_sb_version_hascrc(&mp->m_sb)) { 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 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) 259 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid))
259 return __this_address; 260 return __this_address;
260 if (be64_to_cpu(hdr3->blkno) != bp->b_bn) 261 if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
261 return __this_address; 262 return __this_address;
262 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) 263 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn)))
263 return __this_address; 264 return __this_address;
264 } else {
265 if (hdr3->magic != cpu_to_be32(XFS_DIR2_DATA_MAGIC))
266 return __this_address;
267 } 265 }
268 return __xfs_dir3_data_check(NULL, bp); 266 return __xfs_dir3_data_check(NULL, bp);
269} 267}
@@ -339,6 +337,8 @@ xfs_dir3_data_write_verify(
339 337
340const struct xfs_buf_ops xfs_dir3_data_buf_ops = { 338const struct xfs_buf_ops xfs_dir3_data_buf_ops = {
341 .name = "xfs_dir3_data", 339 .name = "xfs_dir3_data",
340 .magic = { cpu_to_be32(XFS_DIR2_DATA_MAGIC),
341 cpu_to_be32(XFS_DIR3_DATA_MAGIC) },
342 .verify_read = xfs_dir3_data_read_verify, 342 .verify_read = xfs_dir3_data_read_verify,
343 .verify_write = xfs_dir3_data_write_verify, 343 .verify_write = xfs_dir3_data_write_verify,
344 .verify_struct = xfs_dir3_data_verify, 344 .verify_struct = xfs_dir3_data_verify,
@@ -346,6 +346,8 @@ const struct xfs_buf_ops xfs_dir3_data_buf_ops = {
346 346
347static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = { 347static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = {
348 .name = "xfs_dir3_data_reada", 348 .name = "xfs_dir3_data_reada",
349 .magic = { cpu_to_be32(XFS_DIR2_DATA_MAGIC),
350 cpu_to_be32(XFS_DIR3_DATA_MAGIC) },
349 .verify_read = xfs_dir3_data_reada_verify, 351 .verify_read = xfs_dir3_data_reada_verify,
350 .verify_write = xfs_dir3_data_write_verify, 352 .verify_write = xfs_dir3_data_write_verify,
351}; 353};
diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
index f1bb3434f51c..3b03703c5c3d 100644
--- a/fs/xfs/libxfs/xfs_dir2_node.c
+++ b/fs/xfs/libxfs/xfs_dir2_node.c
@@ -87,20 +87,18 @@ xfs_dir3_free_verify(
87 struct xfs_mount *mp = bp->b_target->bt_mount; 87 struct xfs_mount *mp = bp->b_target->bt_mount;
88 struct xfs_dir2_free_hdr *hdr = bp->b_addr; 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 if (xfs_sb_version_hascrc(&mp->m_sb)) { 93 if (xfs_sb_version_hascrc(&mp->m_sb)) {
91 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; 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 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) 96 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid))
96 return __this_address; 97 return __this_address;
97 if (be64_to_cpu(hdr3->blkno) != bp->b_bn) 98 if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
98 return __this_address; 99 return __this_address;
99 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) 100 if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn)))
100 return __this_address; 101 return __this_address;
101 } else {
102 if (hdr->magic != cpu_to_be32(XFS_DIR2_FREE_MAGIC))
103 return __this_address;
104 } 102 }
105 103
106 /* XXX: should bounds check the xfs_dir3_icfree_hdr here */ 104 /* XXX: should bounds check the xfs_dir3_icfree_hdr here */
@@ -151,6 +149,8 @@ xfs_dir3_free_write_verify(
151 149
152const struct xfs_buf_ops xfs_dir3_free_buf_ops = { 150const struct xfs_buf_ops xfs_dir3_free_buf_ops = {
153 .name = "xfs_dir3_free", 151 .name = "xfs_dir3_free",
152 .magic = { cpu_to_be32(XFS_DIR2_FREE_MAGIC),
153 cpu_to_be32(XFS_DIR3_FREE_MAGIC) },
154 .verify_read = xfs_dir3_free_read_verify, 154 .verify_read = xfs_dir3_free_read_verify,
155 .verify_write = xfs_dir3_free_write_verify, 155 .verify_write = xfs_dir3_free_write_verify,
156 .verify_struct = xfs_dir3_free_verify, 156 .verify_struct = xfs_dir3_free_verify,
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index d32152fc8a6c..fe9898875097 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -2508,7 +2508,7 @@ xfs_agi_verify(
2508 /* 2508 /*
2509 * Validate the magic number of the agi block. 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 return __this_address; 2512 return __this_address;
2513 if (!XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum))) 2513 if (!XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum)))
2514 return __this_address; 2514 return __this_address;
@@ -2582,6 +2582,7 @@ xfs_agi_write_verify(
2582 2582
2583const struct xfs_buf_ops xfs_agi_buf_ops = { 2583const struct xfs_buf_ops xfs_agi_buf_ops = {
2584 .name = "xfs_agi", 2584 .name = "xfs_agi",
2585 .magic = { cpu_to_be32(XFS_AGI_MAGIC), cpu_to_be32(XFS_AGI_MAGIC) },
2585 .verify_read = xfs_agi_read_verify, 2586 .verify_read = xfs_agi_read_verify,
2586 .verify_write = xfs_agi_write_verify, 2587 .verify_write = xfs_agi_write_verify,
2587 .verify_struct = xfs_agi_verify, 2588 .verify_struct = xfs_agi_verify,
diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcount_btree.c
index d9eab657b63e..6f47ab876d90 100644
--- a/fs/xfs/libxfs/xfs_refcount_btree.c
+++ b/fs/xfs/libxfs/xfs_refcount_btree.c
@@ -209,7 +209,7 @@ xfs_refcountbt_verify(
209 xfs_failaddr_t fa; 209 xfs_failaddr_t fa;
210 unsigned int level; 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 return __this_address; 213 return __this_address;
214 214
215 if (!xfs_sb_version_hasreflink(&mp->m_sb)) 215 if (!xfs_sb_version_hasreflink(&mp->m_sb))
@@ -264,6 +264,7 @@ xfs_refcountbt_write_verify(
264 264
265const struct xfs_buf_ops xfs_refcountbt_buf_ops = { 265const struct xfs_buf_ops xfs_refcountbt_buf_ops = {
266 .name = "xfs_refcountbt", 266 .name = "xfs_refcountbt",
267 .magic = { 0, cpu_to_be32(XFS_REFC_CRC_MAGIC) },
267 .verify_read = xfs_refcountbt_read_verify, 268 .verify_read = xfs_refcountbt_read_verify,
268 .verify_write = xfs_refcountbt_write_verify, 269 .verify_write = xfs_refcountbt_write_verify,
269 .verify_struct = xfs_refcountbt_verify, 270 .verify_struct = xfs_refcountbt_verify,
diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c
index f79cf040d745..5738e11055e6 100644
--- a/fs/xfs/libxfs/xfs_rmap_btree.c
+++ b/fs/xfs/libxfs/xfs_rmap_btree.c
@@ -310,7 +310,7 @@ xfs_rmapbt_verify(
310 * from the on disk AGF. Again, we can only check against maximum limits 310 * from the on disk AGF. Again, we can only check against maximum limits
311 * in this case. 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 return __this_address; 314 return __this_address;
315 315
316 if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) 316 if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
@@ -365,6 +365,7 @@ xfs_rmapbt_write_verify(
365 365
366const struct xfs_buf_ops xfs_rmapbt_buf_ops = { 366const struct xfs_buf_ops xfs_rmapbt_buf_ops = {
367 .name = "xfs_rmapbt", 367 .name = "xfs_rmapbt",
368 .magic = { 0, cpu_to_be32(XFS_RMAP_CRC_MAGIC) },
368 .verify_read = xfs_rmapbt_read_verify, 369 .verify_read = xfs_rmapbt_read_verify,
369 .verify_write = xfs_rmapbt_write_verify, 370 .verify_write = xfs_rmapbt_write_verify,
370 .verify_struct = xfs_rmapbt_verify, 371 .verify_struct = xfs_rmapbt_verify,
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index a2f52a958091..4e5029c37966 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -229,7 +229,7 @@ xfs_validate_sb_common(
229 uint32_t agcount = 0; 229 uint32_t agcount = 0;
230 uint32_t rem; 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 xfs_warn(mp, "bad magic number"); 233 xfs_warn(mp, "bad magic number");
234 return -EWRONGFS; 234 return -EWRONGFS;
235 } 235 }
@@ -782,12 +782,14 @@ out_error:
782 782
783const struct xfs_buf_ops xfs_sb_buf_ops = { 783const struct xfs_buf_ops xfs_sb_buf_ops = {
784 .name = "xfs_sb", 784 .name = "xfs_sb",
785 .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
785 .verify_read = xfs_sb_read_verify, 786 .verify_read = xfs_sb_read_verify,
786 .verify_write = xfs_sb_write_verify, 787 .verify_write = xfs_sb_write_verify,
787}; 788};
788 789
789const struct xfs_buf_ops xfs_sb_quiet_buf_ops = { 790const struct xfs_buf_ops xfs_sb_quiet_buf_ops = {
790 .name = "xfs_sb_quiet", 791 .name = "xfs_sb_quiet",
792 .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
791 .verify_read = xfs_sb_quiet_read_verify, 793 .verify_read = xfs_sb_quiet_read_verify,
792 .verify_write = xfs_sb_write_verify, 794 .verify_write = xfs_sb_write_verify,
793}; 795};
diff --git a/fs/xfs/libxfs/xfs_symlink_remote.c b/fs/xfs/libxfs/xfs_symlink_remote.c
index 77d80106f989..a0ccc253c43d 100644
--- a/fs/xfs/libxfs/xfs_symlink_remote.c
+++ b/fs/xfs/libxfs/xfs_symlink_remote.c
@@ -95,7 +95,7 @@ xfs_symlink_verify(
95 95
96 if (!xfs_sb_version_hascrc(&mp->m_sb)) 96 if (!xfs_sb_version_hascrc(&mp->m_sb))
97 return __this_address; 97 return __this_address;
98 if (dsl->sl_magic != cpu_to_be32(XFS_SYMLINK_MAGIC)) 98 if (!xfs_verify_magic(bp, dsl->sl_magic))
99 return __this_address; 99 return __this_address;
100 if (!uuid_equal(&dsl->sl_uuid, &mp->m_sb.sb_meta_uuid)) 100 if (!uuid_equal(&dsl->sl_uuid, &mp->m_sb.sb_meta_uuid))
101 return __this_address; 101 return __this_address;
@@ -159,6 +159,7 @@ xfs_symlink_write_verify(
159 159
160const struct xfs_buf_ops xfs_symlink_buf_ops = { 160const struct xfs_buf_ops xfs_symlink_buf_ops = {
161 .name = "xfs_symlink", 161 .name = "xfs_symlink",
162 .magic = { 0, cpu_to_be32(XFS_SYMLINK_MAGIC) },
162 .verify_read = xfs_symlink_read_verify, 163 .verify_read = xfs_symlink_read_verify,
163 .verify_write = xfs_symlink_write_verify, 164 .verify_write = xfs_symlink_write_verify,
164 .verify_struct = xfs_symlink_verify, 165 .verify_struct = xfs_symlink_verify,