[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250102090502.218613-1-lizhi.xu@windriver.com>
Date: Thu, 2 Jan 2025 17:05:02 +0800
From: Lizhi Xu <lizhi.xu@...driver.com>
To: <lizhi.xu@...driver.com>
CC: <clm@...com>, <dsterba@...e.com>, <josef@...icpanda.com>,
<linux-btrfs@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<quwenruo.btrfs@....com>,
<syzbot+339e9dbe3a2ca419b85d@...kaller.appspotmail.com>,
<syzkaller-bugs@...glegroups.com>
Subject: [PATCH V4] btrfs: Prevent the use of corrupt extent root
syzbot reported a null-ptr-deref in find_first_extent_item. [1]
The btrfs filesystem did not successfully initialize extent root to the
global root tree when mounted, since the mount options contain ignorebadroots,
because commit 42437a6386ff, it can be mounted successfully, which causes
the failure to read the tree root, which in turn causes exten root to not
be inserted into the global root tree.
Add a extent root check when scrub calls scrub_find_fill_first_stripe.
[1]
Unable to handle kernel paging request at virtual address dfff800000000041
KASAN: null-ptr-deref in range [0x0000000000000208-0x000000000000020f]
Mem abort info:
ESR = 0x0000000096000005
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x05: level 1 translation fault
Data abort info:
ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
CM = 0, WnR = 0, TnD = 0, TagAccess = 0
GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[dfff800000000041] address between user and kernel address ranges
Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
Modules linked in:
CPU: 1 UID: 0 PID: 6417 Comm: syz-executor153 Not tainted 6.13.0-rc3-syzkaller-g573067a5a685 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : find_first_extent_item+0xac/0x674 fs/btrfs/scrub.c:1375
lr : find_first_extent_item+0xa4/0x674 fs/btrfs/scrub.c:1374
sp : ffff8000a5be6e60
x29: ffff8000a5be6f80 x28: dfff800000000000 x27: 0000000000000000
x26: 0000000000400000 x25: 0000000000400000 x24: 1fffe0001848ab0a
x23: 0000000000000208 x22: ffff8000a5be6f20 x21: ffff0000c2455858
x20: ffff8000a5be6ec0 x19: ffff0000db072010 x18: ffff0000db072010
x17: 000000000000e32c x16: ffff80008b5fea08 x15: 0000000000000004
x14: 1fffe0001b60c031 x13: 0000000000000000 x12: ffff700014b7cdd8
x11: ffff80008257f234 x10: 0000000000ff0100 x9 : 0000000000000000
x8 : 0000000000000041 x7 : 0000000000000000 x6 : 000000000000003f
x5 : 0000000000000040 x4 : 0000000000000008 x3 : 0000000000400000
x2 : 0000000000100000 x1 : ffff0000db072010 x0 : 0000000000000000
Call trace:
find_first_extent_item+0xac/0x674 fs/btrfs/scrub.c:1375 (P)
scrub_find_fill_first_stripe+0x2c0/0xab8 fs/btrfs/scrub.c:1551
queue_scrub_stripe fs/btrfs/scrub.c:1921 [inline]
scrub_simple_mirror+0x440/0x7e4 fs/btrfs/scrub.c:2152
scrub_stripe+0x7e4/0x2174 fs/btrfs/scrub.c:2317
scrub_chunk+0x268/0x41c fs/btrfs/scrub.c:2443
scrub_enumerate_chunks+0xd38/0x1784 fs/btrfs/scrub.c:2707
btrfs_scrub_dev+0x5a8/0xb34 fs/btrfs/scrub.c:3029
btrfs_ioctl_scrub+0x1f4/0x3e8 fs/btrfs/ioctl.c:3248
btrfs_ioctl+0x6a8/0xb04 fs/btrfs/ioctl.c:5246
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:906 [inline]
__se_sys_ioctl fs/ioctl.c:892 [inline]
__arm64_sys_ioctl+0x14c/0x1cc fs/ioctl.c:892
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
Fixes: 42437a6386ff ("btrfs: introduce mount option rescue=ignorebadroots")
Reported-by: syzbot+339e9dbe3a2ca419b85d@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=339e9dbe3a2ca419b85d
Signed-off-by: Lizhi Xu <lizhi.xu@...driver.com>
---
V1 -> V2: exit mount when extent root is corrupt
V2 -> V3: correct comments and Fixes tag
V3 -> V4: check extent root before calling find_first_extent_item
fs/btrfs/scrub.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 204c928beaf9..560415fe1007 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1548,6 +1548,9 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg,
/* The range must be inside the bg. */
ASSERT(logical_start >= bg->start && logical_end <= bg->start + bg->length);
+ if (!extent_root)
+ return -ENOENT;
+
ret = find_first_extent_item(extent_root, extent_path, logical_start,
logical_len);
/* Either error or not found. */
--
2.43.0
Powered by blists - more mailing lists