syzbot


KASAN: slab-use-after-free Read in bch2_copygc

Status: moderation: reported on 2025/06/14 06:29
Subsystems: bcachefs
[Documentation on labels]
Reported-by: syzbot+9fc3ad862a0721dbf65e@syzkaller.appspotmail.com
First crash: 9d14h, last: 5d01h
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KMSAN: uninit-value in bch2_copygc bcachefs C 88 162d 226d 0/29 auto-obsoleted due to no activity on 2025/03/22 22:59
upstream KMSAN: uninit-value in bch2_copygc (2) bcachefs 1 88d 84d 28/29 fixed on 2025/06/10 16:19

Sample crash report:
bcachefs (loop0): Detected missing backpointers in bucket 34, now have 1/128 with missing
  running recovery pass check_extents_to_backpointers (17), currently at check_inodes (28)
==================================================================
BUG: KASAN: slab-use-after-free in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-use-after-free in _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
BUG: KASAN: slab-use-after-free in bch2_bucket_bitmap_test fs/bcachefs/backpointers.h:194 [inline]
BUG: KASAN: slab-use-after-free in bch2_bucket_is_movable fs/bcachefs/movinggc.c:78 [inline]
BUG: KASAN: slab-use-after-free in bch2_copygc_get_buckets fs/bcachefs/movinggc.c:157 [inline]
BUG: KASAN: slab-use-after-free in bch2_copygc+0xfb1/0x4380 fs/bcachefs/movinggc.c:221
Read of size 8 at addr ffff88805548dce0 by task bch-copygc/loop/5349

CPU: 0 UID: 0 PID: 5349 Comm: bch-copygc/loop Not tainted 6.16.0-rc2-syzkaller-00047-g52da431bf03b #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_lvl+0x189/0x250 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:408 [inline]
 print_report+0xd2/0x2b0 mm/kasan/report.c:521
 kasan_report+0x118/0x150 mm/kasan/report.c:634
 check_region_inline mm/kasan/generic.c:-1 [inline]
 kasan_check_range+0x2b0/0x2c0 mm/kasan/generic.c:189
 instrument_atomic_read include/linux/instrumented.h:68 [inline]
 _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
 bch2_bucket_bitmap_test fs/bcachefs/backpointers.h:194 [inline]
 bch2_bucket_is_movable fs/bcachefs/movinggc.c:78 [inline]
 bch2_copygc_get_buckets fs/bcachefs/movinggc.c:157 [inline]
 bch2_copygc+0xfb1/0x4380 fs/bcachefs/movinggc.c:221
 bch2_copygc_thread+0x97a/0xe00 fs/bcachefs/movinggc.c:409
 kthread+0x70e/0x8a0 kernel/kthread.c:464
 ret_from_fork+0x3f9/0x770 arch/x86/kernel/process.c:148
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

Allocated by task 5349:
 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:377 [inline]
 __kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:394
 kasan_kmalloc include/linux/kasan.h:260 [inline]
 __do_kmalloc_node mm/slub.c:4328 [inline]
 __kvmalloc_node_noprof+0x30d/0x5f0 mm/slub.c:5015
 kvmalloc_array_node_noprof include/linux/slab.h:1065 [inline]
 bch2_bucket_bitmap_set+0x9a/0x1a0 fs/bcachefs/backpointers.c:1351
 check_bucket_backpointer_mismatch+0x1bdf/0x23a0 fs/bcachefs/backpointers.c:964
 check_bucket_backpointer_pos_mismatch fs/bcachefs/backpointers.c:1193 [inline]
 bch2_check_bucket_backpointer_mismatch+0x36c/0x690 fs/bcachefs/backpointers.c:1205
 __bch2_move_data_phys+0x17a7/0x1c50 fs/bcachefs/move.c:922
 bch2_evacuate_bucket+0x228/0x3a0 fs/bcachefs/move.c:1082
 bch2_copygc+0x3a89/0x4380 fs/bcachefs/movinggc.c:234
 bch2_copygc_thread+0x97a/0xe00 fs/bcachefs/movinggc.c:409
 kthread+0x70e/0x8a0 kernel/kthread.c:464
 ret_from_fork+0x3f9/0x770 arch/x86/kernel/process.c:148
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

The buggy address belongs to the object at ffff88805548dce0
 which belongs to the cache kmalloc-16 of size 16
The buggy address is located 0 bytes inside of
 freed 16-byte region [ffff88805548dce0, ffff88805548dcf0)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5548d
flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000000 ffff88801a441640 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080800080 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5332, tgid 5331 (syz.0.0), ts 86728673609, free_ts 0
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1704
 prep_new_page mm/page_alloc.c:1712 [inline]
 get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3669
 __alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:4959
 alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2419
 alloc_slab_page mm/slub.c:2451 [inline]
 allocate_slab+0x8a/0x3b0 mm/slub.c:2619
 new_slab mm/slub.c:2673 [inline]
 ___slab_alloc+0xbfc/0x1480 mm/slub.c:3859
 __slab_alloc mm/slub.c:3949 [inline]
 __slab_alloc_node mm/slub.c:4024 [inline]
 slab_alloc_node mm/slub.c:4185 [inline]
 __do_kmalloc_node mm/slub.c:4327 [inline]
 __kmalloc_node_track_caller_noprof+0x2f8/0x4e0 mm/slub.c:4347
 __do_krealloc mm/slub.c:4905 [inline]
 krealloc_noprof+0x124/0x340 mm/slub.c:4958
 bch2_printbuf_make_room+0x1f5/0x360 fs/bcachefs/printbuf.c:59
 bch2_prt_printf+0x282/0x740 fs/bcachefs/printbuf.c:186
 bch2_sb_validate+0xf73/0x1980 fs/bcachefs/super-io.c:514
 bch2_write_super+0xd68/0x2d30 fs/bcachefs/super-io.c:1089
 bch2_fs_mark_dirty+0xa1/0xc0 fs/bcachefs/sb-clean.c:279
 __bch2_fs_read_write+0x52d/0x830 fs/bcachefs/super.c:520
 bch2_fs_read_write_early+0x26/0x40 fs/bcachefs/super.c:576
 bch2_run_recovery_pass fs/bcachefs/recovery_passes.c:485 [inline]
 __bch2_run_recovery_passes+0x395/0x1010 fs/bcachefs/recovery_passes.c:540
page_owner free stack trace missing

Memory state around the buggy address:
 ffff88805548db80: fa fb fc fc fa fb fc fc 00 00 fc fc 00 00 fc fc
 ffff88805548dc00: 00 00 fc fc 00 00 fc fc 00 00 fc fc fa fb fc fc
>ffff88805548dc80: fa fb fc fc fa fb fc fc fa fb fc fc fb fb fc fc
                                                       ^
 ffff88805548dd00: 00 00 fc fc 00 00 fc fc fa fb fc fc fa fb fc fc
 ffff88805548dd80: fa fb fc fc fa fb fc fc 00 00 fc fc 00 00 fc fc
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/06/18 17:47 upstream 52da431bf03b ed3e87f7 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: slab-use-after-free Read in bch2_copygc
2025/06/14 05:22 upstream 18531f4d1c8c 0e8da31f .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: slab-use-after-free Read in bch2_copygc
* Struck through repros no longer work on HEAD.