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 18:33:02 +0800	[thread overview]
Message-ID: <99099790-200d-431f-9009-5c121bc2b7bf@fnnas.com> (raw)
In-Reply-To: <df2d93c0-2e7e-422d-8c81-8ddb1dfc00c3@gmx.com>

在 2026/7/11 18:17, Qu Wenruo 写道:
> 
> 
> 在 2026/7/11 19:22, Dongjiang Zhu 写道:
>> 在 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))) {
> 
> I'd prefer to put this inside btrfs_update_global_block_rsv().
> 
> Just in case there is some other call sites that can still hit 
> btrfs_update_global_block_rsv() for a fully RO fs.
> 
>>                   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?
> 
> I'd prefer fs_is_full_ro().
> 
> BTRFS_FS_ERROR() can be met for critical runtime errors, and we do not 
> want to mess global_block_rsv at all, as it may contain critical info 
> for debug.
> 
> For fs_is_full_ro() is very specific for rescue options, thus nothing to 
> save for debug in the first place.

Got it. Thanks for the clarification. I'll rework this and send a v2 later.

  reply	other threads:[~2026-07-11 10:33 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
2026-07-11 10:17       ` Qu Wenruo
2026-07-11 10:33         ` Dongjiang Zhu [this message]
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=99099790-200d-431f-9009-5c121bc2b7bf@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