[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250224075142.2959155-1-make24@iscas.ac.cn>
Date: Mon, 24 Feb 2025 15:51:42 +0800
From: Ma Ke <make24@...as.ac.cn>
To: clm@...com,
josef@...icpanda.com,
dsterba@...e.com,
jeffm@...e.com
Cc: linux-btrfs@...r.kernel.org,
linux-kernel@...r.kernel.org,
Ma Ke <make24@...as.ac.cn>,
stable@...r.kernel.org
Subject: [PATCH] btrfs: add a sanity check for btrfs root in btrfs_search_old_slot()
When searching the extent tree to gather the needed extent info,
btrfs_search_old_slot() doesn't check if the target root is NULL or
not, resulting the null-ptr-deref. Add sanity check for btrfs root
before using it in btrfs_search_old_slot().
Found by code review.
Cc: stable@...r.kernel.org
Fixes: 0b246afa62b0 ("btrfs: root->fs_info cleanup, add fs_info convenience variables")
Signed-off-by: Ma Ke <make24@...as.ac.cn>
---
fs/btrfs/ctree.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 3dc5a35dd19b..4e2e1c38d33a 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2232,7 +2232,7 @@ ALLOW_ERROR_INJECTION(btrfs_search_slot, ERRNO);
int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
struct btrfs_path *p, u64 time_seq)
{
- struct btrfs_fs_info *fs_info = root->fs_info;
+ struct btrfs_fs_info *fs_info;
struct extent_buffer *b;
int slot;
int ret;
@@ -2241,6 +2241,10 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
int lowest_unlock = 1;
u8 lowest_level = 0;
+ if (!root)
+ return -EINVAL;
+
+ fs_info = root->fs_info;
lowest_level = p->lowest_level;
WARN_ON(p->nodes[0] != NULL);
ASSERT(!p->nowait);
--
2.25.1
Powered by blists - more mailing lists