From: Chris Mason <clm@meta.com>
To: <fdmanana@kernel.org>
Cc: <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 2/2] btrfs: deal with missing root in sample_block_group_extent_item()
Date: Sun, 8 Feb 2026 08:16:33 -0800 [thread overview]
Message-ID: <20260208161657.3972997-1-clm@meta.com> (raw)
In-Reply-To: <30034e48a39502638fbac40662914132895cca4b.1769028677.git.fdmanana@suse.com>
fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> In case the does not exists, which is unexpected, btrfs_extent_root()
> returns NULL, but we ignore that and so if it happens we can trigger
> a NULL pointer dereference later. So verify if we found the root and
> log an error message in case it's missing.
Hi everyone,
I'm running the btrfs for-next branch, along with the encryption patch set
through my AI review prompts:
https://github.com/masoncl/review-prompts
I'm working on some btrfs specific instructions, but hopefully these reviews
are already useful. I've kept the headers to make it easier to double check
that I'm actually replying to the right email, but please let me know if any
parts of this are incorrect:
commit a8bec25e014eab671ec8a25b03d391cad3e55230
Author: Filipe Manana <fdmanana@suse.com>
btrfs: deal with missing root in sample_block_group_extent_item()
This commit adds a NULL check for extent_root after calling
btrfs_extent_root() in sample_block_group_extent_item(), addressing
a potential NULL pointer dereference.
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 66c512bc022c5..28aa87872f0d9 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -607,6 +607,12 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
> lockdep_assert_held_read(&fs_info->commit_root_sem);
>
> extent_root = btrfs_extent_root(fs_info, block_group->start);
> + if (unlikely(!extent_root)) {
> + btrfs_err(fs_info,
> + "missing extent root for block group at offset %llu",
> + block_group->start);
> + return -EUCLEAN;
> + }
>
> search_offset = index * div_u64(block_group->length, max_index);
> search_key.objectid = block_group->start + search_offset;
Does load_extent_tree_free() in the same file have the same issue?
Looking at load_extent_tree_free() around line 741:
last = max_t(u64, block_group->start, BTRFS_SUPER_INFO_OFFSET);
extent_root = btrfs_extent_root(fs_info, last);
and then at line 767:
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
There's no NULL check between the btrfs_extent_root() call and the
btrfs_search_slot() call. If btrfs_extent_root() returns NULL (via
btrfs_global_root() when rb_find() fails), extent_root would be
dereferenced in btrfs_search_slot(), causing a NULL pointer
dereference.
Both sample_block_group_extent_item() and load_extent_tree_free() are
called from caching_thread() during block group caching operations, so
they have the same risk profile. Should load_extent_tree_free() have
the same NULL check added?
next prev parent reply other threads:[~2026-02-08 16:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 20:52 [PATCH 0/2] btrfs: cleanup and fix sample_block_group_extent_item() fdmanana
2026-01-21 20:52 ` [PATCH 1/2] btrfs: remove bogus root search condition in sample_block_group_extent_item() fdmanana
2026-01-21 20:52 ` [PATCH 2/2] btrfs: deal with missing root " fdmanana
2026-01-21 21:28 ` Filipe Manana
2026-01-21 21:42 ` Boris Burkov
2026-01-22 1:42 ` David Sterba
2026-02-08 16:16 ` Chris Mason [this message]
2026-01-21 21:42 ` [PATCH 0/2] btrfs: cleanup and fix sample_block_group_extent_item() Boris Burkov
2026-01-21 22:07 ` Qu Wenruo
2026-01-22 1:43 ` 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=20260208161657.3972997-1-clm@meta.com \
--to=clm@meta.com \
--cc=fdmanana@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/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