summaryrefslogtreecommitdiff
path: root/qgroup-verify.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2016-10-06 17:13:32 +0800
committerDavid Sterba <dsterba@suse.com>2016-10-24 15:02:45 +0200
commitd94816cbde4c26ccd7b936d58636f50682decc83 (patch)
treeac8f835f56d072d5ec8d92d49259e81b07a93998 /qgroup-verify.c
parentc9ec835ae1448e9f6fe5e9bbe29c94b6d8cee4ee (diff)
btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree
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> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'qgroup-verify.c')
-rw-r--r--qgroup-verify.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/qgroup-verify.c b/qgroup-verify.c
index df0e5474..9a56f597 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;