From: ZhengYuan Huang <gality369@gmail.com>
To: dsterba@suse.cz
Cc: dsterba@suse.com, clm@fb.com, idryomov@gmail.com,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
baijiaju1990@gmail.com, r33s3n6@gmail.com, zzzccc427@gmail.com,
stable@vger.kernel.org
Subject: Re: [PATCH v2 1/3] btrfs: balance: fix null-ptr-deref in chunk_usage_filter
Date: Tue, 24 Mar 2026 10:56:07 +0800 [thread overview]
Message-ID: <CAOmEq9UCwf_NzNh3tbuYqWYWxdkM8-V4w38YeVWwaK=RmR9usw@mail.gmail.com> (raw)
In-Reply-To: <20260323174027.GN5735@twin.jikos.cz>
On Tue, Mar 24, 2026 at 1:40 AM David Sterba <dsterba@suse.cz> wrote:
> So, for example you let a filesystem create some structures, let it
> continue, damage/destroy the structures and then let it access again?
>
> If this is supposed to emulate a corruption, either on media or in the
> IO path then OK.
Yes, this is one of the fuzzing strategies we use, where metadata is
intentionally corrupted at runtime to emulate possible media corruption
or I/O errors.
> > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > index 2bec544d8ba3..7c21ac249383 100644
> > --- a/fs/btrfs/volumes.c
> > +++ b/fs/btrfs/volumes.c
> > @@ -3863,14 +3863,20 @@ static bool chunk_usage_range_filter(struct btrfs_fs_info *fs_info, u64 chunk_of
> > return ret;
> > }
> >
> > -static bool chunk_usage_filter(struct btrfs_fs_info *fs_info, u64 chunk_offset,
> > - struct btrfs_balance_args *bargs)
> > +static int chunk_usage_filter(struct btrfs_fs_info *fs_info, u64 chunk_offset,
> > + struct btrfs_balance_args *bargs)
> > {
> > struct btrfs_block_group *cache;
> > u64 chunk_used, user_thresh;
> > bool ret = true;
>
> As this is bool it does not match the changed return type anymore
>
> >
> > cache = btrfs_lookup_block_group(fs_info, chunk_offset);
> > + if (!cache) {
> > + btrfs_err(fs_info,
> > + "balance: chunk at bytenr %llu has no corresponding block group",
> > + chunk_offset);
> > + return -EUCLEAN;
> > + }
> > chunk_used = cache->used;
> >
> > if (bargs->usage_min == 0)
> > @@ -3986,8 +3992,8 @@ static bool chunk_soft_convert_filter(u64 chunk_type, struct btrfs_balance_args
> > return false;
> > }
> >
> > -static bool should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *chunk,
> > - u64 chunk_offset)
> > +static int should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *chunk,
> > + u64 chunk_offset)
> > {
> > struct btrfs_fs_info *fs_info = leaf->fs_info;
> > struct btrfs_balance_control *bctl = fs_info->balance_ctl;
> > @@ -4014,9 +4020,13 @@ static bool should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk
> > }
> >
> > /* usage filter */
> > - if ((bargs->flags & BTRFS_BALANCE_ARGS_USAGE) &&
> > - chunk_usage_filter(fs_info, chunk_offset, bargs)) {
> > - return false;
> > + if (bargs->flags & BTRFS_BALANCE_ARGS_USAGE) {
> > + int filter_ret = chunk_usage_filter(fs_info, chunk_offset, bargs);
>
> Same problem here. Also please use ret2 for nested return values.
Thanks for the note, I’ll fix the return type issue and send a v3.
Thanks,
ZhengYuan Huang
next prev parent reply other threads:[~2026-03-24 2:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260314123741.1439792-1-gality369@gmail.com>
2026-03-14 12:37 ` [PATCH v2 1/3] btrfs: balance: fix null-ptr-deref in chunk_usage_filter ZhengYuan Huang
2026-03-23 17:40 ` David Sterba
2026-03-24 2:56 ` ZhengYuan Huang [this message]
2026-03-14 12:37 ` [PATCH v2 2/3] btrfs: balance: fix null-ptr-deref in chunk_usage_range_filter ZhengYuan Huang
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='CAOmEq9UCwf_NzNh3tbuYqWYWxdkM8-V4w38YeVWwaK=RmR9usw@mail.gmail.com' \
--to=gality369@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--cc=idryomov@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=r33s3n6@gmail.com \
--cc=stable@vger.kernel.org \
--cc=zzzccc427@gmail.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