u64s 7 type dirent 4096:2719903203128567385:U32_MAX len 0 ver 0: file0 -> 4098 type dir, fixing bcachefs (loop3): dirent points to missing inode: u64s 7 type dirent 4096:3048722928926641700:U32_MAX len 0 ver 0: file2 -> 536870913 type reg, fixing ================================================================== BUG: KASAN: use-after-free in check_dirent+0x25b0/0x25c0 fs/bcachefs/fsck.c:2205 Read of size 1 at addr ffff888051e83048 by task syz.3.126/6312 CPU: 0 UID: 0 PID: 6312 Comm: syz.3.126 Not tainted 6.15.0-rc1-syzkaller-00065-g3b07108ada81 #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2025 Call Trace: __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:408 [inline] print_report+0xc3/0x670 mm/kasan/report.c:521 kasan_report+0xe0/0x110 mm/kasan/report.c:634 check_dirent+0x25b0/0x25c0 fs/bcachefs/fsck.c:2205 bch2_check_dirents+0x405/0x780 fs/bcachefs/fsck.c:2230 bch2_run_recovery_pass+0x91/0x1a0 fs/bcachefs/recovery_passes.c:226 bch2_run_recovery_passes+0x403/0x900 fs/bcachefs/recovery_passes.c:285 bch2_fs_recovery+0x296d/0x43e0 fs/bcachefs/recovery.c:936 bch2_fs_start+0x334/0x6c0 fs/bcachefs/super.c:1069 bch2_fs_get_tree+0xf0d/0x17f0 fs/bcachefs/fs.c:2253 vfs_get_tree+0x8e/0x340 fs/super.c:1759 do_new_mount fs/namespace.c:3879 [inline] path_mount+0x14d4/0x1f30 fs/namespace.c:4206 do_mount fs/namespace.c:4219 [inline] __do_sys_mount fs/namespace.c:4430 [inline] __se_sys_mount fs/namespace.c:4407 [inline] __x64_sys_mount+0x28d/0x310 fs/namespace.c:4407 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xcd/0x260 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f2737d8e90a Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 de 1a 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 00 00 00 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:00007f2738ca8e68 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 RAX: ffffffffffffffda RBX: 00007f2738ca8ef0 RCX: 00007f2737d8e90a RDX: 0000200000000000 RSI: 0000200000000040 RDI: 00007f2738ca8eb0 RBP: 0000200000000000 R08: 00007f2738ca8ef0 R09: 0000000001000001 R10: 0000000001000001 R11: 0000000000000246 R12: 0000200000000040 R13: 00007f2738ca8eb0 R14: 0000000000005968 R15: 0000200000000300 The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x51e83 flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000000000 0000000000000000 dead000000000122 0000000000000000 raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected page_owner tracks the page as freed page last allocated via order 5, migratetype Unmovable, gfp_mask 0x52800(GFP_NOWAIT|__GFP_NORETRY|__GFP_COMP), pid 6312, tgid 6310 (syz.3.126), ts 152357526979, free_ts 157603584652 set_page_owner include/linux/page_owner.h:32 [inline] post_alloc_hook+0x181/0x1b0 mm/page_alloc.c:1717 prep_new_page mm/page_alloc.c:1725 [inline] get_page_from_freelist+0x1193/0x39b0 mm/page_alloc.c:3652 __alloc_frozen_pages_noprof+0x263/0x23a0 mm/page_alloc.c:4934 __alloc_pages_noprof+0xb/0x1b0 mm/page_alloc.c:4968 __alloc_pages_node_noprof include/linux/gfp.h:284 [inline] alloc_pages_node_noprof include/linux/gfp.h:311 [inline] ___kmalloc_large_node+0x82/0x1e0 mm/slub.c:4275 __kmalloc_large_node_noprof+0x1c/0x70 mm/slub.c:4303 __do_kmalloc_node mm/slub.c:4319 [inline] __kvmalloc_node_noprof.cold+0xb/0x65 mm/slub.c:5016 btree_bounce_alloc+0x11e/0x210 fs/bcachefs/btree_io.c:124 bch2_btree_node_read_done+0xeba/0x4c90 fs/bcachefs/btree_io.c:1224 btree_node_read_work+0x5ee/0xe90 fs/bcachefs/btree_io.c:1366 bch2_btree_node_read+0x8c5/0xe90 fs/bcachefs/btree_io.c:1756 __bch2_btree_root_read fs/bcachefs/btree_io.c:1797 [inline] bch2_btree_root_read+0x2d1/0x470 fs/bcachefs/btree_io.c:1819 read_btree_roots fs/bcachefs/recovery.c:581 [inline] bch2_fs_recovery+0x2031/0x43e0 fs/bcachefs/recovery.c:928 bch2_fs_start+0x334/0x6c0 fs/bcachefs/super.c:1069 bch2_fs_get_tree+0xf0d/0x17f0 fs/bcachefs/fs.c:2253 vfs_get_tree+0x8e/0x340 fs/super.c:1759 page last free pid 6312 tgid 6310 stack trace: reset_page_owner include/linux/page_owner.h:25 [inline] free_pages_prepare mm/page_alloc.c:1262 [inline] __free_pages_ok+0x647/0xe70 mm/page_alloc.c:1437 __folio_put+0x329/0x450 mm/swap.c:112 btree_bounce_free fs/bcachefs/btree_io.c:112 [inline] btree_node_sort+0xfe7/0x1580 fs/bcachefs/btree_io.c:380 bch2_btree_post_write_cleanup fs/bcachefs/btree_io.c:2508 [inline] bch2_btree_post_write_cleanup+0x145/0x600 fs/bcachefs/btree_io.c:2482 bch2_btree_node_prep_for_write+0x356/0x550 fs/bcachefs/btree_trans_commit.c:93 bch2_trans_lock_write+0x695/0x8c0 fs/bcachefs/btree_trans_commit.c:129 do_bch2_trans_commit fs/bcachefs/btree_trans_commit.c:840 [inline] __bch2_trans_commit+0x2c9c/0x86f0 fs/bcachefs/btree_trans_commit.c:1050 bch2_trans_commit fs/bcachefs/btree_update.h:195 [inline] check_dirent+0xf2b/0x25c0 fs/bcachefs/fsck.c:2200 bch2_check_dirents+0x405/0x780 fs/bcachefs/fsck.c:2230 bch2_run_recovery_pass+0x91/0x1a0 fs/bcachefs/recovery_passes.c:226 bch2_run_recovery_passes+0x403/0x900 fs/bcachefs/recovery_passes.c:285 bch2_fs_recovery+0x296d/0x43e0 fs/bcachefs/recovery.c:936 bch2_fs_start+0x334/0x6c0 fs/bcachefs/super.c:1069 bch2_fs_get_tree+0xf0d/0x17f0 fs/bcachefs/fs.c:2253 vfs_get_tree+0x8e/0x340 fs/super.c:1759 do_new_mount fs/namespace.c:3879 [inline] path_mount+0x14d4/0x1f30 fs/namespace.c:4206 Memory state around the buggy address: ffff888051e82f00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff888051e82f80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff >ffff888051e83000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ^ ffff888051e83080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff888051e83100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ================================================================== bcachefs (loop3): hash table key at wrong offset: btree dirents inode 4096 offset 4330382808765825483, hashed to 1208608671974777765 u64s 7 type dirent 4096:4330382808765825483:U32_MAX len 0 ver 0: file1 -> 536870912 type reg, fixing bcachefs (loop3): dirent points to missing inode: u64s 7 type dirent 4096:4579665380953333281:U32_MAX len 0 ver 0: file3 -> 536870913 type reg, fixing bcachefs (loop3): hash table key at wrong offset: btree dirents inode 4096 offset 8130059955150870709, hashed to 1665583797225247326 u64s 8 type dirent 4096:8130059955150870709:U32_MAX len 0 ver 0: lost+found -> 4097 type dir, fixing bcachefs (loop3): hash table key at wrong offset: btree dirents inode 4096 offset 9097378837824744618, hashed to 2822959180032846904 u64s 8 type dirent 4096:9097378837824744618:U32_MAX len 0 ver 0: file.cold -> 536870914 type reg, fixing bcachefs (loop3): hash table key at wrong offset: btree dirents inode 4098 offset 5675548428000973578, hashed to 8063074530746542444 u64s 7 type dirent 4098:5675548428000973578:U32_MAX len 0 ver 0: file1 -> 4100 type lnk, fixing bcachefs (loop3): dirent points to missing inode: u64s 7 type dirent 4098:8063074530746542444:U32_MAX len 0 ver 0: file1 -> 4100 type lnk, fixing bcachefs (loop3): hash table key at wrong offset: btree dirents inode 4098 offset 8977922886548783724, hashed to 8816046060028035410 u64s 7 type dirent 4098:8977922886548783724:U32_MAX len 0 ver 0: file0 -> 4099 type reg, fixing done bcachefs (loop3): resume_logged_ops... done bcachefs (loop3): delete_dead_inodes... done bcachefs (loop3): Fixed errors, running fsck a second time to verify fs is clean bcachefs (loop3): check_lrus... done bcachefs (loop3): check_backpointers_to_extents... done bcachefs (loop3): check_inodes... done bcachefs (loop3): check_extents... done bcachefs (loop3): check_dirents... bcachefs (loop3): dirent points to missing inode: u64s 7 type dirent 4096:1208608671974777765:U32_MAX len 0 ver 0: file1 -> 536870912 type reg, fixing bcachefs (loop3): dirent points to missing inode: u64s 8 type dirent 4096:1665583797225247326:U32_MAX len 0 ver 0: lost+found -> 4097 type dir, fixing bcachefs (loop3): dirent points to missing inode: u64s 8 type dirent 4096:2822959180032846904:U32_MAX len 0 ver 0: file.cold -> 536870914 type reg, fixing bcachefs (loop3): fsck counted subdirectories wrong for inum 4096:4294967295: got 1 should be 0 bcachefs (loop3): dirent points to missing inode: u64s 7 type dirent 4098:8816046060028035410:U32_MAX len 0 ver 0: file0 -> 4099 type reg, fixing done bcachefs (loop3): resume_logged_ops... done bcachefs (loop3): delete_dead_inodes... done bcachefs (loop3): Second fsck run was not clean bcachefs (loop3): going read-only bcachefs (loop3): finished waiting for writes to stop bcachefs (loop3): flushing journal and stopping allocators, journal seq 23 bcachefs (loop3): flushing journal and stopping allocators complete, journal seq 23 bcachefs (loop3): clean shutdown complete, journal seq 24 bcachefs (loop3): marking filesystem clean bcachefs (loop3): done starting filesystem syz.3.126 (6312) used greatest stack depth: 17032 bytes left