From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C033014B084; Fri, 6 Dec 2024 14:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733495976; cv=none; b=bwvLIOf3R3fLCGqlWv5kBognq9HVNfTFBcX6y/zdxV7jBmLt1NT7HpS6Y70W+gfqRuYioFClf79y4n2EPl1yPrnql+VitJcu4ZTam333/Fc8D7qsVz6Fx7B0KMnGrC+YcV+1LEd0x4nQJgWArcOUz6bKr3mbTVB2IIRWqY5IYXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733495976; c=relaxed/simple; bh=Yy69NKTAYPomQuCEdsf3Zd6qVsiQl/uq0ORBlygwMjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LFeTpnRuDdRNuDZSBO0M3qjGnXV2+9z4O8CFjV3b1vY0El3ijAbGl/CqWDfTize40TJgz4gp8Vx85sMIi9gYRg17N1f1oHbmCnT4WZ9PV27YWepy2k/wEkVvEmdg7OWPWhAcuZTN/WEGUkImGP7DTKjf2HCL8cjTnq9lgwQM9nI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1K74VlZT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1K74VlZT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0928C4CED1; Fri, 6 Dec 2024 14:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733495976; bh=Yy69NKTAYPomQuCEdsf3Zd6qVsiQl/uq0ORBlygwMjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1K74VlZTH/Dd1Mt2cES+Vlo+xTiWPpc2eAYyds/wvQM/pcG7VbLCdI+OAvbmEIEZI EWt051eJwgPD2xz8eCSfVHmkMusfPCkJuBTidQJlMheni7k679YIyv2kLFs5arsMOd XuxgcxchC2tfh3bgeL8joe09KWLIetIIziilllMw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+3030e17bd57a73d39bd7@syzkaller.appspotmail.com, Qu Wenruo , Lizhi Xu , David Sterba , Sasha Levin Subject: [PATCH 6.12 008/146] btrfs: add a sanity check for btrfs root in btrfs_search_slot() Date: Fri, 6 Dec 2024 15:35:39 +0100 Message-ID: <20241206143527.987591378@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241206143527.654980698@linuxfoundation.org> References: <20241206143527.654980698@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lizhi Xu [ Upstream commit 3ed51857a50f530ac7a1482e069dfbd1298558d4 ] Syzbot reports a null-ptr-deref in btrfs_search_slot(). The reproducer is using rescue=ibadroots, and the extent tree root is corrupted thus the extent tree is NULL. When scrub tries to search the extent tree to gather the needed extent info, btrfs_search_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_slot(). Reported-by: syzbot+3030e17bd57a73d39bd7@syzkaller.appspotmail.com Fixes: 42437a6386ff ("btrfs: introduce mount option rescue=ignorebadroots") Link: https://syzkaller.appspot.com/bug?extid=3030e17bd57a73d39bd7 CC: stable@vger.kernel.org # 5.15+ Reviewed-by: Qu Wenruo Tested-by: syzbot+3030e17bd57a73d39bd7@syzkaller.appspotmail.com Signed-off-by: Lizhi Xu Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- 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 0cc919d15b144..9c05cab473f57 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -2010,7 +2010,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, const struct btrfs_key *key, struct btrfs_path *p, int ins_len, int cow) { - struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_fs_info *fs_info; struct extent_buffer *b; int slot; int ret; @@ -2023,6 +2023,10 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, int min_write_lock_level; int prev_cmp; + if (!root) + return -EINVAL; + + fs_info = root->fs_info; might_sleep(); lowest_level = p->lowest_level; -- 2.43.0