From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/5] btrfs: tree-checker: Detect invalid empty essential tree
Date: Wed, 4 Jul 2018 08:56:59 +0300 [thread overview]
Message-ID: <61f1d3f9-5dd5-aa92-f8b4-5d582f1dd99f@suse.com> (raw)
In-Reply-To: <20180703091009.16399-3-wqu@suse.com>
On 3.07.2018 12:10, Qu Wenruo wrote:
> A crafted image has empty root tree block, which will cause later NULL
> pointer dereference.
>
> The following trees should never be empty:
> 1) Tree root
> Must contain at least root items for extent tree, device tree and fs
> tree
>
> 2) Chunk tree
> Or we can't even bootstrap.
>
> 3) Fs tree
> At least inode item for top level inode (.).
>
> 4) Device tree
> Dev extents for chunks
>
> 5) Extent tree
> Must has corresponding extent for each chunk.
>
> If any is empty, we are sure the fs is corrupted and no need to mount
> it.
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=199847
> Reported-by: Xu Wen <wen.xu@gatech.edu>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/tree-checker.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> index 1cd735b099df..3a307efab46b 100644
> --- a/fs/btrfs/tree-checker.c
> +++ b/fs/btrfs/tree-checker.c
> @@ -497,8 +497,20 @@ static int check_leaf(struct btrfs_fs_info *fs_info, struct extent_buffer *leaf,
> * skip this check for relocation trees.
> */
> if (nritems == 0 && !btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_RELOC)) {
> + u64 owner = btrfs_header_owner(leaf);
nit: Since you assign the owner of the leaf to a variable use this
variable when initialising key object below.
> struct btrfs_root *check_root;
>
> + /* These trees should never be empty */
> + if (owner == BTRFS_ROOT_TREE_OBJECTID ||
> + owner == BTRFS_CHUNK_TREE_OBJECTID ||
> + owner == BTRFS_EXTENT_TREE_OBJECTID ||
> + owner == BTRFS_DEV_TREE_OBJECTID ||
> + owner == BTRFS_FS_TREE_OBJECTID) {
> + generic_err(fs_info, leaf, 0,
> + "invalid root, root %llu should never be empty",
> + owner);
> + return -EUCLEAN;
> + }
> key.objectid = btrfs_header_owner(leaf);
> key.type = BTRFS_ROOT_ITEM_KEY;
> key.offset = (u64)-1;
>
next prev parent reply other threads:[~2018-07-04 5:57 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 9:10 [PATCH 0/5] Enhancement for block group/chunk verification Qu Wenruo
2018-07-03 9:10 ` [PATCH 1/5] btrfs: tree-checker: Verify block_group_item Qu Wenruo
2018-07-04 2:20 ` Gu, Jinxiang
2018-07-04 5:54 ` Nikolay Borisov
2018-07-04 7:37 ` Gu, Jinxiang
2018-07-03 9:10 ` [PATCH 2/5] btrfs: tree-checker: Detect invalid empty essential tree Qu Wenruo
2018-07-04 3:42 ` Gu, Jinxiang
2018-07-04 5:56 ` Nikolay Borisov [this message]
2018-07-04 7:37 ` Gu, Jinxiang
2018-07-03 9:10 ` [PATCH 3/5] btrfs: relocation: Only remove reloc rb_trees if reloc control has been initialized Qu Wenruo
2018-07-04 5:23 ` Gu, Jinxiang
2018-07-04 7:37 ` Gu, Jinxiang
2018-07-03 9:10 ` [PATCH 4/5] btrfs: Check each block group has corresponding chunk at mount time Qu Wenruo
2018-07-04 5:45 ` Gu, Jinxiang
2018-07-05 23:41 ` Qu Wenruo
2018-07-04 6:02 ` Nikolay Borisov
2018-07-03 9:10 ` [PATCH 5/5] btrfs: Verify every chunk has corresponding block group " Qu Wenruo
2018-07-04 6:09 ` Gu, Jinxiang
2018-07-04 7:08 ` Nikolay Borisov
2018-07-04 9:46 ` Qu Wenruo
2018-07-05 23:49 ` Qu Wenruo
2018-07-05 15:18 ` David Sterba
2018-07-05 23:44 ` Qu Wenruo
2018-07-16 13:16 ` David Sterba
2018-07-16 13:57 ` Qu Wenruo
2018-07-17 12:33 ` David Sterba
2018-07-17 13:32 ` Qu Wenruo
2018-07-19 14:22 ` David Sterba
2018-07-04 13:36 ` [PATCH 0/5] Enhancement for block group/chunk verification David Sterba
2018-07-05 1:36 ` Qu Wenruo
2018-07-05 15:18 ` 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=61f1d3f9-5dd5-aa92-f8b4-5d582f1dd99f@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/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).