From: Su Yue <l@damenly.su>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, Stickstoff <stickstoff@posteo.de>
Subject: Re: [PATCH 2/3] btrfs: check/original: reject bad metadata backref with invalid level
Date: Mon, 17 Jan 2022 10:48:29 +0800 [thread overview]
Message-ID: <1r17vzxp.fsf@damenly.su> (raw)
In-Reply-To: <20220117023850.40337-3-wqu@suse.com>
On Mon 17 Jan 2022 at 10:38, Qu Wenruo <wqu@suse.com> wrote:
> [BUG]
> There is a bug report that kernel tree-checker rejected an
> invalid
> metadata item:
>
> corrupt leaf: block=934474399744 slot=68 extent
> bytenr=425173254144 len=16384 invalid tree level, have 33554432
> expect [0, 7]
>
> But original mode btrfs-check reports nothing wrong.
> (BTW, lowmem mode will just crash, and fixed in previous patch).
>
> [CAUSE]
> For original mode it doesn't really check tree level, thus
> didn't find
> the problem.
>
> [FIX]
> I don't have a good idea to completely make original mode to
> verify the
> level in backref and in the tree block (while lowmem does that).
>
> But at least we can detect obviouly corrupted level just like
> kernel.
>
> Now original mode will detect such problem:
>
> ...
> [2/7] checking extents
> ERROR: tree block 30457856 has bad backref level, has 256
> expect [0, 7]
> ref mismatch on [30457856 16384] extent item 0, found 1
> tree backref 30457856 root 5 not found in extent tree
> backpointer mismatch on [30457856 16384]
> ERROR: errors found in extent allocation tree or chunk
> allocation
> [3/7] checking free space tree
> ...
>
> Reported-by: Stickstoff <stickstoff@posteo.de>
> Link:
> https://lore.kernel.org/linux-btrfs/6ed4cd5a-7430-f326-4056-25ae7eb44416@posteo.de/
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> check/main.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/check/main.c b/check/main.c
> index 540130b8e223..2dea2acf5104 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -5447,6 +5447,25 @@ static int process_extent_item(struct
> btrfs_root *root,
> if (metadata)
> btrfs_check_subpage_eb_alignment(gfs_info,
> key.objectid, num_bytes);
>
> + ptr = (unsigned long)(ei + 1);
> + if (metadata) {
> + u64 level;
> +
> + if (key.type == BTRFS_EXTENT_ITEM_KEY) {
> + struct btrfs_tree_block_info *info;
> +
> + info = (struct btrfs_tree_block_info
> *)ptr;
> + level = btrfs_tree_block_level(eb, info);
> + } else {
> + level = key.offset;
> + }
> + if (level >= BTRFS_MAX_LEVEL) {
> + error(
> + "tree block %llu has bad backref level, has %llu expect
> [0, %u]",
> + key.objectid, level, BTRFS_MAX_LEVEL
> - 1);
> + return -EIO;
>
-EUCLEAN is better?
Reviewed-by: Su Yue <l@damenly.su>
--
Su
> + }
> + }
> memset(&tmpl, 0, sizeof(tmpl));
> tmpl.start = key.objectid;
> tmpl.nr = num_bytes;
next prev parent reply other threads:[~2022-01-17 2:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 2:38 [PATCH 0/3] btrfs-progs: fsck: detect obviously invalid metadata backref level Qu Wenruo
2022-01-17 2:38 ` [PATCH 1/3] btrfs-progs: check/lowmem: fix crash when METADATA_ITEM has invalid level Qu Wenruo
2022-01-17 2:47 ` Su Yue
2022-01-17 2:38 ` [PATCH 2/3] btrfs: check/original: reject bad metadata backref with " Qu Wenruo
2022-01-17 2:48 ` Su Yue [this message]
2022-02-01 17:34 ` David Sterba
2022-01-17 2:38 ` [PATCH 3/3] btrfs-progs: tests/fsck: add test image with invalid metadata backref level Qu Wenruo
2022-02-01 17:37 ` [PATCH 0/3] btrfs-progs: fsck: detect obviously " 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=1r17vzxp.fsf@damenly.su \
--to=l@damenly.su \
--cc=linux-btrfs@vger.kernel.org \
--cc=stickstoff@posteo.de \
--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).