Skip to content

Commit

Permalink
xfs: Fix possible null-pointer dereferences in xchk_da_btree_block_ch…
Browse files Browse the repository at this point in the history
…eck_sibling()

In xchk_da_btree_block_check_sibling(), there is an if statement on
line 274 to check whether ds->state->altpath.blk[level].bp is NULL:
    if (ds->state->altpath.blk[level].bp)

When ds->state->altpath.blk[level].bp is NULL, it is used on line 281:
    xfs_trans_brelse(..., ds->state->altpath.blk[level].bp);
        struct xfs_buf_log_item *bip = bp->b_log_item;
        ASSERT(bp->b_transp == tp);

Thus, possible null-pointer dereferences may occur.

To fix these bugs, ds->state->altpath.blk[level].bp is checked before
being used.

These bugs are found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
  • Loading branch information
XidianGeneral authored and djwong committed Jul 30, 2019
1 parent 2e616d9 commit afa1d96
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/xfs/scrub/dabtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ xchk_da_btree_block_check_sibling(
/* Compare upper level pointer to sibling pointer. */
if (ds->state->altpath.blk[level].blkno != sibling)
xchk_da_set_corrupt(ds, level);
xfs_trans_brelse(ds->dargs.trans, ds->state->altpath.blk[level].bp);
if (ds->state->altpath.blk[level].bp) {
xfs_trans_brelse(ds->dargs.trans,
ds->state->altpath.blk[level].bp);
ds->state->altpath.blk[level].bp = NULL;
}
out:
return error;
}
Expand Down

0 comments on commit afa1d96

Please sign in to comment.