From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] btrfs-progs: Don't return any fs_info that contain NULL tree_root or fs_root.
Date: Tue, 30 Sep 2014 10:39:22 +0800 [thread overview]
Message-ID: <1412044762-2480-1-git-send-email-quwenruo@cn.fujitsu.com> (raw)
[BUG]
btrfsck will segfault if it fails to open the fs tree or tree root.
[REPRODUCER]
Execute btrfsck on a highly damaged btrfs image.
fsfuzz can be used to make a junk btrfs image.
[REASON]
Current open_ctree() in btrfs-progs support OPEN_CTREE_PARTIAL flag to
allow return fs_info even some of the trees is missing.
However it is too loose and even allows fs_info containing no tree to be
returned.
And when it happens, fs_info->fs_root is NULL,
close_ctree(fs_info->fs_root) will cause the access to NULL pointer and
segfault.
[FIX]
This patch will add checks for fs_info->tree_root and fs_info->fs_root
before return fs_info.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
disk-io.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/disk-io.c b/disk-io.c
index 26a532e..21a3083 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1134,7 +1134,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
return fs_info;
out_failed:
- if (flags & OPEN_CTREE_PARTIAL)
+ if (flags & OPEN_CTREE_PARTIAL &&
+ fs_info->tree_root && fs_info->fs_root)
return fs_info;
out_chunk:
btrfs_release_all_roots(fs_info);
--
2.1.1
next reply other threads:[~2014-09-30 2:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-30 2:39 Qu Wenruo [this message]
2014-09-30 11:35 ` [PATCH] btrfs-progs: Don't return any fs_info that contain NULL tree_root or fs_root David Sterba
2014-09-30 15:24 ` Zach Brown
2014-10-06 1:12 ` Qu Wenruo
2014-10-06 1:17 ` Qu Wenruo
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=1412044762-2480-1-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.com \
--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).