diff options
author | Liu Bo <bo.li.liu@oracle.com> | 2016-08-23 18:22:58 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2016-08-25 06:58:31 -0400 |
commit | 1ba98d086fe3a14d6a31f2f66dbab70c45d00f63 (patch) | |
tree | c521349d7730ec47b60fe78a63822123c0fcf87d /fs/btrfs/disk-io.c | |
parent | 053ab70f0604224c7893b43f9d9d5efa283580d6 (diff) |
Btrfs: detect corruption when non-root leaf has zero item
Right now we treat leaf which has zero item as a valid one
because we could have an empty tree, that is, a root that is
also a leaf without any item, however, in the same case but
when the leaf is not a root, we can end up with hitting the
BUG_ON(1) in btrfs_extend_item() called by
setup_inline_extent_backref().
This makes us check the situation as a corruption if leaf is
not its own root.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 474209f50844..70e76ad11fbf 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -560,8 +560,29 @@ static noinline int check_leaf(struct btrfs_root *root, | |||
560 | u32 nritems = btrfs_header_nritems(leaf); | 560 | u32 nritems = btrfs_header_nritems(leaf); |
561 | int slot; | 561 | int slot; |
562 | 562 | ||
563 | if (nritems == 0) | 563 | if (nritems == 0) { |
564 | struct btrfs_root *check_root; | ||
565 | |||
566 | key.objectid = btrfs_header_owner(leaf); | ||
567 | key.type = BTRFS_ROOT_ITEM_KEY; | ||
568 | key.offset = (u64)-1; | ||
569 | |||
570 | check_root = btrfs_get_fs_root(root->fs_info, &key, false); | ||
571 | /* | ||
572 | * The only reason we also check NULL here is that during | ||
573 | * open_ctree() some roots has not yet been set up. | ||
574 | */ | ||
575 | if (!IS_ERR_OR_NULL(check_root)) { | ||
576 | /* if leaf is the root, then it's fine */ | ||
577 | if (leaf->start != | ||
578 | btrfs_root_bytenr(&check_root->root_item)) { | ||
579 | CORRUPT("non-root leaf's nritems is 0", | ||
580 | leaf, root, 0); | ||
581 | return -EIO; | ||
582 | } | ||
583 | } | ||
564 | return 0; | 584 | return 0; |
585 | } | ||
565 | 586 | ||
566 | /* Check the 0 item */ | 587 | /* Check the 0 item */ |
567 | if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) != | 588 | if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) != |