Skip to content

Commit 6b48e5b

Browse files
committed
xfs: directory scrub should check the null bestfree entries too
Teach the directory scrubber to check all the bestfree entries, including the null ones. We want to be able to detect the case where the entry is null but there actually /is/ a directory data block. Found by fuzzing lbests[0] = ones in xfs/391. Fixes: df48196 ("xfs: scrub directory freespace") Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 498fe26 commit 6b48e5b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

fs/xfs/scrub/dir.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,27 @@ xchk_directory_leaf1_bestfree(
558558
/* Check all the bestfree entries. */
559559
for (i = 0; i < bestcount; i++, bestp++) {
560560
best = be16_to_cpu(*bestp);
561-
if (best == NULLDATAOFF)
562-
continue;
563561
error = xfs_dir3_data_read(sc->tp, sc->ip,
564-
i * args->geo->fsbcount, 0, &dbp);
562+
xfs_dir2_db_to_da(args->geo, i),
563+
XFS_DABUF_MAP_HOLE_OK,
564+
&dbp);
565565
if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, lblk,
566566
&error))
567567
break;
568-
xchk_directory_check_freesp(sc, lblk, dbp, best);
568+
569+
if (!dbp) {
570+
if (best != NULLDATAOFF) {
571+
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK,
572+
lblk);
573+
break;
574+
}
575+
continue;
576+
}
577+
578+
if (best == NULLDATAOFF)
579+
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk);
580+
else
581+
xchk_directory_check_freesp(sc, lblk, dbp, best);
569582
xfs_trans_brelse(sc->tp, dbp);
570583
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
571584
break;

0 commit comments

Comments
 (0)