All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH 2/4] btrfs-progs: check: Fix lowmem mode stack overflow caused by fsck/023
Date: Mon,  5 Dec 2016 17:07:54 +0800	[thread overview]
Message-ID: <20161205090756.7960-3-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20161205090756.7960-1-quwenruo@cn.fujitsu.com>

Lowmem mode fsck will overflow its stack since it will do infinite
backref check for tree reloc root.
We should not check backref if it's pointing to itself for tree reloc
root.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 30847a0..ef90d87 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -9999,10 +9999,15 @@ static int check_tree_block_ref(struct btrfs_root *root,
 	u32 nodesize = root->nodesize;
 	u32 item_size;
 	u64 offset;
+	int tree_reloc_root = 0;
 	int found_ref = 0;
 	int err = 0;
 	int ret;
 
+	if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID &&
+	    btrfs_header_bytenr(root->node) == bytenr)
+		tree_reloc_root = 1;
+
 	btrfs_init_path(&path);
 	key.objectid = bytenr;
 	if (btrfs_fs_incompat(root->fs_info, SKINNY_METADATA))
@@ -10090,9 +10095,16 @@ static int check_tree_block_ref(struct btrfs_root *root,
 			(offset == root->objectid || offset == owner)) {
 			found_ref = 1;
 		} else if (type == BTRFS_SHARED_BLOCK_REF_KEY) {
+			/*
+			 * Backref of tree reloc root points to itself, no need
+			 * to check backref any more.
+			 */
+			if (tree_reloc_root)
+				found_ref = 1;
+			else
 			/* Check if the backref points to valid referencer */
-			found_ref = !check_tree_block_ref(root, NULL, offset,
-							  level + 1, owner);
+				found_ref = !check_tree_block_ref(root, NULL,
+						offset, level + 1, owner);
 		}
 
 		if (found_ref)
-- 
2.10.2




  parent reply	other threads:[~2016-12-05  9:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05  9:07 [PATCH 0/4] Lowmem fsck false alert fixes Qu Wenruo
2016-12-05  9:07 ` [PATCH 1/4] btrfs-progs: check: Fix assert when using lowmem on fs with tree reloc tree Qu Wenruo
2016-12-05  9:07 ` Qu Wenruo [this message]
2016-12-05  9:07 ` [PATCH 3/4] btrfs-progs: check: Fix lowmem false alert on " Qu Wenruo
2016-12-05  9:07 ` [PATCH 4/4] btrfs-progs: check: Fix false alert on generation mismatch for " Qu Wenruo
2016-12-14 13:15 ` [PATCH 0/4] Lowmem fsck false alert fixes 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=20161205090756.7960-3-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 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.