==================================================================
BUG: KASAN: slab-use-after-free in __ref_is_percpu include/linux/percpu-refcount.h:174 [inline]
BUG: KASAN: slab-use-after-free in percpu_ref_put_many include/linux/percpu-refcount.h:332 [inline]
BUG: KASAN: slab-use-after-free in percpu_ref_put+0xda/0x250 include/linux/percpu-refcount.h:351
Read of size 8 at addr ffff88804204e0b0 by task kworker/u4:1/13

CPU: 0 UID: 0 PID: 13 Comm: kworker/u4:1 Not tainted 6.14.0-syzkaller-09352-g0c86b42439b6 #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
Workqueue: loop0 loop_workfn
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:408 [inline]
 print_report+0x16e/0x5b0 mm/kasan/report.c:521
 kasan_report+0x143/0x180 mm/kasan/report.c:634
 __ref_is_percpu include/linux/percpu-refcount.h:174 [inline]
 percpu_ref_put_many include/linux/percpu-refcount.h:332 [inline]
 percpu_ref_put+0xda/0x250 include/linux/percpu-refcount.h:351
 blk_update_request+0x5e5/0x1160 block/blk-mq.c:983
 blk_mq_end_request+0x3e/0x70 block/blk-mq.c:1145
 loop_handle_cmd drivers/block/loop.c:1960 [inline]
 loop_process_work+0x1bdf/0x21d0 drivers/block/loop.c:1978
 process_one_work kernel/workqueue.c:3238 [inline]
 process_scheduled_works+0xac3/0x18e0 kernel/workqueue.c:3319
 worker_thread+0x870/0xd50 kernel/workqueue.c:3400
 kthread+0x7b7/0x940 kernel/kthread.c:464
 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:153
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

Allocated by task 5327:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:377 [inline]
 __kasan_kmalloc+0x9d/0xb0 mm/kasan/common.c:394
 kasan_kmalloc include/linux/kasan.h:260 [inline]
 __kmalloc_cache_noprof+0x236/0x370 mm/slub.c:4349
 kmalloc_noprof include/linux/slab.h:902 [inline]
 kzalloc_noprof include/linux/slab.h:1036 [inline]
 __bch2_dev_alloc+0x57/0xa60 fs/bcachefs/super.c:1327
 bch2_dev_alloc+0xd6/0x180 fs/bcachefs/super.c:1394
 bch2_fs_alloc fs/bcachefs/super.c:958 [inline]
 bch2_fs_open+0x315f/0x32a0 fs/bcachefs/super.c:2182
 bch2_fs_get_tree+0x77b/0x18d0 fs/bcachefs/fs.c:2172
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3878
 do_mount fs/namespace.c:4218 [inline]
 __do_sys_mount fs/namespace.c:4429 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4406
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 5327:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:576
 poison_slab_object mm/kasan/common.c:247 [inline]
 __kasan_slab_free+0x59/0x70 mm/kasan/common.c:264
 kasan_slab_free include/linux/kasan.h:233 [inline]
 slab_free_hook mm/slub.c:2376 [inline]
 slab_free mm/slub.c:4633 [inline]
 kfree+0x198/0x430 mm/slub.c:4832
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x22f/0x480 lib/kobject.c:737
 bch2_fs_free+0x27b/0x3c0 fs/bcachefs/super.c:677
 deactivate_locked_super+0xc4/0x130 fs/super.c:473
 bch2_fs_get_tree+0xd41/0x18d0 fs/bcachefs/fs.c:2294
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3878
 do_mount fs/namespace.c:4218 [inline]
 __do_sys_mount fs/namespace.c:4429 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4406
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Last potentially related work creation:
 kasan_save_stack+0x3f/0x60 mm/kasan/common.c:47
 kasan_record_aux_stack+0xbf/0xd0 mm/kasan/generic.c:548
 insert_work+0x3e/0x330 kernel/workqueue.c:2183
 __queue_work+0xda3/0x10a0 kernel/workqueue.c:2341
 queue_work_on+0x1c4/0x380 kernel/workqueue.c:2392
 queue_work include/linux/workqueue.h:662 [inline]
 bch2_dev_do_invalidates+0x17a/0x1f0 fs/bcachefs/alloc_background.c:2274
 bch2_do_invalidates+0x29/0x60 fs/bcachefs/alloc_background.c:2285
 __bch2_fs_read_write+0x386/0x3b0 fs/bcachefs/super.c:510
 bch2_run_recovery_pass+0xf0/0x1e0 fs/bcachefs/recovery_passes.c:226
 bch2_run_recovery_passes+0x2ad/0xa90 fs/bcachefs/recovery_passes.c:291
 bch2_fs_recovery+0x292a/0x3e20 fs/bcachefs/recovery.c:936
 bch2_fs_start+0x37c/0x620 fs/bcachefs/super.c:1057
 bch2_fs_get_tree+0x1270/0x18d0 fs/bcachefs/fs.c:2253
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3878
 do_mount fs/namespace.c:4218 [inline]
 __do_sys_mount fs/namespace.c:4429 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4406
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Second to last potentially related work creation:
 kasan_save_stack+0x3f/0x60 mm/kasan/common.c:47
 kasan_record_aux_stack+0xbf/0xd0 mm/kasan/generic.c:548
 insert_work+0x3e/0x330 kernel/workqueue.c:2183
 __queue_work+0xda3/0x10a0 kernel/workqueue.c:2341
 queue_work_on+0x1c4/0x380 kernel/workqueue.c:2392
 queue_work include/linux/workqueue.h:662 [inline]
 bch2_dev_do_discards+0x17a/0x1f0 fs/bcachefs/alloc_background.c:1967
 bch2_do_discards+0x29/0x60 fs/bcachefs/alloc_background.c:1978
 __bch2_fs_read_write+0x37e/0x3b0 fs/bcachefs/super.c:509
 bch2_run_recovery_pass+0xf0/0x1e0 fs/bcachefs/recovery_passes.c:226
 bch2_run_recovery_passes+0x2ad/0xa90 fs/bcachefs/recovery_passes.c:291
 bch2_fs_recovery+0x292a/0x3e20 fs/bcachefs/recovery.c:936
 bch2_fs_start+0x37c/0x620 fs/bcachefs/super.c:1057
 bch2_fs_get_tree+0x1270/0x18d0 fs/bcachefs/fs.c:2253
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3878
 do_mount fs/namespace.c:4218 [inline]
 __do_sys_mount fs/namespace.c:4429 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4406
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff88804204e000
 which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 176 bytes inside of
 freed 4096-byte region [ffff88804204e000, ffff88804204f000)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x42048
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x4fff00000000040(head|node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000040 ffff88801b042140 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 04fff00000000040 ffff88801b042140 dead000000000100 dead000000000122
head: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 04fff00000000003 ffffea0001081201 ffffffffffffffff 0000000000000000
head: 0000000000000008 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4732, tgid 4732 (udevd), ts 32610770584, free_ts 32607855029
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1f4/0x240 mm/page_alloc.c:1551
 prep_new_page mm/page_alloc.c:1559 [inline]
 get_page_from_freelist+0x3695/0x37e0 mm/page_alloc.c:3477
 __alloc_frozen_pages_noprof+0x2c5/0x7b0 mm/page_alloc.c:4740
 alloc_pages_mpol+0x339/0x690 mm/mempolicy.c:2301
 alloc_slab_page mm/slub.c:2446 [inline]
 allocate_slab+0x8f/0x3a0 mm/slub.c:2610
 new_slab mm/slub.c:2663 [inline]
 ___slab_alloc+0xc3b/0x1500 mm/slub.c:3849
 __slab_alloc+0x58/0xa0 mm/slub.c:3939
 __slab_alloc_node mm/slub.c:4014 [inline]
 slab_alloc_node mm/slub.c:4175 [inline]
 __do_kmalloc_node mm/slub.c:4317 [inline]
 __kmalloc_noprof+0x2ea/0x4d0 mm/slub.c:4330
 kmalloc_noprof include/linux/slab.h:906 [inline]
 tomoyo_realpath_from_path+0xcf/0x5e0 security/tomoyo/realpath.c:251
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_check_open_permission+0x25a/0x4f0 security/tomoyo/file.c:771
 security_file_open+0xac/0x250 security/security.c:3114
 do_dentry_open+0x320/0x1960 fs/open.c:933
 vfs_open+0x3b/0x370 fs/open.c:1086
 do_open fs/namei.c:3845 [inline]
 path_openat+0x2caf/0x35d0 fs/namei.c:4004
 do_filp_open+0x284/0x4e0 fs/namei.c:4031
 do_sys_openat2+0x12b/0x1d0 fs/open.c:1429
page last free pid 4732 tgid 4732 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1127 [inline]
 free_frozen_pages+0xe16/0x10f0 mm/page_alloc.c:2660
 discard_slab mm/slub.c:2707 [inline]
 __put_partials+0x160/0x1c0 mm/slub.c:3176
 put_cpu_partial+0x17e/0x250 mm/slub.c:3251
 __slab_free+0x294/0x390 mm/slub.c:4503
 qlink_free mm/kasan/quarantine.c:163 [inline]
 qlist_free_all+0x9a/0x140 mm/kasan/quarantine.c:179
 kasan_quarantine_reduce+0x14f/0x170 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x23/0x80 mm/kasan/common.c:329
 kasan_slab_alloc include/linux/kasan.h:250 [inline]
 slab_post_alloc_hook mm/slub.c:4138 [inline]
 slab_alloc_node mm/slub.c:4187 [inline]
 kmem_cache_alloc_noprof+0x1e1/0x390 mm/slub.c:4194
 getname_flags+0xb6/0x530 fs/namei.c:146
 getname include/linux/fs.h:2852 [inline]
 do_sys_openat2+0xbf/0x1d0 fs/open.c:1423
 do_sys_open fs/open.c:1444 [inline]
 __do_sys_openat fs/open.c:1460 [inline]
 __se_sys_openat fs/open.c:1455 [inline]
 __x64_sys_openat+0x249/0x2a0 fs/open.c:1455
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff88804204df80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff88804204e000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88804204e080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                     ^
 ffff88804204e100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88804204e180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================