bp_start 8 incorrectly set at freespace:0:40:0 (free 0, genbits 0 should be 0), fixing ================================================================== BUG: KASAN: slab-use-after-free in bch2_bucket_alloc_trans+0x1308/0x1a7c fs/bcachefs/alloc_foreground.c:547 Read of size 8 at addr ffff0000e9270520 by task syz.3.192/7532 CPU: 1 UID: 0 PID: 7532 Comm: syz.3.192 Not tainted 6.16.0-rc2-syzkaller-g9aa9b43d689e #0 PREEMPT Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025 Call trace: show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:501 (C) __dump_stack+0x30/0x40 lib/dump_stack.c:94 dump_stack_lvl+0xd8/0x12c lib/dump_stack.c:120 print_address_description+0xa8/0x254 mm/kasan/report.c:408 print_report+0x68/0x84 mm/kasan/report.c:521 kasan_report+0xb0/0x110 mm/kasan/report.c:634 __asan_report_load8_noabort+0x20/0x2c mm/kasan/report_generic.c:381 bch2_bucket_alloc_trans+0x1308/0x1a7c fs/bcachefs/alloc_foreground.c:547 bch2_bucket_alloc_set_trans+0x490/0x9cc fs/bcachefs/alloc_foreground.c:728 __open_bucket_add_buckets+0x10a4/0x1954 fs/bcachefs/alloc_foreground.c:925 open_bucket_add_buckets+0x314/0x3d0 fs/bcachefs/alloc_foreground.c:957 bch2_alloc_sectors_start_trans+0xa54/0x1880 fs/bcachefs/alloc_foreground.c:-1 __bch2_btree_node_alloc fs/bcachefs/btree_update_interior.c:320 [inline] bch2_btree_reserve_get+0x4ec/0xe80 fs/bcachefs/btree_update_interior.c:534 bch2_btree_update_start+0x1130/0x1a68 fs/bcachefs/btree_update_interior.c:1270 bch2_btree_split_leaf+0x118/0x71c fs/bcachefs/btree_update_interior.c:1920 bch2_trans_commit_error+0x17c/0x11a0 fs/bcachefs/btree_trans_commit.c:911 __bch2_trans_commit+0x1888/0x6198 fs/bcachefs/btree_trans_commit.c:1098 bch2_trans_commit fs/bcachefs/btree_update.h:242 [inline] bch2_journal_replay+0xfec/0x1c3c fs/bcachefs/recovery.c:396 bch2_run_recovery_pass fs/bcachefs/recovery_passes.c:485 [inline] __bch2_run_recovery_passes+0x29c/0xd18 fs/bcachefs/recovery_passes.c:540 bch2_run_recovery_passes+0x174/0x1f4 fs/bcachefs/recovery_passes.c:611 bch2_fs_recovery+0x1d60/0x2fa8 fs/bcachefs/recovery.c:989 bch2_fs_start+0x914/0xbc0 fs/bcachefs/super.c:1203 bch2_fs_get_tree+0x890/0x1048 fs/bcachefs/fs.c:2489 vfs_get_tree+0x90/0x28c fs/super.c:1802 do_new_mount+0x228/0x814 fs/namespace.c:3885 path_mount+0x5b4/0xde0 fs/namespace.c:4209 do_mount fs/namespace.c:4222 [inline] __do_sys_mount fs/namespace.c:4433 [inline] __se_sys_mount fs/namespace.c:4410 [inline] __arm64_sys_mount+0x3e8/0x468 fs/namespace.c:4410 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151 el0_svc+0x58/0x17c arch/arm64/kernel/entry-common.c:767 el0t_64_sync_handler+0x78/0x108 arch/arm64/kernel/entry-common.c:786 el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:600 Allocated by task 7532: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x40/0x78 mm/kasan/common.c:68 kasan_save_alloc_info+0x44/0x54 mm/kasan/generic.c:562 poison_kmalloc_redzone mm/kasan/common.c:377 [inline] __kasan_kmalloc+0x9c/0xb4 mm/kasan/common.c:394 kasan_kmalloc include/linux/kasan.h:260 [inline] __do_kmalloc_node mm/slub.c:4328 [inline] __kmalloc_node_track_caller_noprof+0x304/0x4d0 mm/slub.c:4347 __do_krealloc mm/slub.c:4905 [inline] krealloc_noprof+0x11c/0x2f0 mm/slub.c:4958 __bch2_trans_kmalloc+0x1f4/0xb8c fs/bcachefs/btree_iter.c:3187 bch2_trans_kmalloc_nomemzero_ip fs/bcachefs/btree_iter.h:586 [inline] bch2_trans_kmalloc_nomemzero+0xe4/0x13c fs/bcachefs/btree_iter.h:621 bch2_alloc_sectors_start_trans+0x78/0x1880 fs/bcachefs/alloc_foreground.c:1250 __bch2_btree_node_alloc fs/bcachefs/btree_update_interior.c:320 [inline] bch2_btree_reserve_get+0x4ec/0xe80 fs/bcachefs/btree_update_interior.c:534 bch2_btree_update_start+0x1130/0x1a68 fs/bcachefs/btree_update_interior.c:1270 bch2_btree_split_leaf+0x118/0x71c fs/bcachefs/btree_update_interior.c:1920 bch2_trans_commit_error+0x17c/0x11a0 fs/bcachefs/btree_trans_commit.c:911 __bch2_trans_commit+0x1888/0x6198 fs/bcachefs/btree_trans_commit.c:1098 bch2_trans_commit fs/bcachefs/btree_update.h:242 [inline] bch2_journal_replay+0xfec/0x1c3c fs/bcachefs/recovery.c:396 bch2_run_recovery_pass fs/bcachefs/recovery_passes.c:485 [inline] __bch2_run_recovery_passes+0x29c/0xd18 fs/bcachefs/recovery_passes.c:540 bch2_run_recovery_passes+0x174/0x1f4 fs/bcachefs/recovery_passes.c:611 bch2_fs_recovery+0x1d60/0x2fa8 fs/bcachefs/recovery.c:989 bch2_fs_start+0x914/0xbc0 fs/bcachefs/super.c:1203 bch2_fs_get_tree+0x890/0x1048 fs/bcachefs/fs.c:2489 vfs_get_tree+0x90/0x28c fs/super.c:1802 do_new_mount+0x228/0x814 fs/namespace.c:3885 path_mount+0x5b4/0xde0 fs/namespace.c:4209 do_mount fs/namespace.c:4222 [inline] __do_sys_mount fs/namespace.c:4433 [inline] __se_sys_mount fs/namespace.c:4410 [inline] __arm64_sys_mount+0x3e8/0x468 fs/namespace.c:4410 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151 el0_svc+0x58/0x17c arch/arm64/kernel/entry-common.c:767 el0t_64_sync_handler+0x78/0x108 arch/arm64/kernel/entry-common.c:786 el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:600 Freed by task 7532: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x40/0x78 mm/kasan/common.c:68 kasan_save_free_info+0x58/0x70 mm/kasan/generic.c:576 poison_slab_object mm/kasan/common.c:247 [inline] __kasan_slab_free+0x68/0x88 mm/kasan/common.c:264 kasan_slab_free include/linux/kasan.h:233 [inline] slab_free_hook mm/slub.c:2381 [inline] slab_free mm/slub.c:4643 [inline] kfree+0x17c/0x474 mm/slub.c:4842 krealloc_noprof+0x214/0x2f0 mm/slub.c:-1 __bch2_trans_kmalloc+0x1f4/0xb8c fs/bcachefs/btree_iter.c:3187 bch2_trans_kmalloc_nomemzero_ip fs/bcachefs/btree_iter.h:586 [inline] bch2_trans_kmalloc_nomemzero+0xf8/0x150 fs/bcachefs/btree_iter.h:621 __bch2_trans_subbuf_alloc+0xe0/0x2a0 fs/bcachefs/btree_update.c:557 bch2_trans_subbuf_alloc fs/bcachefs/btree_update.h:148 [inline] bch2_trans_jset_entry_alloc fs/bcachefs/btree_update.h:168 [inline] __bch2_trans_log_str fs/bcachefs/btree_update.c:814 [inline] bch2_trans_log_str+0xb4/0x308 fs/bcachefs/btree_update.c:827 __bch2_fsck_err+0x94c/0xe68 fs/bcachefs/error.c:625 bch2_check_discard_freespace_key+0x5b8/0xb14 fs/bcachefs/alloc_background.c:1436 try_alloc_bucket fs/bcachefs/alloc_foreground.c:272 [inline] bch2_bucket_alloc_freelist fs/bcachefs/alloc_foreground.c:420 [inline] bch2_bucket_alloc_trans+0xcec/0x1a7c fs/bcachefs/alloc_foreground.c:544 bch2_bucket_alloc_set_trans+0x490/0x9cc fs/bcachefs/alloc_foreground.c:728 __open_bucket_add_buckets+0x10a4/0x1954 fs/bcachefs/alloc_foreground.c:925 open_bucket_add_buckets+0x314/0x3d0 fs/bcachefs/alloc_foreground.c:957 bch2_alloc_sectors_start_trans+0xa54/0x1880 fs/bcachefs/alloc_foreground.c:-1 __bch2_btree_node_alloc fs/bcachefs/btree_update_interior.c:320 [inline] bch2_btree_reserve_get+0x4ec/0xe80 fs/bcachefs/btree_update_interior.c:534 bch2_btree_update_start+0x1130/0x1a68 fs/bcachefs/btree_update_interior.c:1270 bch2_btree_split_leaf+0x118/0x71c fs/bcachefs/btree_update_interior.c:1920 bch2_trans_commit_error+0x17c/0x11a0 fs/bcachefs/btree_trans_commit.c:911 __bch2_trans_commit+0x1888/0x6198 fs/bcachefs/btree_trans_commit.c:1098 bch2_trans_commit fs/bcachefs/btree_update.h:242 [inline] bch2_journal_replay+0xfec/0x1c3c fs/bcachefs/recovery.c:396 bch2_run_recovery_pass fs/bcachefs/recovery_passes.c:485 [inline] __bch2_run_recovery_passes+0x29c/0xd18 fs/bcachefs/recovery_passes.c:540 bch2_run_recovery_passes+0x174/0x1f4 fs/bcachefs/recovery_passes.c:611 bch2_fs_recovery+0x1d60/0x2fa8 fs/bcachefs/recovery.c:989 bch2_fs_start+0x914/0xbc0 fs/bcachefs/super.c:1203 bch2_fs_get_tree+0x890/0x1048 fs/bcachefs/fs.c:2489 vfs_get_tree+0x90/0x28c fs/super.c:1802 do_new_mount+0x228/0x814 fs/namespace.c:3885 path_mount+0x5b4/0xde0 fs/namespace.c:4209 do_mount fs/namespace.c:4222 [inline] __do_sys_mount fs/namespace.c:4433 [inline] __se_sys_mount fs/namespace.c:4410 [inline] __arm64_sys_mount+0x3e8/0x468 fs/namespace.c:4410 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151 el0_svc+0x58/0x17c arch/arm64/kernel/entry-common.c:767 el0t_64_sync_handler+0x78/0x108 arch/arm64/kernel/entry-common.c:786 el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:600 The buggy address belongs to the object at ffff0000e9270400 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 288 bytes inside of freed 512-byte region [ffff0000e9270400, ffff0000e9270600) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x129270 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x5ffc00000000040(head|node=0|zone=2|lastcpupid=0x7ff) page_type: f5(slab) raw: 05ffc00000000040 ffff0000c0001c80 dead000000000122 0000000000000000 raw: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000 head: 05ffc00000000040 ffff0000c0001c80 dead000000000122 0000000000000000 head: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000 head: 05ffc00000000002 fffffdffc3a49c01 00000000ffffffff 00000000ffffffff head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff0000e9270400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff0000e9270480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff0000e9270500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff0000e9270580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff0000e9270600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ================================================================== bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:36:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:36:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:40:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:40:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:36:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:36:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:40:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:40:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:36:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:36:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:40:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:40:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:36:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:36:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:40:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:40:0 (free 0, genbits 0 should be 0), fixing bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): u64s 13 type alloc_v4 0:36:0 len 0 ver 0: gen 0 oldest_gen 0 data_type btree journal_seq_nonempty 0 journal_seq_empty 0 need_discard 0 need_inc_gen 0 dirty_sectors 256 stripe_sectors 0 cached_sectors 0 stripe 0 stripe_redundancy 0 io_time[READ] 0 io_time[WRITE] 0 fragmentation 0 bp_start 8 incorrectly set at freespace:0:36:0 (free 0, genbits 0 should be 0), fixing Ratelimiting new instances of previous error bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): bch2_journal_replay(): error journal_shutdown bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): error in recovery: journal_shutdown bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): bch2_fs_start(): error starting filesystem journal_shutdown bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): shutting down bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): going read-only bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): finished waiting for writes to stop bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): flushing journal and stopping allocators, journal seq 9 bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): flushing journal and stopping allocators complete, journal seq 9 bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): unclean shutdown complete, journal seq 9 bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): done going read-only, filesystem not clean bcachefs (a46a46fb-710c-4d8a-8a40-d337fbcdfe7d): shutdown complete bcachefs: bch2_fs_get_tree() error: journal_shutdown