public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [btrfs?] kernel BUG in populate_free_space_tree
@ 2025-06-05 18:06 syzbot
  0 siblings, 0 replies; 2+ messages in thread
From: syzbot @ 2025-06-05 18:06 UTC (permalink / raw)
  To: clm, dsterba, josef, linux-btrfs, linux-kernel, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    d7fa1af5b33e Merge branch 'for-next/core' into for-kernelci
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci
console output: https://syzkaller.appspot.com/x/log.txt?x=17ab4c0c580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=89c13de706fbf07a
dashboard link: https://syzkaller.appspot.com/bug?extid=36fae25c35159a763a2a
compiler:       Debian clang version 20.1.6 (++20250514063057+1e4d39e07757-1~exp1~20250514183223.118), Debian LLD 20.1.6
userspace arch: arm64
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=12b79282580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=106b4c0c580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/da97ad659b2c/disk-d7fa1af5.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/659e123552a8/vmlinux-d7fa1af5.xz
kernel image: https://storage.googleapis.com/syzbot-assets/6ec5dbf4643e/Image-d7fa1af5.gz.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/643a65f1a5eb/mount_0.gz
  fsck result: OK (log: https://syzkaller.appspot.com/x/fsck.log?x=11f86570580000)

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+36fae25c35159a763a2a@syzkaller.appspotmail.com

BTRFS warning: 'usebackuproot' is deprecated, use 'rescue=usebackuproot' instead
BTRFS info (device loop0 state M): rebuilding free space tree
assertion failed: ret == 0, in fs/btrfs/free-space-tree.c:1102
------------[ cut here ]------------
kernel BUG at fs/btrfs/free-space-tree.c:1102!
Internal error: Oops - BUG: 00000000f2000800 [#1]  SMP
Modules linked in:
CPU: 1 UID: 0 PID: 6592 Comm: syz-executor322 Not tainted 6.15.0-rc7-syzkaller-gd7fa1af5b33e #0 PREEMPT 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025
pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : populate_free_space_tree+0x514/0x518 fs/btrfs/free-space-tree.c:1102
lr : populate_free_space_tree+0x514/0x518 fs/btrfs/free-space-tree.c:1102
sp : ffff8000a4ce7600
x29: ffff8000a4ce76e0 x28: ffff0000c9bc6000 x27: ffff0000ddfff3d8
x26: ffff0000ddfff378 x25: dfff800000000000 x24: 0000000000000001
x23: ffff8000a4ce7660 x22: ffff70001499cecc x21: ffff0000e1d8c160
x20: ffff0000e1cb7800 x19: ffff0000e1d8c0b0 x18: 00000000ffffffff
x17: ffff800092f39000 x16: ffff80008ad27e48 x15: ffff700011e740c0
x14: 1ffff00011e740c0 x13: 0000000000000004 x12: ffffffffffffffff
x11: ffff700011e740c0 x10: 0000000000ff0100 x9 : 94ef24f55d2dbc00
x8 : 94ef24f55d2dbc00 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff8000a4ce6f98 x4 : ffff80008f415ba0 x3 : ffff800080548ef0
x2 : 0000000000000000 x1 : 0000000100000000 x0 : 000000000000003e
Call trace:
 populate_free_space_tree+0x514/0x518 fs/btrfs/free-space-tree.c:1102 (P)
 btrfs_rebuild_free_space_tree+0x14c/0x54c fs/btrfs/free-space-tree.c:1337
 btrfs_start_pre_rw_mount+0xa78/0xe10 fs/btrfs/disk-io.c:3074
 btrfs_remount_rw fs/btrfs/super.c:1319 [inline]
 btrfs_reconfigure+0x828/0x2418 fs/btrfs/super.c:1543
 reconfigure_super+0x1d4/0x6f0 fs/super.c:1083
 do_remount fs/namespace.c:3365 [inline]
 path_mount+0xb34/0xde0 fs/namespace.c:4200
 do_mount fs/namespace.c:4221 [inline]
 __do_sys_mount fs/namespace.c:4432 [inline]
 __se_sys_mount fs/namespace.c:4409 [inline]
 __arm64_sys_mount+0x3e8/0x468 fs/namespace.c:4409
 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
 invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49
 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132
 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151
 el0_svc+0x58/0x17c arch/arm64/kernel/entry-common.c:767
 el0t_64_sync_handler+0x78/0x108 arch/arm64/kernel/entry-common.c:786
 el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:600
Code: f0047182 91178042 528089c3 9771d47b (d4210000) 
---[ end trace 0000000000000000 ]---


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

^ permalink raw reply	[flat|nested] 2+ messages in thread
* kernel BUG in populate_free_space_tre
@ 2025-06-07 11:19 Abinash
  2025-06-07 12:15 ` [syzbot] [btrfs?] kernel BUG in populate_free_space_tree syzbot
  0 siblings, 1 reply; 2+ messages in thread
From: Abinash @ 2025-06-07 11:19 UTC (permalink / raw)
  To: syzbot+36fae25c35159a763a2a; +Cc: clm, josef, dsterba, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 10 bytes --]

#syz test

[-- Attachment #1.2: Type: text/html, Size: 31 bytes --]

[-- Attachment #2: 0001-btrfs-remove-ASSERT-in-populate_free_space_tree-for-.patch --]
[-- Type: text/x-patch, Size: 3058 bytes --]

From d25d9fb07d3eab994234665ebb0d98b298aa59c4 Mon Sep 17 00:00:00 2001
From: avinashlalotra <abinashsinghlalotra@gmail.com>
Date: Sat, 7 Jun 2025 16:19:41 +0530
Subject: [PATCH] btrfs: remove ASSERT in populate_free_space_tree for empty
 extent tree btrfs_search_slot_for_read() returns 1 when no items are found

 but populate_free_space_tree() has ASSERT(ret == 0) which panics on empty
 extent trees. Empty extent trees are valid (new block groups, after
 deletions) so remove the assert and handle ret == 1 by skipping the scan
 loop.

Reported-by: syzbot+36fae25c35159a763a2a@syzkaller.appspotmail.com
Signed-off-by: avinashlalotra <abinashsinghlalotra@gmail.com>
---
 fs/btrfs/free-space-tree.c | 62 ++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 0c573d46639a..beffe52dfa59 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1115,43 +1115,45 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans,
 	ret = btrfs_search_slot_for_read(extent_root, &key, path, 1, 0);
 	if (ret < 0)
 		goto out_locked;
-	ASSERT(ret == 0);
 
 	start = block_group->start;
 	end = block_group->start + block_group->length;
-	while (1) {
-		btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
-
-		if (key.type == BTRFS_EXTENT_ITEM_KEY ||
-		    key.type == BTRFS_METADATA_ITEM_KEY) {
-			if (key.objectid >= end)
-				break;
 
-			if (start < key.objectid) {
-				ret = __add_to_free_space_tree(trans,
-							       block_group,
-							       path2, start,
-							       key.objectid -
-							       start);
-				if (ret)
-					goto out_locked;
+	if (ret == 0) {
+		while (1) {
+			btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+
+			if (key.type == BTRFS_EXTENT_ITEM_KEY ||
+			    key.type == BTRFS_METADATA_ITEM_KEY) {
+				if (key.objectid >= end)
+					break;
+
+				if (start < key.objectid) {
+					ret = __add_to_free_space_tree(trans,
+								       block_group,
+								       path2, start,
+								       key.objectid -
+								       start);
+					if (ret)
+						goto out_locked;
+				}
+				start = key.objectid;
+				if (key.type == BTRFS_METADATA_ITEM_KEY)
+					start += trans->fs_info->nodesize;
+				else
+					start += key.offset;
+			} else if (key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) {
+				if (key.objectid != block_group->start)
+					break;
 			}
-			start = key.objectid;
-			if (key.type == BTRFS_METADATA_ITEM_KEY)
-				start += trans->fs_info->nodesize;
-			else
-				start += key.offset;
-		} else if (key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) {
-			if (key.objectid != block_group->start)
+
+			ret = btrfs_next_item(extent_root, path);
+			if (ret < 0)
+				goto out_locked;
+			if (ret)
 				break;
 		}
-
-		ret = btrfs_next_item(extent_root, path);
-		if (ret < 0)
-			goto out_locked;
-		if (ret)
-			break;
-	}
+	}	
 	if (start < end) {
 		ret = __add_to_free_space_tree(trans, block_group, path2,
 					       start, end - start);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-07 12:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 18:06 [syzbot] [btrfs?] kernel BUG in populate_free_space_tree syzbot
  -- strict thread matches above, loose matches on Subject: below --
2025-06-07 11:19 kernel BUG in populate_free_space_tre Abinash
2025-06-07 12:15 ` [syzbot] [btrfs?] kernel BUG in populate_free_space_tree syzbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox