Skip to content

Commit 31723c9

Browse files
adam900710kdave
authored andcommitted
btrfs: tree-checker: reject BTRFS_FT_UNKNOWN dir type
[REPORT] There is a bug report that kernel is rejecting a mismatching inode mode and its dir item: [ 1881.553937] BTRFS critical (device dm-0): inode mode mismatch with dir: inode mode=040700 btrfs type=2 dir type=0 [CAUSE] It looks like the inode mode is correct, while the dir item type 0 is BTRFS_FT_UNKNOWN, which should not be generated by btrfs at all. This may be caused by a memory bit flip. [ENHANCEMENT] Although tree-checker is not able to do any cross-leaf verification, for this particular case we can at least reject any dir type with BTRFS_FT_UNKNOWN. So here we enhance the dir type check from [0, BTRFS_FT_MAX), to (0, BTRFS_FT_MAX). Although the existing corruption can not be fixed just by such enhanced checking, it should prevent the same 0x2->0x0 bitflip for dir type to reach disk in the future. Reported-by: Kota <[email protected]> Link: https://lore.kernel.org/linux-btrfs/CACsxjPYnQF9ZF-0OhH16dAx50=BXXOcP74MxBc3BG+xae4vTTw@mail.gmail.com/ CC: [email protected] # 5.4+ Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 42fac18 commit 31723c9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/btrfs/tree-checker.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,10 @@ static int check_dir_item(struct extent_buffer *leaf,
569569

570570
/* dir type check */
571571
dir_type = btrfs_dir_ftype(leaf, di);
572-
if (unlikely(dir_type >= BTRFS_FT_MAX)) {
572+
if (unlikely(dir_type <= BTRFS_FT_UNKNOWN ||
573+
dir_type >= BTRFS_FT_MAX)) {
573574
dir_item_err(leaf, slot,
574-
"invalid dir item type, have %u expect [0, %u)",
575+
"invalid dir item type, have %u expect (0, %u)",
575576
dir_type, BTRFS_FT_MAX);
576577
return -EUCLEAN;
577578
}

0 commit comments

Comments
 (0)