Commit cf1b0b8b authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: scrub in-core metadata

Whenever we load a buffer, explicitly re-call the structure verifier to
ensure that memory isn't corrupting things.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 561f648a
...@@ -611,6 +611,7 @@ xfs_scrub_agf( ...@@ -611,6 +611,7 @@ xfs_scrub_agf(
&sc->sa.agf_bp, &sc->sa.agfl_bp); &sc->sa.agf_bp, &sc->sa.agfl_bp);
if (!xfs_scrub_process_error(sc, agno, XFS_AGF_BLOCK(sc->mp), &error)) if (!xfs_scrub_process_error(sc, agno, XFS_AGF_BLOCK(sc->mp), &error))
goto out; goto out;
xfs_scrub_buffer_recheck(sc, sc->sa.agf_bp);
agf = XFS_BUF_TO_AGF(sc->sa.agf_bp); agf = XFS_BUF_TO_AGF(sc->sa.agf_bp);
...@@ -780,6 +781,7 @@ xfs_scrub_agfl( ...@@ -780,6 +781,7 @@ xfs_scrub_agfl(
goto out; goto out;
if (!sc->sa.agf_bp) if (!sc->sa.agf_bp)
return -EFSCORRUPTED; return -EFSCORRUPTED;
xfs_scrub_buffer_recheck(sc, sc->sa.agfl_bp);
xfs_scrub_agfl_xref(sc); xfs_scrub_agfl_xref(sc);
...@@ -902,6 +904,7 @@ xfs_scrub_agi( ...@@ -902,6 +904,7 @@ xfs_scrub_agi(
&sc->sa.agf_bp, &sc->sa.agfl_bp); &sc->sa.agf_bp, &sc->sa.agfl_bp);
if (!xfs_scrub_process_error(sc, agno, XFS_AGI_BLOCK(sc->mp), &error)) if (!xfs_scrub_process_error(sc, agno, XFS_AGI_BLOCK(sc->mp), &error))
goto out; goto out;
xfs_scrub_buffer_recheck(sc, sc->sa.agi_bp);
agi = XFS_BUF_TO_AGI(sc->sa.agi_bp); agi = XFS_BUF_TO_AGI(sc->sa.agi_bp);
......
...@@ -314,6 +314,8 @@ xfs_scrub_btree_block_check_sibling( ...@@ -314,6 +314,8 @@ xfs_scrub_btree_block_check_sibling(
pp = xfs_btree_ptr_addr(ncur, ncur->bc_ptrs[level + 1], pblock); pp = xfs_btree_ptr_addr(ncur, ncur->bc_ptrs[level + 1], pblock);
if (!xfs_scrub_btree_ptr_ok(bs, level + 1, pp)) if (!xfs_scrub_btree_ptr_ok(bs, level + 1, pp))
goto out; goto out;
if (pbp)
xfs_scrub_buffer_recheck(bs->sc, pbp);
if (xfs_btree_diff_two_ptrs(cur, pp, sibling)) if (xfs_btree_diff_two_ptrs(cur, pp, sibling))
xfs_scrub_btree_set_corrupt(bs->sc, cur, level); xfs_scrub_btree_set_corrupt(bs->sc, cur, level);
...@@ -486,6 +488,8 @@ xfs_scrub_btree_get_block( ...@@ -486,6 +488,8 @@ xfs_scrub_btree_get_block(
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, level); xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, level);
return 0; return 0;
} }
if (*pbp)
xfs_scrub_buffer_recheck(bs->sc, *pbp);
/* /*
* Check the block's owner; this function absorbs error codes * Check the block's owner; this function absorbs error codes
......
...@@ -756,3 +756,26 @@ xfs_scrub_should_check_xref( ...@@ -756,3 +756,26 @@ xfs_scrub_should_check_xref(
*error = 0; *error = 0;
return false; return false;
} }
/* Run the structure verifiers on in-memory buffers to detect bad memory. */
void
xfs_scrub_buffer_recheck(
struct xfs_scrub_context *sc,
struct xfs_buf *bp)
{
xfs_failaddr_t fa;
if (bp->b_ops == NULL) {
xfs_scrub_block_set_corrupt(sc, bp);
return;
}
if (bp->b_ops->verify_struct == NULL) {
xfs_scrub_set_incomplete(sc);
return;
}
fa = bp->b_ops->verify_struct(bp);
if (!fa)
return;
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
trace_xfs_scrub_block_error(sc, bp->b_bn, fa);
}
...@@ -158,5 +158,6 @@ int xfs_scrub_setup_ag_btree(struct xfs_scrub_context *sc, ...@@ -158,5 +158,6 @@ int xfs_scrub_setup_ag_btree(struct xfs_scrub_context *sc,
int xfs_scrub_get_inode(struct xfs_scrub_context *sc, struct xfs_inode *ip_in); int xfs_scrub_get_inode(struct xfs_scrub_context *sc, struct xfs_inode *ip_in);
int xfs_scrub_setup_inode_contents(struct xfs_scrub_context *sc, int xfs_scrub_setup_inode_contents(struct xfs_scrub_context *sc,
struct xfs_inode *ip, unsigned int resblks); struct xfs_inode *ip, unsigned int resblks);
void xfs_scrub_buffer_recheck(struct xfs_scrub_context *sc, struct xfs_buf *bp);
#endif /* __XFS_SCRUB_COMMON_H__ */ #endif /* __XFS_SCRUB_COMMON_H__ */
...@@ -233,11 +233,28 @@ xfs_scrub_da_btree_write_verify( ...@@ -233,11 +233,28 @@ xfs_scrub_da_btree_write_verify(
return; return;
} }
} }
static void *
xfs_scrub_da_btree_verify(
struct xfs_buf *bp)
{
struct xfs_da_blkinfo *info = bp->b_addr;
switch (be16_to_cpu(info->magic)) {
case XFS_DIR2_LEAF1_MAGIC:
case XFS_DIR3_LEAF1_MAGIC:
bp->b_ops = &xfs_dir3_leaf1_buf_ops;
return bp->b_ops->verify_struct(bp);
default:
bp->b_ops = &xfs_da3_node_buf_ops;
return bp->b_ops->verify_struct(bp);
}
}
static const struct xfs_buf_ops xfs_scrub_da_btree_buf_ops = { static const struct xfs_buf_ops xfs_scrub_da_btree_buf_ops = {
.name = "xfs_scrub_da_btree", .name = "xfs_scrub_da_btree",
.verify_read = xfs_scrub_da_btree_read_verify, .verify_read = xfs_scrub_da_btree_read_verify,
.verify_write = xfs_scrub_da_btree_write_verify, .verify_write = xfs_scrub_da_btree_write_verify,
.verify_struct = xfs_scrub_da_btree_verify,
}; };
/* Check a block's sibling. */ /* Check a block's sibling. */
...@@ -276,6 +293,9 @@ xfs_scrub_da_btree_block_check_sibling( ...@@ -276,6 +293,9 @@ xfs_scrub_da_btree_block_check_sibling(
xfs_scrub_da_set_corrupt(ds, level); xfs_scrub_da_set_corrupt(ds, level);
return error; return error;
} }
if (ds->state->altpath.blk[level].bp)
xfs_scrub_buffer_recheck(ds->sc,
ds->state->altpath.blk[level].bp);
/* Compare upper level pointer to sibling pointer. */ /* Compare upper level pointer to sibling pointer. */
if (ds->state->altpath.blk[level].blkno != sibling) if (ds->state->altpath.blk[level].blkno != sibling)
...@@ -358,6 +378,8 @@ xfs_scrub_da_btree_block( ...@@ -358,6 +378,8 @@ xfs_scrub_da_btree_block(
&xfs_scrub_da_btree_buf_ops); &xfs_scrub_da_btree_buf_ops);
if (!xfs_scrub_da_process_error(ds, level, &error)) if (!xfs_scrub_da_process_error(ds, level, &error))
goto out_nobuf; goto out_nobuf;
if (blk->bp)
xfs_scrub_buffer_recheck(ds->sc, blk->bp);
/* /*
* We didn't find a dir btree root block, which means that * We didn't find a dir btree root block, which means that
......
...@@ -237,6 +237,7 @@ xfs_scrub_dir_rec( ...@@ -237,6 +237,7 @@ xfs_scrub_dir_rec(
xfs_scrub_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); xfs_scrub_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno);
goto out; goto out;
} }
xfs_scrub_buffer_recheck(ds->sc, bp);
/* Retrieve the entry, sanity check it, and compare hashes. */ /* Retrieve the entry, sanity check it, and compare hashes. */
dent = (struct xfs_dir2_data_entry *)(((char *)bp->b_addr) + off); dent = (struct xfs_dir2_data_entry *)(((char *)bp->b_addr) + off);
...@@ -324,6 +325,7 @@ xfs_scrub_directory_data_bestfree( ...@@ -324,6 +325,7 @@ xfs_scrub_directory_data_bestfree(
} }
if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error)) if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error))
goto out; goto out;
xfs_scrub_buffer_recheck(sc, bp);
/* XXX: Check xfs_dir3_data_hdr.pad is zero once we start setting it. */ /* XXX: Check xfs_dir3_data_hdr.pad is zero once we start setting it. */
...@@ -474,6 +476,7 @@ xfs_scrub_directory_leaf1_bestfree( ...@@ -474,6 +476,7 @@ xfs_scrub_directory_leaf1_bestfree(
error = xfs_dir3_leaf_read(sc->tp, sc->ip, lblk, -1, &bp); error = xfs_dir3_leaf_read(sc->tp, sc->ip, lblk, -1, &bp);
if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error)) if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error))
goto out; goto out;
xfs_scrub_buffer_recheck(sc, bp);
leaf = bp->b_addr; leaf = bp->b_addr;
d_ops->leaf_hdr_from_disk(&leafhdr, leaf); d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
...@@ -559,6 +562,7 @@ xfs_scrub_directory_free_bestfree( ...@@ -559,6 +562,7 @@ xfs_scrub_directory_free_bestfree(
error = xfs_dir2_free_read(sc->tp, sc->ip, lblk, &bp); error = xfs_dir2_free_read(sc->tp, sc->ip, lblk, &bp);
if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error)) if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error))
goto out; goto out;
xfs_scrub_buffer_recheck(sc, bp);
if (xfs_sb_version_hascrc(&sc->mp->m_sb)) { if (xfs_sb_version_hascrc(&sc->mp->m_sb)) {
struct xfs_dir3_free_hdr *hdr3 = bp->b_addr; struct xfs_dir3_free_hdr *hdr3 = bp->b_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment