From: Qu Wenruo <wqu@suse.com>
To: Mark Harmstone <maharmstone@fb.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: don't clobber ret in btrfs_validate_super()
Date: Wed, 12 Mar 2025 07:40:09 +1030 [thread overview]
Message-ID: <92a9f026-d195-43fd-aade-029f12f4fca8@suse.com> (raw)
In-Reply-To: <20250311163931.1021554-1-maharmstone@fb.com>
在 2025/3/12 03:09, Mark Harmstone 写道:
> Commit 2a9bb78cfd36 introduces a call to validate_sys_chunk_array() in
> btrfs_validate_super(), which clobbers the value of ret set earlier.
> This has the effect of negating the validity checks done earlier, making
> it so btrfs could potentially try to mount invalid filesystems.
>
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
> Cc: Qu Wenruo <wqu@suse.com>
> Fixes: 2a9bb78cfd36 ("btrfs: validate system chunk array at btrfs_validate_super()")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks for catching this.
Although I agree with Filipe that it's better to return the error
immediately in the future.
Yes, currently it will report all the errors, but if the first check
against magic number fails, the super block can just be garbage and all
the remaining checks will be triggered.
Other than a single "no valid fs found" message, we got all kinds of
errors, which is not that easy for end users to understand.
Thanks,
Qu
> ---
> fs/btrfs/disk-io.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 0afd3c0f2fab..4421c946a53c 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -2562,6 +2562,9 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
> ret = -EINVAL;
> }
>
> + if (ret)
> + return ret;
> +
> ret = validate_sys_chunk_array(fs_info, sb);
>
> /*
next prev parent reply other threads:[~2025-03-11 21:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-11 16:39 [PATCH] btrfs: don't clobber ret in btrfs_validate_super() Mark Harmstone
2025-03-11 16:54 ` Filipe Manana
2025-03-11 18:27 ` Mark Harmstone
2025-03-11 21:10 ` Qu Wenruo [this message]
2025-03-12 14:18 ` David Sterba
2025-03-12 14:26 ` 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=92a9f026-d195-43fd-aade-029f12f4fca8@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=maharmstone@fb.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