aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2016-09-02 15:35:34 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-06 04:40:10 -0500
commit7d470f04e36c6a23838e9bb384535b7c61fe372c (patch)
treef1a7c4286abcdb7cf9aeeed696991d50f2f7ab7c /fs/btrfs/disk-io.c
parent3bac322e18c3c5f3fc1d77ab0db1fca2e3b7cb03 (diff)
Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
commit ef85b25e982b5bba1530b936e283ef129f02ab9d upstream. 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: 1ba98d086fe3 (Btrfs: detect corruption when non-root leaf has zero item) Reported-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3a57f99d96aa..c4e673a94426 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -572,13 +572,17 @@ static noinline int check_leaf(struct btrfs_root *root,
572 * open_ctree() some roots has not yet been set up. 572 * open_ctree() some roots has not yet been set up.
573 */ 573 */
574 if (!IS_ERR_OR_NULL(check_root)) { 574 if (!IS_ERR_OR_NULL(check_root)) {
575 struct extent_buffer *eb;
576
577 eb = btrfs_root_node(check_root);
575 /* if leaf is the root, then it's fine */ 578 /* if leaf is the root, then it's fine */
576 if (leaf->start != 579 if (leaf != eb) {
577 btrfs_root_bytenr(&check_root->root_item)) {
578 CORRUPT("non-root leaf's nritems is 0", 580 CORRUPT("non-root leaf's nritems is 0",
579 leaf, root, 0); 581 leaf, check_root, 0);
582 free_extent_buffer(eb);
580 return -EIO; 583 return -EIO;
581 } 584 }
585 free_extent_buffer(eb);
582 } 586 }
583 return 0; 587 return 0;
584 } 588 }