All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
@ 2016-11-23 21:58 Liu Bo
  2016-11-24  9:56 ` Filipe Manana
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Bo @ 2016-11-23 21:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba, Filipe Manana, Jeff Mahoney

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)
Cc: stable@vger.kernel.org  # 4.8+
Reported-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
v2: Tag itself for stable.

 fs/btrfs/disk-io.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 9367c31..b401e6d 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,
 		 * open_ctree() some roots has not yet been set up.
 		 */
 		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->start !=
-			    btrfs_root_bytenr(&check_root->root_item)) {
+			if (leaf != eb) {
 				CORRUPT("non-root leaf's nritems is 0",
-					leaf, root, 0);
+					leaf, check_root, 0);
+				free_extent_buffer(eb);
 				return -EIO;
 			}
+			free_extent_buffer(eb);
 		}
 		return 0;
 	}
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
  2016-11-23 21:58 [PATCH v2] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty Liu Bo
@ 2016-11-24  9:56 ` Filipe Manana
  0 siblings, 0 replies; 2+ messages in thread
From: Filipe Manana @ 2016-11-24  9:56 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs, David Sterba, Filipe Manana, Jeff Mahoney

On Wed, Nov 23, 2016 at 9:58 PM, Liu Bo <bo.li.liu@oracle.com> wrote:
> 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)
> Cc: stable@vger.kernel.org  # 4.8+
> Reported-by: Jeff Mahoney <jeffm@suse.com>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>

Thanks Bo!

> ---
> v2: Tag itself for stable.
>
>  fs/btrfs/disk-io.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 9367c31..b401e6d 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,
>                  * open_ctree() some roots has not yet been set up.
>                  */
>                 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->start !=
> -                           btrfs_root_bytenr(&check_root->root_item)) {
> +                       if (leaf != eb) {
>                                 CORRUPT("non-root leaf's nritems is 0",
> -                                       leaf, root, 0);
> +                                       leaf, check_root, 0);
> +                               free_extent_buffer(eb);
>                                 return -EIO;
>                         }
> +                       free_extent_buffer(eb);
>                 }
>                 return 0;
>         }
> --
> 2.5.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Filipe David Manana,

"People will forget what you said,
 people will forget what you did,
 but people will never forget how you made them feel."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-24  9:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23 21:58 [PATCH v2] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty Liu Bo
2016-11-24  9:56 ` Filipe Manana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.