linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH] btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree
Date: Thu,  6 Oct 2016 17:13:32 +0800	[thread overview]
Message-ID: <20161006091332.12836-1-quwenruo@cn.fujitsu.com> (raw)

For tree reloc tree whose level is >= 2, the root node's parent will
point to itself.
In this case it will make btrfsck overflow its stack and cause segfault.

While for tree reloc tree, it doesn't affect qgroup and kernel can
handle it well.

So add tree reloc tree check for qgroup-verify.c and fix the bug.

Test case will follow soon after I make a minimal image for it.
Current xz ziped image is still over 10M for a 512M fs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 qgroup-verify.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/qgroup-verify.c b/qgroup-verify.c
index df0e547..9a56f59 100644
--- a/qgroup-verify.c
+++ b/qgroup-verify.c
@@ -369,6 +369,11 @@ static int find_parent_roots(struct ulist *roots, u64 parent)
 				if (ret < 0)
 					goto out;
 			}
+		} else if (ref->parent == ref->bytenr) {
+			/*
+			 * Special loop case for tree reloc tree
+			 */
+			ref->root = BTRFS_TREE_RELOC_OBJECTID;
 		} else {
 			ret = find_parent_roots(roots, ref->parent);
 			if (ret < 0)
@@ -578,6 +583,8 @@ static u64 resolve_one_root(u64 bytenr)
 
 	if (ref->root)
 		return ref->root;
+	if (ref->parent == bytenr)
+		return BTRFS_TREE_RELOC_OBJECTID;
 	return resolve_one_root(ref->parent);
 }
 
@@ -748,6 +755,9 @@ static int add_refs_for_implied(struct btrfs_fs_info *info, u64 bytenr,
 	struct btrfs_root *root;
 	struct btrfs_key key;
 
+	/* Tree reloc tree doesn't contribute qgroup, skip it */
+	if (root_id == BTRFS_TREE_RELOC_OBJECTID)
+		return 0;
 	key.objectid = root_id;
 	key.type = BTRFS_ROOT_ITEM_KEY;
 	key.offset = (u64)-1;
-- 
2.10.0




             reply	other threads:[~2016-10-06  9:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06  9:13 Qu Wenruo [this message]
2016-10-13 15:58 ` [PATCH] btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161006091332.12836-1-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).