From: "Daniel Xu" <dxu@dxuuu.xyz>
To: linux-btrfs@vger.kernel.org, dsterba@suse.com
Cc: "Kernel Team" <kernel-team@fb.com>,
josef@toxicpanda.com, quwenruo.btrfs@gmx.com,
"Qu Wenruo" <wqu@suse.com>
Subject: Re: [PATCH v2] btrfs: Fix divide by zero
Date: Wed, 14 Oct 2020 13:26:06 -0700 [thread overview]
Message-ID: <04fd46a0-c93c-4fd7-ae60-cd63f765beff@www.fastmail.com> (raw)
In-Reply-To: <20201009010910.270794-1-dxu@dxuuu.xyz>
On Thu, Oct 8, 2020, at 6:09 PM, Daniel Xu wrote:
> If there's no parity and num_stripes < ncopies, an btrfs image can
> trigger a divide by zero in calc_stripe_length().
>
> The image (see link) was generated through fuzzing.
>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=209587
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>
> v1->v2:
> * Upload test image to kernel bugzilla
>
>
> fs/btrfs/tree-checker.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> index 7b1fee630f97..e03c3807921f 100644
> --- a/fs/btrfs/tree-checker.c
> +++ b/fs/btrfs/tree-checker.c
> @@ -760,18 +760,36 @@ int btrfs_check_chunk_valid(struct extent_buffer *leaf,
> u64 type;
> u64 features;
> bool mixed = false;
> + int raid_index;
> + int nparity;
> + int ncopies;
>
> length = btrfs_chunk_length(leaf, chunk);
> stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
> num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
> sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk);
> type = btrfs_chunk_type(leaf, chunk);
> + raid_index = btrfs_bg_flags_to_raid_index(type);
> + ncopies = btrfs_raid_array[raid_index].ncopies;
> + nparity = btrfs_raid_array[raid_index].nparity;
>
> if (!num_stripes) {
> chunk_err(leaf, chunk, logical,
> "invalid chunk num_stripes, have %u", num_stripes);
> return -EUCLEAN;
> }
> + if (num_stripes < ncopies) {
> + chunk_err(leaf, chunk, logical,
> + "invalid chunk num_stripes < ncopies, have %u < %d",
> + num_stripes, ncopies);
> + return -EUCLEAN;
> + }
> + if (nparity && num_stripes == nparity) {
> + chunk_err(leaf, chunk, logical,
> + "invalid chunk num_stripes == nparity, have %u == %d",
> + num_stripes, nparity);
> + return -EUCLEAN;
> + }
> if (!IS_ALIGNED(logical, fs_info->sectorsize)) {
> chunk_err(leaf, chunk, logical,
> "invalid chunk logical, have %llu should aligned to %u",
> --
> 2.28.0
>
>
Gentle poke.
Thanks,
Daniel
next prev parent reply other threads:[~2020-10-14 20:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-09 1:09 [PATCH v2] btrfs: Fix divide by zero Daniel Xu
2020-10-14 20:26 ` Daniel Xu [this message]
2020-10-14 20:44 ` Josef Bacik
2020-10-16 14:33 ` 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=04fd46a0-c93c-4fd7-ae60-cd63f765beff@www.fastmail.com \
--to=dxu@dxuuu.xyz \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
--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).