Skip to content

Commit ef85b25

Browse files
Liu Bofdmanana
authored andcommitted
Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
This can only happen with CONFIG_BTRFS_FS_CHECK_INTEGRITY=y. Commit 1ba98d0 ("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: 1ba98d0 (Btrfs: detect corruption when non-root leaf has zero item) Cc: [email protected] # 4.8+ Reported-by: Jeff Mahoney <[email protected]> Signed-off-by: Liu Bo <[email protected]> Reviewed-by: Filipe Manana <[email protected]>
1 parent 2a2a83d commit ef85b25

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/btrfs/disk-io.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,17 @@ static noinline int check_leaf(struct btrfs_root *root,
572572
* open_ctree() some roots has not yet been set up.
573573
*/
574574
if (!IS_ERR_OR_NULL(check_root)) {
575+
struct extent_buffer *eb;
576+
577+
eb = btrfs_root_node(check_root);
575578
/* if leaf is the root, then it's fine */
576-
if (leaf->start !=
577-
btrfs_root_bytenr(&check_root->root_item)) {
579+
if (leaf != eb) {
578580
CORRUPT("non-root leaf's nritems is 0",
579-
leaf, root, 0);
581+
leaf, check_root, 0);
582+
free_extent_buffer(eb);
580583
return -EIO;
581584
}
585+
free_extent_buffer(eb);
582586
}
583587
return 0;
584588
}

0 commit comments

Comments
 (0)