bcachefs (loop0): reading snapshots done
bcachefs (loop0): done starting filesystem
==================================================================
BUG: KASAN: slab-out-of-bounds in bch2_dirent_init_name+0x396/0x8b0 fs/bcachefs/dirent.c:276
Write of size 1985 at addr ffff8880412dc22f by task syz.0.17/6001

CPU: 0 UID: 0 PID: 6001 Comm: syz.0.17 Not tainted 6.17.0-rc1-syzkaller-00036-gdfc0f6373094-dirty #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:378 [inline]
 print_report+0xca/0x240 mm/kasan/report.c:482
 kasan_report+0x118/0x150 mm/kasan/report.c:595
 check_region_inline mm/kasan/generic.c:-1 [inline]
 kasan_check_range+0x2b0/0x2c0 mm/kasan/generic.c:189
 __asan_memset+0x22/0x50 mm/kasan/shadow.c:84
 bch2_dirent_init_name+0x396/0x8b0 fs/bcachefs/dirent.c:276
 bch2_dirent_create_key+0x2a1/0x5f0 fs/bcachefs/dirent.c:319
 bch2_dirent_create+0xc5/0xc80 fs/bcachefs/dirent.c:362
 bch2_link_trans+0x39e/0x560 fs/bcachefs/namei.c:241
 __bch2_link+0x231/0x3f0 fs/bcachefs/fs.c:776
 bch2_symlink+0x183/0x240 fs/bcachefs/fs.c:892
 vfs_symlink+0x143/0x2f0 fs/namei.c:4730
 do_symlinkat+0x1b1/0x3f0 fs/namei.c:4756
 __do_sys_symlink fs/namei.c:4777 [inline]
 __se_sys_symlink fs/namei.c:4775 [inline]
 __x64_sys_symlink+0x7a/0x90 fs/namei.c:4775
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f9b7458ebe9
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:00007f9b753ce038 EFLAGS: 00000246 ORIG_RAX: 0000000000000058
RAX: ffffffffffffffda RBX: 00007f9b747b5fa0 RCX: 00007f9b7458ebe9
RDX: 0000000000000000 RSI: 00002000000007c0 RDI: 0000200000000ac0
RBP: 00007f9b74611e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f9b747b6038 R14: 00007f9b747b5fa0 R15: 00007ffdbf58a558
 </TASK>

Allocated by task 6001:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:388 [inline]
 __kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:405
 kasan_kmalloc include/linux/kasan.h:260 [inline]
 __do_kmalloc_node mm/slub.c:4365 [inline]
 __kmalloc_noprof+0x27a/0x4f0 mm/slub.c:4377
 kmalloc_noprof include/linux/slab.h:909 [inline]
 __bch2_trans_kmalloc+0x396/0x9d0 fs/bcachefs/btree_iter.c:3242
 bch2_trans_kmalloc_ip fs/bcachefs/btree_iter.h:604 [inline]
 bch2_trans_kmalloc fs/bcachefs/btree_iter.h:616 [inline]
 bch2_dirent_create_key+0x113/0x5f0 fs/bcachefs/dirent.c:302
 bch2_dirent_create+0xc5/0xc80 fs/bcachefs/dirent.c:362
 bch2_link_trans+0x39e/0x560 fs/bcachefs/namei.c:241
 __bch2_link+0x231/0x3f0 fs/bcachefs/fs.c:776
 bch2_symlink+0x183/0x240 fs/bcachefs/fs.c:892
 vfs_symlink+0x143/0x2f0 fs/namei.c:4730
 do_symlinkat+0x1b1/0x3f0 fs/namei.c:4756
 __do_sys_symlink fs/namei.c:4777 [inline]
 __se_sys_symlink fs/namei.c:4775 [inline]
 __x64_sys_symlink+0x7a/0x90 fs/namei.c:4775
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff8880412dc000
 which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 559 bytes inside of
 allocated 2048-byte region [ffff8880412dc000, ffff8880412dc800)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x412d8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801a442000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080080008 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801a442000 dead000000000122 0000000000000000
head: 0000000000000000 0000000080080008 00000000f5000000 0000000000000000
head: 00fff00000000003 ffffea000104b601 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 6001, tgid 6000 (syz.0.17), ts 64889116556, free_ts 61588185170
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
 prep_new_page mm/page_alloc.c:1859 [inline]
 get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
 __alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
 alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
 alloc_slab_page mm/slub.c:2487 [inline]
 allocate_slab+0x8a/0x370 mm/slub.c:2655
 new_slab mm/slub.c:2709 [inline]
 ___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
 __slab_alloc mm/slub.c:3981 [inline]
 __slab_alloc_node mm/slub.c:4056 [inline]
 slab_alloc_node mm/slub.c:4217 [inline]
 __kmalloc_cache_noprof+0x296/0x3d0 mm/slub.c:4391
 kmalloc_noprof include/linux/slab.h:905 [inline]
 kzalloc_noprof include/linux/slab.h:1039 [inline]
 device_create_groups_vargs drivers/base/core.c:4353 [inline]
 device_create+0x12f/0x2f0 drivers/base/core.c:4410
 bdi_register_va+0x9c/0x740 mm/backing-dev.c:1094
 super_setup_bdi_name+0xe6/0x200 fs/super.c:1874
 bch2_fs_get_tree+0xa83/0x1520 fs/bcachefs/fs.c:2540
 vfs_get_tree+0x92/0x2b0 fs/super.c:1815
 do_new_mount+0x2a2/0x9e0 fs/namespace.c:3805
 do_mount fs/namespace.c:4133 [inline]
 __do_sys_mount fs/namespace.c:4344 [inline]
 __se_sys_mount+0x317/0x410 fs/namespace.c:4321
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 5916 tgid 5916 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1395 [inline]
 __free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
 vfree+0x25a/0x400 mm/vmalloc.c:3434
 kcov_put kernel/kcov.c:439 [inline]
 kcov_close+0x28/0x50 kernel/kcov.c:535
 __fput+0x44c/0xa70 fs/file_table.c:468
 task_work_run+0x1d4/0x260 kernel/task_work.c:227
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0x6b5/0x2300 kernel/exit.c:961
 do_group_exit+0x21c/0x2d0 kernel/exit.c:1102
 get_signal+0x1286/0x1340 kernel/signal.c:3034
 arch_do_signal_or_restart+0x9a/0x750 arch/x86/kernel/signal.c:337
 exit_to_user_mode_loop+0x75/0x110 kernel/entry/common.c:40
 exit_to_user_mode_prepare include/linux/irq-entry-common.h:225 [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

Memory state around the buggy address:
 ffff8880412dc700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff8880412dc780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff8880412dc800: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
                   ^
 ffff8880412dc880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880412dc900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
