xfs: scrub in-core metadata
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 17 Jan 2018 02:53:11 +0000 (18:53 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Thu, 18 Jan 2018 05:00:46 +0000 (21:00 -0800)
Whenever we load a buffer, explicitly re-call the structure verifier to
ensure that memory isn't corrupting things.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/scrub/agheader.c
fs/xfs/scrub/btree.c
fs/xfs/scrub/common.c
fs/xfs/scrub/common.h
fs/xfs/scrub/dabtree.c
fs/xfs/scrub/dir.c

index 20a3bebdee0662f93f08bfd8e4d0ac1d19b401b9..fd975524f4603387e28078d13b175b5df2443021 100644 (file)
@@ -611,6 +611,7 @@ xfs_scrub_agf(
                        &sc->sa.agf_bp, &sc->sa.agfl_bp);
        if (!xfs_scrub_process_error(sc, agno, XFS_AGF_BLOCK(sc->mp), &error))
                goto out;
+       xfs_scrub_buffer_recheck(sc, sc->sa.agf_bp);
 
        agf = XFS_BUF_TO_AGF(sc->sa.agf_bp);
 
@@ -780,6 +781,7 @@ xfs_scrub_agfl(
                goto out;
        if (!sc->sa.agf_bp)
                return -EFSCORRUPTED;
+       xfs_scrub_buffer_recheck(sc, sc->sa.agfl_bp);
 
        xfs_scrub_agfl_xref(sc);
 
@@ -902,6 +904,7 @@ xfs_scrub_agi(
                        &sc->sa.agf_bp, &sc->sa.agfl_bp);
        if (!xfs_scrub_process_error(sc, agno, XFS_AGI_BLOCK(sc->mp), &error))
                goto out;
+       xfs_scrub_buffer_recheck(sc, sc->sa.agi_bp);
 
        agi = XFS_BUF_TO_AGI(sc->sa.agi_bp);
 
index 0589d4efbf6b696ce35ea5acceb14f2a97b41dbc..54218168c8f969f06f26acb6520647a6621fb1b8 100644 (file)
@@ -314,6 +314,8 @@ xfs_scrub_btree_block_check_sibling(
        pp = xfs_btree_ptr_addr(ncur, ncur->bc_ptrs[level + 1], pblock);
        if (!xfs_scrub_btree_ptr_ok(bs, level + 1, pp))
                goto out;
+       if (pbp)
+               xfs_scrub_buffer_recheck(bs->sc, pbp);
 
        if (xfs_btree_diff_two_ptrs(cur, pp, sibling))
                xfs_scrub_btree_set_corrupt(bs->sc, cur, level);
@@ -486,6 +488,8 @@ xfs_scrub_btree_get_block(
                xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, level);
                return 0;
        }
+       if (*pbp)
+               xfs_scrub_buffer_recheck(bs->sc, *pbp);
 
        /*
         * Check the block's owner; this function absorbs error codes
index f5df8f2859d74b139b8f0dcf24dabf2bf21a2e73..8033ab9d8f47d51f63e64ac168f3a9ac82d23055 100644 (file)
@@ -756,3 +756,26 @@ xfs_scrub_should_check_xref(
        *error = 0;
        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);
+}
index bf88a677f6e7dc693cd74b05f8c057b3381b752c..ddb65d22c76acdf4ad447164efa2ffc2c66c76c5 100644 (file)
@@ -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_setup_inode_contents(struct xfs_scrub_context *sc,
                                   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__ */
index d94edd93cba833b602da7dfc3f510161d6cd62b9..bffdb7dc09bf8db89b9702013bfbdbe614b6cf8b 100644 (file)
@@ -233,11 +233,28 @@ xfs_scrub_da_btree_write_verify(
                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 = {
        .name = "xfs_scrub_da_btree",
        .verify_read = xfs_scrub_da_btree_read_verify,
        .verify_write = xfs_scrub_da_btree_write_verify,
+       .verify_struct = xfs_scrub_da_btree_verify,
 };
 
 /* Check a block's sibling. */
@@ -276,6 +293,9 @@ xfs_scrub_da_btree_block_check_sibling(
                xfs_scrub_da_set_corrupt(ds, level);
                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. */
        if (ds->state->altpath.blk[level].blkno != sibling)
@@ -358,6 +378,8 @@ xfs_scrub_da_btree_block(
                        &xfs_scrub_da_btree_buf_ops);
        if (!xfs_scrub_da_process_error(ds, level, &error))
                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
index e75826bb6516e1dedb3e0cc7c35a255c961e077e..f5a0d179eac04dfc15ae672bc559656b65c231e1 100644 (file)
@@ -237,6 +237,7 @@ xfs_scrub_dir_rec(
                xfs_scrub_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno);
                goto out;
        }
+       xfs_scrub_buffer_recheck(ds->sc, bp);
 
        /* Retrieve the entry, sanity check it, and compare hashes. */
        dent = (struct xfs_dir2_data_entry *)(((char *)bp->b_addr) + off);
@@ -324,6 +325,7 @@ xfs_scrub_directory_data_bestfree(
        }
        if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error))
                goto out;
+       xfs_scrub_buffer_recheck(sc, bp);
 
        /* XXX: Check xfs_dir3_data_hdr.pad is zero once we start setting it. */
 
@@ -474,6 +476,7 @@ xfs_scrub_directory_leaf1_bestfree(
        error = xfs_dir3_leaf_read(sc->tp, sc->ip, lblk, -1, &bp);
        if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error))
                goto out;
+       xfs_scrub_buffer_recheck(sc, bp);
 
        leaf = bp->b_addr;
        d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
@@ -559,6 +562,7 @@ xfs_scrub_directory_free_bestfree(
        error = xfs_dir2_free_read(sc->tp, sc->ip, lblk, &bp);
        if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error))
                goto out;
+       xfs_scrub_buffer_recheck(sc, bp);
 
        if (xfs_sb_version_hascrc(&sc->mp->m_sb)) {
                struct xfs_dir3_free_hdr        *hdr3 = bp->b_addr;