syzbot


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

Status: fixed on 2024/06/11 03:41
Subsystems: bcachefs
[Documentation on labels]
Reported-by: syzbot+a0ddc9873c280a4cb18f@syzkaller.appspotmail.com
Fix commit: d93ff5fa40b9 bcachefs: Fix race path in bch2_inode_insert()
First crash: 149d, last: 149d
Cause bisection: introduced by (bisect log) :
commit 0e42f381193d7f9b47922f1c4308e7729a45ba13
Author: Kent Overstreet <kent.overstreet@linux.dev>
Date: Sun Apr 21 02:26:47 2024 +0000

  bcachefs: Fix inode early destruction path

Crash: KASAN: slab-use-after-free Read in evict_inodes (log)
Repro: C syz .config
  
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [bcachefs?] KASAN: slab-use-after-free Read in evict_inodes 0 (1) 2024/05/13 15:44
Last patch testing requests (1)
Created Duration User Patch Repo Result
2024/05/23 18:57 44m retest repro upstream OK log

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in evict_inodes+0x111/0x690
Read of size 8 at addr ffff888075cc70e0 by task syz-executor647/5099

CPU: 0 PID: 5099 Comm: syz-executor647 Not tainted 6.9.0-rc7-syzkaller-00056-g45db3ab70092 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0x169/0x550 mm/kasan/report.c:488
 kasan_report+0x143/0x180 mm/kasan/report.c:601
 evict_inodes+0x111/0x690
 generic_shutdown_super+0x9d/0x2d0 fs/super.c:626
 bch2_kill_sb+0x41/0x50 fs/bcachefs/fs.c:2012
 deactivate_locked_super+0xc4/0x130 fs/super.c:472
 cleanup_mnt+0x426/0x4c0 fs/namespace.c:1267
 task_work_run+0x24f/0x310 kernel/task_work.c:180
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
 exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
 __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
 syscall_exit_to_user_mode+0x168/0x370 kernel/entry/common.c:218
 do_syscall_64+0x102/0x240 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f9d14a95cb7
Code: 09 00 48 83 c4 08 5b 5d c3 66 2e 0f 1f 84 00 00 00 00 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 c7 c2 b0 ff ff ff f7 d8 64 89 02 b8
RSP: 002b:00007ffd534829a8 EFLAGS: 00000202 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00007f9d14a95cb7
RDX: 0000000000000000 RSI: 0000000000000009 RDI: 00007ffd53482a60
RBP: 00007ffd53482a60 R08: 0000000000000000 R09: 0000000000000000
R10: 00000000ffffffff R11: 0000000000000202 R12: 00007ffd53483b20
R13: 0000555567b26700 R14: 431bde82d7b634db R15: 00007ffd53483ac4
 </TASK>

Allocated by task 8194:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 unpoison_slab_object mm/kasan/common.c:312 [inline]
 __kasan_slab_alloc+0x66/0x80 mm/kasan/common.c:338
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3804 [inline]
 slab_alloc_node mm/slub.c:3851 [inline]
 kmem_cache_alloc+0x174/0x350 mm/slub.c:3858
 bch2_alloc_inode+0x1f/0x130 fs/bcachefs/fs.c:1494
 alloc_inode fs/inode.c:261 [inline]
 new_inode_pseudo+0x69/0x1e0 fs/inode.c:1007
 new_inode+0x22/0x1d0 fs/inode.c:1033
 bch2_new_inode+0xa7/0x1a0 fs/bcachefs/fs.c:224
 bch2_lookup_trans fs/bcachefs/fs.c:408 [inline]
 bch2_lookup+0xc44/0x1330 fs/bcachefs/fs.c:437
 lookup_open fs/namei.c:3475 [inline]
 open_last_lookups fs/namei.c:3566 [inline]
 path_openat+0x1033/0x3240 fs/namei.c:3796
 do_filp_open+0x235/0x490 fs/namei.c:3826
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1406
 do_sys_open fs/open.c:1421 [inline]
 __do_sys_openat fs/open.c:1437 [inline]
 __se_sys_openat fs/open.c:1432 [inline]
 __x64_sys_openat+0x247/0x2a0 fs/open.c:1432
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 8194:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579
 poison_slab_object+0xa6/0xe0 mm/kasan/common.c:240
 __kasan_slab_free+0x37/0x60 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2111 [inline]
 slab_free mm/slub.c:4286 [inline]
 kmem_cache_free+0x10b/0x2d0 mm/slub.c:4350
 bch2_inode_insert+0x339/0x3a0 fs/bcachefs/fs.c:192
 bch2_lookup_trans fs/bcachefs/fs.c:420 [inline]
 bch2_lookup+0xdf0/0x1330 fs/bcachefs/fs.c:437
 lookup_open fs/namei.c:3475 [inline]
 open_last_lookups fs/namei.c:3566 [inline]
 path_openat+0x1033/0x3240 fs/namei.c:3796
 do_filp_open+0x235/0x490 fs/namei.c:3826
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1406
 do_sys_open fs/open.c:1421 [inline]
 __do_sys_openat fs/open.c:1437 [inline]
 __se_sys_openat fs/open.c:1432 [inline]
 __x64_sys_openat+0x247/0x2a0 fs/open.c:1432
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff888075cc6f18
 which belongs to the cache bch_inode_info of size 1768
The buggy address is located 456 bytes inside of
 freed 1768-byte region [ffff888075cc6f18, ffff888075cc7600)

The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888075cc0768 pfn:0x75cc0
head: order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff88801af46c80 ffffea0001da0c00 0000000000000002
raw: ffff888075cc0768 0000000080110010 00000001ffffffff 0000000000000000
head: 00fff00000000840 ffff88801af46c80 ffffea0001da0c00 0000000000000002
head: ffff888075cc0768 0000000080110010 00000001ffffffff 0000000000000000
head: 00fff00000000003 ffffea0001d73001 dead000000000122 00000000ffffffff
head: 0000000800000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Reclaimable, gfp_mask 0xd2050(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_RECLAIMABLE), pid 5468, tgid -1659749701 (syz-executor647), ts 5469, free_ts 597295756743
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1ea/0x210 mm/page_alloc.c:1534
 prep_new_page mm/page_alloc.c:1541 [inline]
 get_page_from_freelist+0x3410/0x35b0 mm/page_alloc.c:3317
 __alloc_pages+0x256/0x6c0 mm/page_alloc.c:4575
 __alloc_pages_node include/linux/gfp.h:238 [inline]
 alloc_pages_node include/linux/gfp.h:261 [inline]
 alloc_slab_page+0x5f/0x160 mm/slub.c:2180
 allocate_slab mm/slub.c:2343 [inline]
 new_slab+0x84/0x2f0 mm/slub.c:2396
 ___slab_alloc+0xc73/0x1260 mm/slub.c:3530
 __slab_alloc mm/slub.c:3615 [inline]
 __slab_alloc_node mm/slub.c:3668 [inline]
 slab_alloc_node mm/slub.c:3841 [inline]
 kmem_cache_alloc+0x252/0x350 mm/slub.c:3858
 bch2_alloc_inode+0x1f/0x130 fs/bcachefs/fs.c:1494
 alloc_inode fs/inode.c:261 [inline]
 new_inode_pseudo+0x69/0x1e0 fs/inode.c:1007
 new_inode+0x22/0x1d0 fs/inode.c:1033
 bch2_new_inode+0xa7/0x1a0 fs/bcachefs/fs.c:224
 bch2_lookup_trans fs/bcachefs/fs.c:408 [inline]
 bch2_lookup+0xc44/0x1330 fs/bcachefs/fs.c:437
 lookup_open fs/namei.c:3475 [inline]
 open_last_lookups fs/namei.c:3566 [inline]
 path_openat+0x1033/0x3240 fs/namei.c:3796
 do_filp_open+0x235/0x490 fs/namei.c:3826
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1406
 do_sys_open fs/open.c:1421 [inline]
 __do_sys_openat fs/open.c:1437 [inline]
 __se_sys_openat fs/open.c:1432 [inline]
 __x64_sys_openat+0x247/0x2a0 fs/open.c:1432
page last free pid 5099 tgid 5099 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1141 [inline]
 free_unref_page_prepare+0x97b/0xaa0 mm/page_alloc.c:2347
 free_unref_page+0x37/0x3f0 mm/page_alloc.c:2487
 vfree+0x186/0x2e0 mm/vmalloc.c:3340
 bch2_fs_btree_write_buffer_exit+0x140/0x1b0 fs/bcachefs/btree_write_buffer.c:652
 __bch2_fs_free fs/bcachefs/super.c:573 [inline]
 bch2_fs_release+0x2c7/0x5a0 fs/bcachefs/super.c:610
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x22f/0x480 lib/kobject.c:737
 deactivate_locked_super+0xc4/0x130 fs/super.c:472
 cleanup_mnt+0x426/0x4c0 fs/namespace.c:1267
 task_work_run+0x24f/0x310 kernel/task_work.c:180
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
 exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
 __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
 syscall_exit_to_user_mode+0x168/0x370 kernel/entry/common.c:218
 do_syscall_64+0x102/0x240 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff888075cc6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888075cc7000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888075cc7080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                       ^
 ffff888075cc7100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888075cc7180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/05/09 18:35 upstream 45db3ab70092 05079661 .config console log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-upstream-fs KASAN: slab-use-after-free Read in evict_inodes
2024/05/09 15:34 upstream 45db3ab70092 05079661 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: slab-use-after-free Read in evict_inodes
* Struck through repros no longer work on HEAD.