public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit
@ 2025-12-08  7:52 syzbot
  2025-12-08 10:50 ` Edward Adam Davis
  2025-12-08 11:05 ` [PATCH] btrfs: Optimize the timing of prealloc memory allocation Edward Adam Davis
  0 siblings, 2 replies; 5+ messages in thread
From: syzbot @ 2025-12-08  7:52 UTC (permalink / raw)
  To: clm, dsterba, josef, linux-btrfs, linux-kernel, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    416f99c3b16f Merge tag 'driver-core-6.19-rc1' of git://git..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=12ed421a580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=f5a0bcda07a0bfd7
dashboard link: https://syzkaller.appspot.com/bug?extid=b44d4a4885bc82af2a06
compiler:       Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=12770eb4580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=148bbc1a580000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/d900f083ada3/non_bootable_disk-416f99c3.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/fb10fdbc0d42/vmlinux-416f99c3.xz
kernel image: https://storage.googleapis.com/syzbot-assets/f277b82f7dd0/bzImage-416f99c3.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/11aaebf70e5c/mount_0.gz
  fsck result: OK (log: https://syzkaller.appspot.com/x/fsck.log?x=176f4992580000)

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

R13: 00007f24f59e5fa0 R14: 00007f24f59e5fa0 R15: 0000000000000003
 </TASK>
assertion failed: prealloc == NULL :: 0, in fs/btrfs/qgroup.c:3529
------------[ cut here ]------------
kernel BUG at fs/btrfs/qgroup.c:3529!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
CPU: 0 UID: 0 PID: 5562 Comm: syz.0.19 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:btrfs_qgroup_inherit+0x2892/0x28a0 fs/btrfs/qgroup.c:3529
Code: ff ff e8 d1 1f d4 fd 48 c7 c7 a0 e5 b0 8b 48 c7 c6 00 e6 b0 8b 31 d2 48 c7 c1 20 e2 b0 8b 41 b8 c9 0d 00 00 e8 ef 58 3a fd 90 <0f> 0b 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 90
RSP: 0018:ffffc9000cbe7740 EFLAGS: 00010246
RAX: 0000000000000042 RBX: 0000000000000000 RCX: b3bb6c739819f900
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc9000cbe7990 R08: ffffc9000cbe7467 R09: 1ffff9200197ce8c
R10: dffffc0000000000 R11: fffff5200197ce8d R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 00000000fffffff4
FS:  0000555588ca7500(0000) GS:ffff88808d679000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b31b63fff CR3: 0000000011fab000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 create_subvol+0x5ad/0x18f0 fs/btrfs/ioctl.c:570
 btrfs_mksubvol+0x6e4/0x12c0 fs/btrfs/ioctl.c:928
 __btrfs_ioctl_snap_create+0x2b2/0x730 fs/btrfs/ioctl.c:1201
 btrfs_ioctl_snap_create+0x131/0x180 fs/btrfs/ioctl.c:1259
 btrfs_ioctl+0xb4d/0xd00 fs/btrfs/ioctl.c:-1
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:597 [inline]
 __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f24f578f7c9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffc9b4adc18 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f24f59e5fa0 RCX: 00007f24f578f7c9
RDX: 0000200000000280 RSI: 000000005000940e RDI: 0000000000000003
RBP: 00007ffc9b4adc70 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000002
R13: 00007f24f59e5fa0 R14: 00007f24f59e5fa0 R15: 0000000000000003
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:btrfs_qgroup_inherit+0x2892/0x28a0 fs/btrfs/qgroup.c:3529
Code: ff ff e8 d1 1f d4 fd 48 c7 c7 a0 e5 b0 8b 48 c7 c6 00 e6 b0 8b 31 d2 48 c7 c1 20 e2 b0 8b 41 b8 c9 0d 00 00 e8 ef 58 3a fd 90 <0f> 0b 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 90
RSP: 0018:ffffc9000cbe7740 EFLAGS: 00010246
RAX: 0000000000000042 RBX: 0000000000000000 RCX: b3bb6c739819f900
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc9000cbe7990 R08: ffffc9000cbe7467 R09: 1ffff9200197ce8c
R10: dffffc0000000000 R11: fffff5200197ce8d R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 00000000fffffff4
FS:  0000555588ca7500(0000) GS:ffff88808d679000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b31b63fff CR3: 0000000011fab000 CR4: 0000000000352ef0


---
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] 5+ messages in thread

* Re: [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit
  2025-12-08  7:52 [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit syzbot
@ 2025-12-08 10:50 ` Edward Adam Davis
  2025-12-08 11:06   ` syzbot
  2025-12-08 11:05 ` [PATCH] btrfs: Optimize the timing of prealloc memory allocation Edward Adam Davis
  1 sibling, 1 reply; 5+ messages in thread
From: Edward Adam Davis @ 2025-12-08 10:50 UTC (permalink / raw)
  To: syzbot+b44d4a4885bc82af2a06; +Cc: linux-kernel, syzkaller-bugs

#syz test

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 9e2b53e90dcb..ac5380520152 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3289,10 +3289,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 	if (!btrfs_qgroup_enabled(fs_info))
 		return 0;
 
-	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
-	if (!prealloc)
-		return -ENOMEM;
-
 	/*
 	 * There are only two callers of this function.
 	 *
@@ -3388,6 +3384,12 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 		}
 	}
 
+	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
+	if (!prealloc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	spin_lock(&fs_info->qgroup_lock);
 
 	dstgroup = add_qgroup_rb(fs_info, prealloc, objectid);


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

* [PATCH] btrfs: Optimize the timing of prealloc memory allocation
  2025-12-08  7:52 [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit syzbot
  2025-12-08 10:50 ` Edward Adam Davis
@ 2025-12-08 11:05 ` Edward Adam Davis
  2025-12-08 20:19   ` Qu Wenruo
  1 sibling, 1 reply; 5+ messages in thread
From: Edward Adam Davis @ 2025-12-08 11:05 UTC (permalink / raw)
  To: syzbot+b44d4a4885bc82af2a06
  Cc: clm, dsterba, josef, linux-btrfs, linux-kernel, syzkaller-bugs

Too many abnormal exits can cause the prealloc assertion to fail, as
reported by syzbot in [1].

Move the prealloc memory allocation to before it is actually used.

[1]
assertion failed: prealloc == NULL :: 0, in fs/btrfs/qgroup.c:3529
kernel BUG at fs/btrfs/qgroup.c:3529!
Call Trace:
 <TASK>
 create_subvol+0x5ad/0x18f0 fs/btrfs/ioctl.c:570
 btrfs_mksubvol+0x6e4/0x12c0 fs/btrfs/ioctl.c:928
 __btrfs_ioctl_snap_create+0x2b2/0x730 fs/btrfs/ioctl.c:1201
 btrfs_ioctl_snap_create+0x131/0x180 fs/btrfs/ioctl.c:1259
 btrfs_ioctl+0xb4d/0xd00 fs/btrfs/ioctl.c:-1

Fixes: 252877a87015 ("btrfs: add ASSERTs on prealloc in qgroup functions")
Reported-by: syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b44d4a4885bc82af2a06
Tested-by: syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 fs/btrfs/qgroup.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 9e2b53e90dcb..ac5380520152 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3289,10 +3289,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 	if (!btrfs_qgroup_enabled(fs_info))
 		return 0;
 
-	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
-	if (!prealloc)
-		return -ENOMEM;
-
 	/*
 	 * There are only two callers of this function.
 	 *
@@ -3388,6 +3384,12 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 		}
 	}
 
+	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
+	if (!prealloc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	spin_lock(&fs_info->qgroup_lock);
 
 	dstgroup = add_qgroup_rb(fs_info, prealloc, objectid);
-- 
2.43.0


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

* Re: [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit
  2025-12-08 10:50 ` Edward Adam Davis
@ 2025-12-08 11:06   ` syzbot
  0 siblings, 0 replies; 5+ messages in thread
From: syzbot @ 2025-12-08 11:06 UTC (permalink / raw)
  To: eadavis, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in btrfs_space_info_update_bytes_may_use

BTRFS info (device loop0): last unmount of filesystem 395ef67a-297e-477c-816d-cd80a5b93e5d
------------[ cut here ]------------
WARNING: fs/btrfs/space-info.h:257 at btrfs_space_info_update_bytes_may_use+0x318/0x600 fs/btrfs/space-info.h:257, CPU#0: syz-executor/5723
Modules linked in:
CPU: 0 UID: 0 PID: 5723 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:btrfs_space_info_update_bytes_may_use+0x318/0x600 fs/btrfs/space-info.h:257
Code: 00 00 74 08 4c 89 ff e8 56 d6 32 fe 4d 8b 27 4c 89 e7 48 8b 6c 24 18 48 89 ee e8 73 fc ca fd 49 39 ec 73 1c e8 09 fa ca fd 90 <0f> 0b 90 31 db 43 80 7c 35 00 00 0f 85 48 ff ff ff e9 4b ff ff ff
RSP: 0018:ffffc900029ff9d0 EFLAGS: 00010293
RAX: ffffffff83f6c687 RBX: ffffffffffea0000 RCX: ffff888043438000
RDX: 0000000000000000 RSI: 0000000000160000 RDI: 000000000015f000
RBP: 0000000000160000 R08: ffffffff8fa19777 R09: 1ffffffff1f432ee
R10: dffffc0000000000 R11: fffffbfff1f432ef R12: 000000000015f000
R13: 1ffff11007879710 R14: dffffc0000000000 R15: ffff88803c3cb880
FS:  000055558d353500(0000) GS:ffff88808d239000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fff9fad9d38 CR3: 0000000041c16000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 btrfs_space_info_free_bytes_may_use fs/btrfs/space-info.h:294 [inline]
 block_rsv_release_bytes fs/btrfs/block-rsv.c:153 [inline]
 btrfs_block_rsv_release+0x462/0x570 fs/btrfs/block-rsv.c:290
 btrfs_release_global_block_rsv+0x33/0x270 fs/btrfs/block-rsv.c:455
 btrfs_free_block_groups+0xcbf/0xfd0 fs/btrfs/block-group.c:4579
 close_ctree+0x7bc/0x1380 fs/btrfs/disk-io.c:4410
 generic_shutdown_super+0x135/0x2c0 fs/super.c:643
 kill_anon_super+0x3b/0x70 fs/super.c:1289
 btrfs_kill_super+0x41/0x50 fs/btrfs/super.c:2129
 deactivate_locked_super+0xbc/0x130 fs/super.c:474
 cleanup_mnt+0x425/0x4c0 fs/namespace.c:1318
 task_work_run+0x1d4/0x260 kernel/task_work.c:233
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 __exit_to_user_mode_loop kernel/entry/common.c:44 [inline]
 exit_to_user_mode_loop+0xff/0x4f0 kernel/entry/common.c:75
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:226 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:256 [inline]
 syscall_exit_to_user_mode_work include/linux/entry-common.h:159 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:194 [inline]
 do_syscall_64+0x2e3/0xf80 arch/x86/entry/syscall_64.c:100
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f3cbc790af7
Code: a8 ff ff ff f7 d8 64 89 01 48 83 c8 ff c3 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 c7 c2 a8 ff ff ff f7 d8 64 89 02 b8
RSP: 002b:00007fff9fada4e8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 00007f3cbc813d7d RCX: 00007f3cbc790af7
RDX: 0000000000000000 RSI: 0000000000000009 RDI: 00007fff9fada5a0
RBP: 00007fff9fada5a0 R08: 0000000000000000 R09: 0000000000000000
R10: 00000000ffffffff R11: 0000000000000246 R12: 00007fff9fadb630
R13: 00007f3cbc813d7d R14: 0000000000026b03 R15: 00007fff9fadb670
 </TASK>


Tested on:

commit:         c2f2b01b Merge tag 'i3c/for-6.19' of git://git.kernel...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14fd321a580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=1889d7812b50029c
dashboard link: https://syzkaller.appspot.com/bug?extid=b44d4a4885bc82af2a06
compiler:       Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
patch:          https://syzkaller.appspot.com/x/patch.diff?x=173be992580000


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

* Re: [PATCH] btrfs: Optimize the timing of prealloc memory allocation
  2025-12-08 11:05 ` [PATCH] btrfs: Optimize the timing of prealloc memory allocation Edward Adam Davis
@ 2025-12-08 20:19   ` Qu Wenruo
  0 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2025-12-08 20:19 UTC (permalink / raw)
  To: Edward Adam Davis, syzbot+b44d4a4885bc82af2a06
  Cc: clm, dsterba, josef, linux-btrfs, linux-kernel, syzkaller-bugs



在 2025/12/8 21:35, Edward Adam Davis 写道:
> Too many abnormal exits can cause the prealloc assertion to fail, as
> reported by syzbot in [1].
> 
> Move the prealloc memory allocation to before it is actually used.
> 
> [1]
> assertion failed: prealloc == NULL :: 0, in fs/btrfs/qgroup.c:3529
> kernel BUG at fs/btrfs/qgroup.c:3529!
> Call Trace:
>   <TASK>
>   create_subvol+0x5ad/0x18f0 fs/btrfs/ioctl.c:570
>   btrfs_mksubvol+0x6e4/0x12c0 fs/btrfs/ioctl.c:928
>   __btrfs_ioctl_snap_create+0x2b2/0x730 fs/btrfs/ioctl.c:1201
>   btrfs_ioctl_snap_create+0x131/0x180 fs/btrfs/ioctl.c:1259
>   btrfs_ioctl+0xb4d/0xd00 fs/btrfs/ioctl.c:-1

There is already a full revert, and your fix misses all the other error 
cases.

https://lore.kernel.org/linux-btrfs/20251208195407.GC4859@twin.jikos.cz/T/#t


> 
> Fixes: 252877a87015 ("btrfs: add ASSERTs on prealloc in qgroup functions")
> Reported-by: syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b44d4a4885bc82af2a06
> Tested-by: syzbot+b44d4a4885bc82af2a06@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>   fs/btrfs/qgroup.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 9e2b53e90dcb..ac5380520152 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3289,10 +3289,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>   	if (!btrfs_qgroup_enabled(fs_info))
>   		return 0;
>   
> -	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
> -	if (!prealloc)
> -		return -ENOMEM;
> -
>   	/*
>   	 * There are only two callers of this function.
>   	 *
> @@ -3388,6 +3384,12 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
>   		}
>   	}
>   
> +	prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
> +	if (!prealloc) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
>   	spin_lock(&fs_info->qgroup_lock);
>   
>   	dstgroup = add_qgroup_rb(fs_info, prealloc, objectid);


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

end of thread, other threads:[~2025-12-08 20:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08  7:52 [syzbot] [btrfs?] kernel BUG in btrfs_qgroup_inherit syzbot
2025-12-08 10:50 ` Edward Adam Davis
2025-12-08 11:06   ` syzbot
2025-12-08 11:05 ` [PATCH] btrfs: Optimize the timing of prealloc memory allocation Edward Adam Davis
2025-12-08 20:19   ` Qu Wenruo

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