WARNING: refcount bug in process_scheduled_works
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: ced1b9e0392d Merge tag 'ata-6.17-rc1' of git://git.kernel... git tree: upstream console+strace: https://syzkaller.appspot.com/x/log.txt?x=15c89782580000 kernel config: https://syzkaller.appspot.com/x/.config?x=d51af648924b64c9 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=177f7034580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=165e44a2580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/f1495c1de592/disk-ced1b9e0.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/982f755305ce/vmlinux-ced1b9e0.xz
kernel image: https://storage.googleapis.com/syzbot-assets/b17cd424f373/bzImage-ced1b9e0.xz
The issue was bisected to:
commit 9e59d609763f70a992a8f3808dabcce60f14eb5c
Author: Xiao Ni <[email protected]> Date: Wed Jun 11 07:31:06 2025 +0000
md: call del_gendisk in control path
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=14ab54a2580000 final oops: https://syzkaller.appspot.com/x/report.txt?x=16ab54a2580000 console output: https://syzkaller.appspot.com/x/log.txt?x=12ab54a2580000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
------------[ cut here ]------------ refcount_t: underflow; use-after-free. WARNING: CPU: 1 PID: 24 at lib/refcount.c:28 refcount_warn_saturate+0x11a/0x1d0 lib/refcount.c:28 Modules linked in: CPU: 1 UID: 0 PID: 24 Comm: kworker/1:0 Not tainted 6.16.0-syzkaller-00857-gced1b9e0392d #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025 Workqueue: md_misc mddev_delayed_delete RIP: 0010:refcount_warn_saturate+0x11a/0x1d0 lib/refcount.c:28 Code: 00 83 e2 8b e8 b7 5b bf fc 90 0f 0b 90 90 eb d7 e8 bb 6d fb fc c6 05 09 32 c7 0a 01 90 48 c7 c7 60 83 e2 8b e8 97 5b bf fc 90 <0f> 0b 90 90 eb b7 e8 9b 6d fb fc c6 05 e6 31 c7 0a 01 90 48 c7 c7 RSP: 0018:ffffc900001e7a68 EFLAGS: 00010246 RAX: 3c6a9b38a742a100 RBX: 0000000000000003 RCX: ffff88801d298000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000002 RBP: ffffc900001e7c70 R08: ffff8880b8724293 R09: 1ffff110170e4852 R10: dffffc0000000000 R11: ffffed10170e4853 R12: ffff8880b8739700 R13: ffff88801d2ab218 R14: ffff8880331dc130 R15: 0000000000000001 FS: 0000000000000000(0000) GS:ffff888125d07000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000056071c71c048 CR3: 000000000df38000 CR4: 0000000000350ef0 Call Trace: <TASK> process_one_work kernel/workqueue.c:3238 [inline] process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3321 worker_thread+0x8a0/0xda0 kernel/workqueue.c:3402 kthread+0x711/0x8a0 kernel/kthread.c:464 ret_from_fork+0x3fc/0x770 arch/x86/kernel/process.c:148 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 </TASK>
---
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 [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot. For information about bisection process see: https://goo.gl/tpsmEJ#bisection
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
Quoted 5 lines
Date: Tue, 29 Jul 2025 14:58:32 -0700 [thread overview]
Hello,syzbot found the following issue on:
Quoted 7 lines
HEAD commit: ced1b9e0392d Merge tag 'ata-6.17-rc1' of git://git.kernel... git tree: upstream console+strace: https://syzkaller.appspot.com/x/log.txt?x=15c89782580000 kernel config: https://syzkaller.appspot.com/x/.config?x=d51af648924b64c9 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=177f7034580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=165e44a2580000
#syz test
drivers/md/md.c +4 -1
@@ -632,10 +632,13 @@ static void mddev_delayed_delete(structstatic void __mddev_put (struct mddev *mddev) { +struct kobject *kobj = &mddev->kobj; +if (mddev->raid_disks || !list_empty (&mddev->disks) || mddev->ctime || mddev->hold_active)return ; +BUG_ON (kref_read (&kobj->kref) <1 );/* * Call queue_work inside the spinlock so that flush_workqueue() after * mddev_find will succeed in waiting for the work to be done.
@@ -710,6 +713,7 @@ int mddev_init(struct mddev *mddev)INIT_WORK (&mddev->sync_work, md_start_sync);INIT_WORK (&mddev->del_work, mddev_delayed_delete); +kobject_init (&mddev->kobj, &md_ktype);return 0 ; }
@@ -5982,7 +5986,6 @@ struct mddev *md_alloc(dev_t dev, char *if (error) goto out_put_disk; -kobject_init (&mddev->kobj, &md_ktype); error =kobject_add (&mddev->kobj, &disk_to_dev (disk)->kobj,"%s" ,"md" );if (error) {/*
--
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: kernel BUG in mddev_put
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
kernel BUG in mddev_put
------------[ cut here ]------------ kernel BUG at drivers/md/md.c:641! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI CPU: 1 UID: 0 PID: 6615 Comm: syz.0.17 Not tainted 6.16.0-syzkaller-gbeb6c8326eb4-dirty #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025 RIP: 0010:__mddev_put drivers/md/md.c:641 [inline] RIP: 0010:mddev_put+0x1e9/0x1f0 drivers/md/md.c:660 Code: f9 e9 3f ff ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6d ff ff ff 4c 89 f7 e8 12 f3 e0 f9 e9 60 ff ff ff e8 48 e0 7e f9 90 <0f> 0b 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 RSP: 0018:ffffc90002ee7cb0 EFLAGS: 00010293 RAX: ffffffff8840dae8 RBX: ffff888033654000 RCX: ffff88802f4bda00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffff888033654133 R09: 1ffff110066ca826 R10: dffffc0000000000 R11: ffffed10066ca827 R12: ffff888027267000 R13: ffff888148c55090 R14: ffff888033654130 R15: dffffc0000000000 FS: 0000555567c20500(0000) GS:ffff888125d86000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000007 CR3: 0000000075a4e000 CR4: 0000000000350ef0 Call Trace: <TASK> bdev_release+0x536/0x650 block/bdev.c:-1 blkdev_release+0x15/0x20 block/fops.c:699 __fput+0x44c/0xa70 fs/file_table.c:468 task_work_run+0x1d4/0x260 kernel/task_work.c:227 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline] exit_to_user_mode_loop+0xec/0x110 kernel/entry/common.c:43 exit_to_user_mode_prepare include/linux/irq-entry-common.h:208 [inline] syscall_exit_to_user_mode_work include/linux/entry-common.h:175 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:210 [inline] do_syscall_64+0x2bd/0x3b0 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe9c578e9a9 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:00007ffe99d6fa48 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4 RAX: 0000000000000000 RBX: 000000000002511a RCX: 00007fe9c578e9a9 RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003 RBP: 00007fe9c59b7ba0 R08: 0000000000000001 R09: 0000000899d6fd3f R10: 00007fe9c5600000 R11: 0000000000000246 R12: 00007fe9c59b5fac R13: 00007fe9c59b5fa0 R14: ffffffffffffffff R15: 00007ffe99d6fb60 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:__mddev_put drivers/md/md.c:641 [inline] RIP: 0010:mddev_put+0x1e9/0x1f0 drivers/md/md.c:660 Code: f9 e9 3f ff ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6d ff ff ff 4c 89 f7 e8 12 f3 e0 f9 e9 60 ff ff ff e8 48 e0 7e f9 90 <0f> 0b 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 RSP: 0018:ffffc90002ee7cb0 EFLAGS: 00010293 RAX: ffffffff8840dae8 RBX: ffff888033654000 RCX: ffff88802f4bda00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffff888033654133 R09: 1ffff110066ca826 R10: dffffc0000000000 R11: ffffed10066ca827 R12: ffff888027267000 R13: ffff888148c55090 R14: ffff888033654130 R15: dffffc0000000000 FS: 0000555567c20500(0000) GS:ffff888125d86000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000007 CR3: 0000000075a4e000 CR4: 0000000000350ef0
Tested on:
commit: beb6c832 Merge tag 'uml-for-linux-6.17-rc1' of git://g.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=152d0834580000 kernel config: https://syzkaller.appspot.com/x/.config?x=dea300d7050f7861 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=13a3b1bc580000
Quoted 5 lines
Date: Tue, 29 Jul 2025 14:58:32 -0700 [thread overview]
Hello,syzbot found the following issue on:
Quoted 7 lines
HEAD commit: ced1b9e0392d Merge tag 'ata-6.17-rc1' of git://git.kernel... git tree: upstream console+strace: https://syzkaller.appspot.com/x/log.txt?x=15c89782580000 kernel config: https://syzkaller.appspot.com/x/.config?x=d51af648924b64c9 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=177f7034580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=165e44a2580000
#syz test
drivers/md/md.c +4 -0
@@ -632,10 +632,13 @@ static void mddev_delayed_delete(structstatic void __mddev_put (struct mddev *mddev) { +struct kobject *kobj = &mddev->kobj; +if (mddev->raid_disks || !list_empty (&mddev->disks) || mddev->ctime || mddev->hold_active)return ; +BUG_ON (kref_read (&kobj->kref) <1 );/* * Call queue_work inside the spinlock so that flush_workqueue() after * mddev_find will succeed in waiting for the work to be done.
@@ -5983,6 +5986,7 @@ struct mddev *md_alloc(dev_t dev, char * goto out_put_disk;kobject_init (&mddev->kobj, &md_ktype); +kobject_get (&mddev->kobj); error =kobject_add (&mddev->kobj, &disk_to_dev (disk)->kobj,"%s" ,"md" );if (error) {/*
--
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: kernel BUG in mddev_put
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
kernel BUG in mddev_put
------------[ cut here ]------------ kernel BUG at drivers/md/md.c:641! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI CPU: 0 UID: 0 PID: 6690 Comm: syz.0.18 Not tainted 6.16.0-syzkaller-04405-g4b290aae788e-dirty #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025 RIP: 0010:__mddev_put drivers/md/md.c:641 [inline] RIP: 0010:mddev_put+0x1e9/0x1f0 drivers/md/md.c:660 Code: f9 e9 3f ff ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6d ff ff ff 4c 89 f7 e8 c2 ed e0 f9 e9 60 ff ff ff e8 f8 da 7e f9 90 <0f> 0b 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 RSP: 0018:ffffc90002f27cb0 EFLAGS: 00010293 RAX: ffffffff8840e0e8 RBX: ffff888032332000 RCX: ffff88807b13da00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffff888032332133 R09: 1ffff11006466426 R10: dffffc0000000000 R11: ffffed1006466427 R12: ffff88806364e000 R13: ffff888148c47310 R14: ffff888032332130 R15: dffffc0000000000 FS: 000055558e36e500(0000) GS:ffff888125c86000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000007 CR3: 000000005c370000 CR4: 0000000000350ef0 Call Trace: <TASK> bdev_release+0x536/0x650 block/bdev.c:-1 blkdev_release+0x15/0x20 block/fops.c:699 __fput+0x44c/0xa70 fs/file_table.c:468 task_work_run+0x1d4/0x260 kernel/task_work.c:227 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline] exit_to_user_mode_loop+0xec/0x110 kernel/entry/common.c:43 exit_to_user_mode_prepare include/linux/irq-entry-common.h:208 [inline] syscall_exit_to_user_mode_work include/linux/entry-common.h:175 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:210 [inline] do_syscall_64+0x2bd/0x3b0 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f9d1d58e9a9 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:00007ffee3402d38 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4 RAX: 0000000000000000 RBX: 0000000000025060 RCX: 00007f9d1d58e9a9 RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003 RBP: 00007f9d1d7b7ba0 R08: 0000000000000001 R09: 00000008e340302f R10: 00007f9d1d400000 R11: 0000000000000246 R12: 00007f9d1d7b5fac R13: 00007f9d1d7b5fa0 R14: ffffffffffffffff R15: 00007ffee3402e50 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:__mddev_put drivers/md/md.c:641 [inline] RIP: 0010:mddev_put+0x1e9/0x1f0 drivers/md/md.c:660 Code: f9 e9 3f ff ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6d ff ff ff 4c 89 f7 e8 c2 ed e0 f9 e9 60 ff ff ff e8 f8 da 7e f9 90 <0f> 0b 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 RSP: 0018:ffffc90002f27cb0 EFLAGS: 00010293 RAX: ffffffff8840e0e8 RBX: ffff888032332000 RCX: ffff88807b13da00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffff888032332133 R09: 1ffff11006466426 R10: dffffc0000000000 R11: ffffed1006466427 R12: ffff88806364e000 R13: ffff888148c47310 R14: ffff888032332130 R15: dffffc0000000000 FS: 000055558e36e500(0000) GS:ffff888125c86000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000007 CR3: 000000005c370000 CR4: 0000000000350ef0
Tested on:
commit: 4b290aae Merge tag 'sysctl-6.17-rc1' of git://git.kern.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=11948834580000 kernel config: https://syzkaller.appspot.com/x/.config?x=dea300d7050f7861 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=1394ccf0580000
Quoted 5 lines
Date: Tue, 29 Jul 2025 14:58:32 -0700 [thread overview]
Hello,syzbot found the following issue on:
Quoted 7 lines
HEAD commit: ced1b9e0392d Merge tag 'ata-6.17-rc1' of git://git.kernel... git tree: upstream console+strace: https://syzkaller.appspot.com/x/log.txt?x=15c89782580000 kernel config: https://syzkaller.appspot.com/x/.config?x=d51af648924b64c9 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=177f7034580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=165e44a2580000
Test Yu Kuai's fix (https://lore.kernel.org/lkml/[email protected]/)
#syz test
drivers/md/md.c +6 -0
@@ -636,6 +636,12 @@ static void __mddev_put(struct mddev *mddev) mddev->ctime || mddev->hold_active)return ; +/* +* If array is freed by stopping array, MD_DELETED is set by +* do_md_stop(), MD_DELETED is still set here in cause mddev is freed +* directly by closing a mddev that is created by create_on_open. +*/ +set_bit (MD_DELETED , &mddev->flags);/* * Call queue_work inside the spinlock so that flush_workqueue() after * mddev_find will succeed in waiting for the work to be done.
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 4b290aae Merge tag 'sysctl-6.17-rc1' of git://git.kern.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=13420ca2580000 kernel config: https://syzkaller.appspot.com/x/.config?x=dea300d7050f7861 dashboard link: https://syzkaller.appspot.com/bug?extid=9921e319bd6168140b40 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=12908834580000
Note: testing is done by a robot and is best-effort only.