node offset 16/24 bset u64s 110 bset byte offset 152: keys out of order: u64s 16 type inode_v3 134217728:4096:U32_MAX len 0 ver 0 > u64s 18 type inode_v3 0:4098:U32_MAX len 0 ver 0, fixing
bcachefs (loop0): invalid bkey in btree_node btree=inodes level=0: u64s 16 type inode_v3 134217728:4096:U32_MAX len 0 ver 0: 
    mode=40755
    flags=(16300000)
    journal_seq=0
    hash_seed=28e4f092a4fc58ee
    hash_type=siphash
    bi_size=0
    bi_sectors=0
    bi_version=0
    bi_atime=200535484
    bi_ctime=2780562352
    bi_mtime=2780562352
    bi_otime=200535484
    bi_uid=0
    bi_gid=0
    bi_nlink=2
    bi_generation=0
    bi_dev=0
    bi_data_checksum=0
    bi_compression=0
    bi_project=0
    bi_background_compression=0
    bi_data_replicas=0
    bi_promote_target=0
    bi_foreground_target=0
    bi_background_target=0
    bi_erasure_code=0
    bi_fields_set=0
    bi_dir=0
    bi_dir_offset=0
    bi_subvol=1
    bi_parent_subvol=0
    bi_nocow=0
    bi_depth=0
    bi_inodes_32bit=0
  nonzero k.p.inode, deleting
bcachefs (loop0): btree_node_read_work: rewriting btree node at due to error
  btree=inodes level=0 u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 7589ab5e0c11cc7a written 24 min_key POS_MIN durability: 1 ptr: 0:38:0 gen 0
bcachefs (loop0): bcachefs (loop0): error validating btree node on loop0 at btree dirents level 0/0
  u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 9aa2895aefce4bdf written 24 min_key POS_MIN durability: 1 ptr: 0:41:0 gen 0
  node offset 16/24: btree node data missing: expected 24 sectors, found 16, fixing
bcachefs (loop0): btree_node_read_work: rewriting btree node at due to error
  btree=dirents level=0 u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq 9aa2895aefce4bdf written 24 min_key POS_MIN durability: 1 ptr: 0:41:0 gen 0
bcachefs (loop0): bcachefs (loop0): error validating btree node at btree alloc level 0/0
  u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq ac62141f8dc7e261 written 24 min_key POS_MIN durability: 1 ptr: 0:26:0 gen 0
  node offset 8/24 bset u64s 375 bset byte offset 184: keys out of order: u64s 11 type alloc_v4 0:32:0 len 0 ver 0 > u64s 11 type alloc_v4 0:2:0 len 0 ver 0, fixing
bcachefs (loop0): btree_node_read_work: rewriting btree node at due to error
  btree=alloc level=0 u64s 11 type btree_ptr_v2 SPOS_MAX len 0 ver 0: seq ac62141f8dc7e261 written 24 min_key POS_MIN durability: 1 ptr: 0:26:0 gen 0
==================================================================
BUG: KASAN: use-after-free in bch2_btree_node_read_done+0x117d/0x6290 fs/bcachefs/btree_io.c:1085
Read of size 8 at addr ffff8880451bc010 by task syz.0.0/5322

CPU: 0 UID: 0 PID: 5322 Comm: syz.0.0 Not tainted 6.15.0-rc3-syzkaller-00008-ga33b5a08cbbd #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
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
 bch2_btree_node_read_done+0x117d/0x6290 fs/bcachefs/btree_io.c:1085
 btree_node_read_work+0x6cb/0x1400 fs/bcachefs/btree_io.c:1366
 bch2_btree_node_read+0x2427/0x29e0 fs/bcachefs/btree_io.c:-1
 __bch2_btree_root_read fs/bcachefs/btree_io.c:1797 [inline]
 bch2_btree_root_read+0x656/0x7e0 fs/bcachefs/btree_io.c:1819
 read_btree_roots+0x3d7/0xa80 fs/bcachefs/recovery.c:581
 bch2_fs_recovery+0x28e4/0x3e20 fs/bcachefs/recovery.c:928
 bch2_fs_start+0x310/0x620 fs/bcachefs/super.c:1065
 bch2_fs_get_tree+0x113e/0x18f0 fs/bcachefs/fs.c:2253
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3881
 do_mount fs/namespace.c:4221 [inline]
 __do_sys_mount fs/namespace.c:4432 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4409
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x210 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fed2938f90a
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:00007fed2a163e68 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007fed2a163ef0 RCX: 00007fed2938f90a
RDX: 00002000000005c0 RSI: 0000200000000180 RDI: 00007fed2a163eb0
RBP: 00002000000005c0 R08: 00007fed2a163ef0 R09: 0000000000000010
R10: 0000000000000010 R11: 0000000000000246 R12: 0000200000000180
R13: 00007fed2a163eb0 R14: 000000000000598c R15: 00002000000001c0
 </TASK>

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x451bc
flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
raw: 04fff00000000000 ffffea0001147008 ffff88801fc3f8e0 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 2, migratetype Reclaimable, gfp_mask 0x452cd0(GFP_KERNEL_ACCOUNT|__GFP_RECLAIMABLE|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5322, tgid 5321 (syz.0.0), ts 78349318679, free_ts 78688109255
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1f4/0x240 mm/page_alloc.c:1718
 prep_new_page mm/page_alloc.c:1726 [inline]
 get_page_from_freelist+0x360a/0x37a0 mm/page_alloc.c:3688
 __alloc_frozen_pages_noprof+0x211/0x5b0 mm/page_alloc.c:4970
 __alloc_pages_noprof+0xa/0x30 mm/page_alloc.c:5004
 __alloc_pages_node_noprof include/linux/gfp.h:284 [inline]
 alloc_pages_node_noprof include/linux/gfp.h:311 [inline]
 ___kmalloc_large_node+0x92/0x210 mm/slub.c:4285
 __kmalloc_large_node_noprof+0x1a/0x80 mm/slub.c:4313
 __do_kmalloc_node mm/slub.c:4329 [inline]
 __kvmalloc_node_noprof+0x7c/0x5a0 mm/slub.c:5026
 btree_node_data_alloc+0xdb/0x260 fs/bcachefs/btree_cache.c:156
 __bch2_btree_node_mem_alloc+0x201/0x420 fs/bcachefs/btree_cache.c:201
 bch2_fs_btree_cache_init+0x27a/0x630 fs/bcachefs/btree_cache.c:656
 bch2_fs_alloc fs/bcachefs/super.c:943 [inline]
 bch2_fs_open+0x2dea/0x32a0 fs/bcachefs/super.c:2216
 bch2_fs_get_tree+0x77b/0x18f0 fs/bcachefs/fs.c:2172
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3881
 do_mount fs/namespace.c:4221 [inline]
 __do_sys_mount fs/namespace.c:4432 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4409
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x210 arch/x86/entry/syscall_64.c:94
page last free pid 5322 tgid 5321 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1262 [inline]
 __free_frozen_pages+0xde8/0x10a0 mm/page_alloc.c:2725
 __folio_put+0x2b5/0x360 mm/swap.c:112
 folio_put include/linux/mm.h:1580 [inline]
 free_large_kmalloc+0x143/0x1e0 mm/slub.c:4781
 kfree+0x216/0x430 mm/slub.c:4849
 btree_bounce_free fs/bcachefs/btree_io.c:112 [inline]
 bch2_btree_node_read_done+0x3da2/0x6290 fs/bcachefs/btree_io.c:1245
 btree_node_read_work+0x6cb/0x1400 fs/bcachefs/btree_io.c:1366
 bch2_btree_node_read+0x2427/0x29e0 fs/bcachefs/btree_io.c:-1
 __bch2_btree_root_read fs/bcachefs/btree_io.c:1797 [inline]
 bch2_btree_root_read+0x656/0x7e0 fs/bcachefs/btree_io.c:1819
 read_btree_roots+0x3d7/0xa80 fs/bcachefs/recovery.c:581
 bch2_fs_recovery+0x28e4/0x3e20 fs/bcachefs/recovery.c:928
 bch2_fs_start+0x310/0x620 fs/bcachefs/super.c:1065
 bch2_fs_get_tree+0x113e/0x18f0 fs/bcachefs/fs.c:2253
 vfs_get_tree+0x90/0x2b0 fs/super.c:1759
 do_new_mount+0x2cf/0xb70 fs/namespace.c:3881
 do_mount fs/namespace.c:4221 [inline]
 __do_sys_mount fs/namespace.c:4432 [inline]
 __se_sys_mount+0x38c/0x400 fs/namespace.c:4409
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x210 arch/x86/entry/syscall_64.c:94

Memory state around the buggy address:
 ffff8880451bbf00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff8880451bbf80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff8880451bc000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                         ^
 ffff8880451bc080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff8880451bc100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================