Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: "Dongjiang Zhu" <zhudongjiang@fnnas.com>
To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, <linux-btrfs@vger.kernel.org>
Cc: <dsterba@suse.com>
Subject: Re: [PATCH 1/3] btrfs: avoid NULL pointer dereference when block group tree root is missing
Date: Sat, 11 Jul 2026 17:52:32 +0800	[thread overview]
Message-ID: <46fb761c-838f-4701-89aa-e56a85cca972@fnnas.com> (raw)
In-Reply-To: <2fc07620-861f-4bb8-ad36-71128ec1ab09@gmx.com>

在 2026/7/11 14:20, Qu Wenruo 写道:
>
>
> 在 2026/7/11 14:49, Dongjiang Zhu 写道:
>> [BUG]
>> For a filesystem using the block group tree feature, corrupting the 
>> block
>> group tree root and mounting with rescue=ibadroots triggers the 
>> following
>> NULL pointer dereference:
>>
>>    BTRFS warning (device loop0 state E): checksum verify failed on 
>> logical 30654464 mirror 1 wanted 0x0f55b851 found 0xd7efdde7 level 0
>>    BTRFS warning (device loop0 state E): checksum verify failed on 
>> logical 30654464 mirror 2 wanted 0x0f55b851 found 0xd7efdde7 level 0
>>    BUG: kernel NULL pointer dereference, address: 0000000000000100
>>    #PF: supervisor read access in kernel mode
>>    #PF: error_code(0x0000) - not-present page
>>    Oops: Oops: 0000 [#1] SMP NOPTI
>>    RIP: 0010:btrfs_update_global_block_rsv+0x9d/0x1c0 [btrfs]
>
> The problem is why we need to use global block rsv in the first place?
>
> The whole fs is never going to be mounted RW as long as "rescue=" 
> mount option is utilized.
>
> In the case of a rescue mount, we should just fill in a dummy block 
> rsv, with block_rsv->full set.
>
> This will also fix the next bug you're fixing.

That makes sense, thanks.

I had considered simply skipping btrfs_update_global_block_rsv() from
btrfs_init_global_block_rsv() when rescue=ibadroots is set, but did not
choose that approach in the end.

Your suggestion is semantically more precise. If I understand it
correctly, would the implementation look like this?

void btrfs_init_global_block_rsv(struct btrfs_fs_info *fs_info)
{
         struct btrfs_space_info *space_info;

         /* Existing space_info initialization. */

         if (unlikely(BTRFS_FS_ERROR(fs_info))) {
                 fs_info->global_block_rsv.full = true;
                 return;
         }

         btrfs_update_global_block_rsv(fs_info);
}

Would you agree with using BTRFS_FS_ERROR() here, or would you prefer the
narrower fs_is_full_ro() or IGNOREBADROOTS condition?

Thanks,
Dongjiang

  reply	other threads:[~2026-07-11  9:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-11  5:19 [PATCH 0/3] btrfs: handle missing block group and raid stripe tree roots Dongjiang Zhu
2026-07-11  5:19 ` [PATCH 1/3] btrfs: avoid NULL pointer dereference when block group tree root is missing Dongjiang Zhu
2026-07-11  6:20   ` Qu Wenruo
2026-07-11  9:52     ` Dongjiang Zhu [this message]
2026-07-11 10:17       ` Qu Wenruo
2026-07-11 10:33         ` Dongjiang Zhu
2026-07-11  5:19 ` [PATCH 2/3] btrfs: avoid NULL pointer dereference when raid stripe " Dongjiang Zhu
2026-07-11  5:19 ` [PATCH 3/3] btrfs: report missing raid stripe tree root during lookup Dongjiang Zhu

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=46fb761c-838f-4701-89aa-e56a85cca972@fnnas.com \
    --to=zhudongjiang@fnnas.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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