Commit 361e8213 authored by Liu Bo's avatar Liu Bo Committed by Greg Kroah-Hartman

Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty

commit ef85b25e upstream.

This can only happen with CONFIG_BTRFS_FS_CHECK_INTEGRITY=y.

Commit 1ba98d08 ("Btrfs: detect corruption when non-root leaf has zero item")
assumes that a leaf is its root when leaf->bytenr == btrfs_root_bytenr(root),
however, we should not use btrfs_root_bytenr(root) since it's mainly got
updated during committing transaction.  So the check can fail when doing
COW on this leaf while it is a root.

This changes to use "if (leaf == btrfs_root_node(root))" instead, just like
how we check whether leaf is a root in __btrfs_cow_block().

Fixes: 1ba98d08 (Btrfs: detect corruption when non-root leaf has zero item)
Reported-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 562de9c7
...@@ -572,13 +572,17 @@ static noinline int check_leaf(struct btrfs_root *root, ...@@ -572,13 +572,17 @@ static noinline int check_leaf(struct btrfs_root *root,
* open_ctree() some roots has not yet been set up. * open_ctree() some roots has not yet been set up.
*/ */
if (!IS_ERR_OR_NULL(check_root)) { if (!IS_ERR_OR_NULL(check_root)) {
struct extent_buffer *eb;
eb = btrfs_root_node(check_root);
/* if leaf is the root, then it's fine */ /* if leaf is the root, then it's fine */
if (leaf->start != if (leaf != eb) {
btrfs_root_bytenr(&check_root->root_item)) {
CORRUPT("non-root leaf's nritems is 0", CORRUPT("non-root leaf's nritems is 0",
leaf, root, 0); leaf, check_root, 0);
free_extent_buffer(eb);
return -EIO; return -EIO;
} }
free_extent_buffer(eb);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment