From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Yoon Jungyeon <jungyeon@gatech.edu>
Subject: [PATCH 3/3] btrfs: tree-checker: Fix NULL pointer access for corrupted chunk root
Date: Fri, 8 Mar 2019 15:29:29 +0800 [thread overview]
Message-ID: <20190308072929.30863-4-wqu@suse.com> (raw)
In-Reply-To: <20190308072929.30863-1-wqu@suse.com>
[BUG]
For a special crafted image, kernel can cause NULL pointer dereference like:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000024
#PF error: [normal kernel read fault]
Oops: 0000 [#1] SMP PTI
CPU: 0 PID: 146 Comm: kworker/u2:4 Not tainted 5.0.0-rc8+ #9
Workqueue: btrfs-endio-meta btrfs_endio_meta_helper
RIP: 0010:btrfs_root_node+0x10/0x50
Call Trace:
btrfs_read_lock_root_node+0x29/0x50
btrfs_search_slot+0x529/0x920
btrfs_find_root+0x56/0x240
btrfs_read_tree_root+0x8b/0x130
btrfs_read_fs_root+0x12/0x40
btrfs_get_fs_root.part.49+0x53/0x170
btrfs_get_fs_root+0x44/0xa0
check_leaf+0xc0/0xa90
btrfs_check_leaf_full+0x13/0x20
btree_readpage_end_io_hook+0x242/0x290
end_bio_extent_readpage+0x14f/0x660
bio_endio+0xc4/0x140
end_workqueue_fn+0x3d/0x40
normal_work_helper+0xcb/0x320
btrfs_endio_meta_helper+0x12/0x20
process_one_work+0x167/0x410
worker_thread+0x4d/0x460
kthread+0x105/0x140
ret_from_fork+0x35/0x40
[CAUSE]
Tree checker can be triggered when tree root is still not initialized.
This is for chunk tree read.
However if chunk tree is empty and has incorrect owner, then tree
checker will do comprehensive empty tree check.
This check involves search root tree to find the root, thus triggering
NULL pointer dereference as root tree is not yet initialized.
[FIX]
Just skip restrict owner check if tree root is not yet initialized.
Fix this fix, the corrupted image can be rejected as expected:
BTRFS info (device loop0): disk space caching is enabled
BTRFS info (device loop0): has skinny extents
BTRFS error (device loop0): super_num_devices 1 mismatch with num_devices 0 found here
BTRFS error (device loop0): failed to read chunk tree: -22
BTRFS error (device loop0): open_ctree failed
Reported-by: Yoon Jungyeon <jungyeon@gatech.edu>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=202753
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/tree-checker.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 5ccb4be583ea..e01a84be768f 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -760,8 +760,12 @@ static int check_leaf(struct btrfs_fs_info *fs_info, struct extent_buffer *leaf,
* we can't use @owner as accurate owner indicator.
* Case like balance and new tree block created for commit root
* can break owner check easily.
+ *
+ * Also we could trigger tree checker before root tree
+ * initialized (read chunk tree), skip strict owner check
+ * if root tree is not initialized yet.
*/
- if (!check_empty_leaf)
+ if (!check_empty_leaf || !fs_info->tree_root->node)
return 0;
key.objectid = owner;
--
2.21.0
prev parent reply other threads:[~2019-03-08 7:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-08 7:29 [PATCH 0/3] btrfs: tree-checker: Enhancement and fixes for new fuzzed image report Qu Wenruo
2019-03-08 7:29 ` [PATCH 1/3] btrfs: tree-checker: Verify chunk items Qu Wenruo
2019-03-09 5:51 ` Nikolay Borisov
2019-03-11 15:25 ` Nikolay Borisov
2019-03-11 23:41 ` Qu Wenruo
2019-03-19 7:58 ` Qu Wenruo
2019-03-28 16:58 ` David Sterba
2019-03-28 23:38 ` Qu Wenruo
2019-03-08 7:29 ` [PATCH 2/3] btrfs: tree-checker: Verify dev item Qu Wenruo
2019-03-08 7:29 ` Qu Wenruo [this message]
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=20190308072929.30863-4-wqu@suse.com \
--to=wqu@suse.com \
--cc=jungyeon@gatech.edu \
--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).