* [PATCH 0/2] btrfs: minor fixes in
@ 2026-11-22 22:59 Qu Wenruo
2026-11-22 22:59 ` [PATCH 1/2] btrfs: reject too high tree level during backref walk Qu Wenruo
2026-11-22 22:59 ` [PATCH 2/2] btrfs: avoid NULL-ptr-dreference after a lowest_level search Qu Wenruo
0 siblings, 2 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-22 22:59 UTC (permalink / raw)
To: linux-btrfs
The first one is reported by Sashiko, the second one is another bug
exposed during fixing the first one.
Qu Wenruo (2):
btrfs: reject too high tree level during backref walk
btrfs: avoid NULL-ptr-dreference after a lowest_level search
fs/btrfs/backref.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] btrfs: reject too high tree level during backref walk
2026-11-22 22:59 [PATCH 0/2] btrfs: minor fixes in Qu Wenruo
@ 2026-11-22 22:59 ` Qu Wenruo
2026-11-23 16:02 ` David Sterba
2026-11-22 22:59 ` [PATCH 2/2] btrfs: avoid NULL-ptr-dreference after a lowest_level search Qu Wenruo
1 sibling, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2026-11-22 22:59 UTC (permalink / raw)
To: linux-btrfs
In handle_indirect_tree_backref(), if we got @cur->level set to 7
(the max level valid), @level will be 8, then later path->slots[level]
and path->nodes[level] will all go beyond the array boundary.
Fix it by rejecting such high level before calling btrfs_search_slot().
Link: https://sashiko.dev/#/bug/linux-8a4f92b4-daf7-4f57-8369-8e6ef323652f
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/backref.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index a0fb90b7a9ed..d56476b21fe8 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -3316,6 +3316,11 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
}
level = cur->level + 1;
+ if (level >= BTRFS_MAX_LEVEL) {
+ btrfs_put_root(root);
+ btrfs_err(fs_info, "invalid searcch level %d", level);
+ return -EUCLEAN;
+ }
/* Search the tree to find parent blocks referring to the block */
path->search_commit_root = true;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs: avoid NULL-ptr-dreference after a lowest_level search
2026-11-22 22:59 [PATCH 0/2] btrfs: minor fixes in Qu Wenruo
2026-11-22 22:59 ` [PATCH 1/2] btrfs: reject too high tree level during backref walk Qu Wenruo
@ 2026-11-22 22:59 ` Qu Wenruo
1 sibling, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-22 22:59 UTC (permalink / raw)
To: linux-btrfs
In handle_indirect_tree_backref(), if we got a corrupted backref item
that has a valid level (e.g. 2), but higher than the subvolume root level
(e.g. 0), btrfs_search_slot() will return 0 or 1 depending on if the key
can be found in the leaf.
But the returned path->nodes[] will be all be NULL.
Later we call btrfs_node_blockptr(path->nodes[level]) will trigger a
NULL pointer dereference.
Fix it by checking if we got a valid eb pointer before calling
btrfs_node_blockptr(), and reject it as we can not find the parent tree
block.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/backref.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index d56476b21fe8..83301ffbfa87 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -3336,7 +3336,7 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
path->slots[level]--;
eb = path->nodes[level];
- if (btrfs_node_blockptr(eb, path->slots[level]) != cur->bytenr) {
+ if (!eb || btrfs_node_blockptr(eb, path->slots[level]) != cur->bytenr) {
btrfs_err(fs_info,
"couldn't find block (%llu) (level %d) in tree (%llu) with key " BTRFS_KEY_FMT,
cur->bytenr, level - 1, btrfs_root_id(root),
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs: reject too high tree level during backref walk
2026-11-22 22:59 ` [PATCH 1/2] btrfs: reject too high tree level during backref walk Qu Wenruo
@ 2026-11-23 16:02 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2026-11-23 16:02 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Mon, Nov 23, 2026 at 09:29:58AM +1030, Qu Wenruo wrote:
> In handle_indirect_tree_backref(), if we got @cur->level set to 7
> (the max level valid), @level will be 8, then later path->slots[level]
> and path->nodes[level] will all go beyond the array boundary.
>
> Fix it by rejecting such high level before calling btrfs_search_slot().
>
> Link: https://sashiko.dev/#/bug/linux-8a4f92b4-daf7-4f57-8369-8e6ef323652f
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/backref.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index a0fb90b7a9ed..d56476b21fe8 100644
> --- a/fs/btrfs/backref.c
> +++ b/fs/btrfs/backref.c
> @@ -3316,6 +3316,11 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
> }
>
> level = cur->level + 1;
> + if (level >= BTRFS_MAX_LEVEL) {
For EUCLEAN conditions you can add unlikely()
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 16:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 22:59 [PATCH 0/2] btrfs: minor fixes in Qu Wenruo
2026-11-22 22:59 ` [PATCH 1/2] btrfs: reject too high tree level during backref walk Qu Wenruo
2026-11-23 16:02 ` David Sterba
2026-11-22 22:59 ` [PATCH 2/2] btrfs: avoid NULL-ptr-dreference after a lowest_level search Qu Wenruo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.