syzbot


KASAN: use-after-free Read in nilfs_segctor_confirm

Status: upstream: reported C repro on 2022/10/01 13:48
Reported-by: syzbot+b8c672b0e22615c80fe0@syzkaller.appspotmail.com
Fix commit: d325dc6eb763 nilfs2: fix use-after-free bug of struct nilfs_root
Patched on: [ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm32 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-upstream-bpf-kasan-gce ci-upstream-bpf-next-kasan-gce ci-upstream-gce-arm64 ci-upstream-gce-leak ci-upstream-kasan-gce ci-upstream-kasan-gce-386 ci-upstream-kasan-gce-root ci-upstream-kasan-gce-selinux-root ci-upstream-kasan-gce-smack-root ci-upstream-kmsan-gce ci-upstream-kmsan-gce-386 ci-upstream-linux-next-kasan-gce-root ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci2-upstream-fs ci2-upstream-kcsan-gce ci2-upstream-usb], missing on: [ci-qemu2-riscv64]
First crash: 63d, last: 44d

Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: WARNING in account_page_dirtied (log)
Repro: C syz .config
duplicates (7):
Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
KASAN: use-after-free Read in nilfs_test_metadata_dirty C error 61 42d 62d 0/24 closed as dup on 2022/10/04 08:41
KASAN: use-after-free Read in nilfs_iget 2 44d 46d 0/24 closed as dup on 2022/10/21 23:19
KASAN: use-after-free Read in nilfs_permission 4 43d 57d 0/24 closed as dup on 2022/10/11 10:33
WARNING: refcount bug in nilfs_put_root C 68 25d 62d 0/24 closed as dup on 2022/10/04 08:41
BUG: unable to handle kernel paging request in nilfs_mdt_fetch_dirty 1 25d 25d 0/24 closed as dup on 2022/11/08 01:59
KASAN: use-after-free Read in nilfs_load_inode_block 1 54d 53d 0/24 closed as dup on 2022/10/11 10:33
KASAN: use-after-free Read in nilfs_update_inode C error 2 48d 46d 0/24 closed as dup on 2022/10/21 23:19
similar bugs (2):
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 KASAN: use-after-free Read in nilfs_segctor_confirm C 3 4d19h 14d 0/1 upstream: reported C repro on 2022/11/18 14:16
linux-4.14 KASAN: use-after-free Read in nilfs_segctor_confirm C 1 12d 12d 0/1 upstream: reported C repro on 2022/11/20 06:43

Sample crash report:
loop0: detected capacity change from 0 to 2048
==================================================================
BUG: KASAN: use-after-free in nilfs_segctor_confirm+0x175/0x190 fs/nilfs2/segment.c:837
Read of size 8 at addr ffff88801d5c9830 by task syz-executor489/3605

CPU: 0 PID: 3605 Comm: syz-executor489 Not tainted 6.0.0-syzkaller-09589-g55be6084c8e0 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:317 [inline]
 print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
 kasan_report+0xb1/0x1e0 mm/kasan/report.c:495
 nilfs_segctor_confirm+0x175/0x190 fs/nilfs2/segment.c:837
 nilfs_segctor_destroy fs/nilfs2/segment.c:2729 [inline]
 nilfs_detach_log_writer+0x856/0x9f0 fs/nilfs2/segment.c:2810
 nilfs_put_super+0x3f/0x1a0 fs/nilfs2/super.c:468
 generic_shutdown_super+0x154/0x410 fs/super.c:491
 kill_block_super+0x97/0xf0 fs/super.c:1427
 deactivate_locked_super+0x94/0x160 fs/super.c:331
 deactivate_super+0xad/0xd0 fs/super.c:362
 cleanup_mnt+0x2ae/0x3d0 fs/namespace.c:1186
 task_work_run+0xdd/0x1a0 kernel/task_work.c:177
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xb2f/0x2a20 kernel/exit.c:813
 do_group_exit+0xd0/0x2a0 kernel/exit.c:943
 __do_sys_exit_group kernel/exit.c:954 [inline]
 __se_sys_exit_group kernel/exit.c:952 [inline]
 __x64_sys_exit_group+0x3a/0x50 kernel/exit.c:952
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fedf6ebeb69
Code: Unable to access opcode bytes at 0x7fedf6ebeb3f.
RSP: 002b:00007ffe9c323778 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 00007fedf6f36330 RCX: 00007fedf6ebeb69
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000001
RBP: 0000000000000001 R08: ffffffffffffffc0 R09: 00007fedf6f30e40
R10: 00007ffe9c323690 R11: 0000000000000246 R12: 00007fedf6f36330
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001
 </TASK>

Allocated by task 3605:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:437 [inline]
 ____kasan_kmalloc mm/kasan/common.c:516 [inline]
 ____kasan_kmalloc mm/kasan/common.c:475 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:525
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 nilfs_find_or_create_root+0x84/0x4d0 fs/nilfs2/the_nilfs.c:747
 nilfs_attach_checkpoint+0xc1/0x4b0 fs/nilfs2/super.c:519
 nilfs_fill_super fs/nilfs2/super.c:1064 [inline]
 nilfs_mount+0xb12/0xfb0 fs/nilfs2/super.c:1317
 legacy_get_tree+0x105/0x220 fs/fs_context.c:610
 vfs_get_tree+0x89/0x2f0 fs/super.c:1530
 do_new_mount fs/namespace.c:3040 [inline]
 path_mount+0x1326/0x1e20 fs/namespace.c:3370
 do_mount fs/namespace.c:3383 [inline]
 __do_sys_mount fs/namespace.c:3591 [inline]
 __se_sys_mount fs/namespace.c:3568 [inline]
 __x64_sys_mount+0x27f/0x300 fs/namespace.c:3568
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 3605:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:367 [inline]
 ____kasan_slab_free+0x166/0x1c0 mm/kasan/common.c:329
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1759 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1785
 slab_free mm/slub.c:3539 [inline]
 kfree+0xe2/0x580 mm/slub.c:4567
 nilfs_put_root+0xb1/0xd0 fs/nilfs2/the_nilfs.c:804
 nilfs_clear_inode+0x29a/0x330 fs/nilfs2/inode.c:895
 nilfs_evict_inode+0x318/0x440 fs/nilfs2/inode.c:908
 evict+0x2ed/0x6b0 fs/inode.c:664
 dispose_list+0x117/0x1e0 fs/inode.c:697
 evict_inodes+0x352/0x450 fs/inode.c:747
 generic_shutdown_super+0xab/0x410 fs/super.c:479
 kill_block_super+0x97/0xf0 fs/super.c:1427
 deactivate_locked_super+0x94/0x160 fs/super.c:331
 deactivate_super+0xad/0xd0 fs/super.c:362
 cleanup_mnt+0x2ae/0x3d0 fs/namespace.c:1186
 task_work_run+0xdd/0x1a0 kernel/task_work.c:177
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xb2f/0x2a20 kernel/exit.c:813
 do_group_exit+0xd0/0x2a0 kernel/exit.c:943
 __do_sys_exit_group kernel/exit.c:954 [inline]
 __se_sys_exit_group kernel/exit.c:952 [inline]
 __x64_sys_exit_group+0x3a/0x50 kernel/exit.c:952
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff88801d5c9800
 which belongs to the cache kmalloc-256 of size 256
The buggy address is located 48 bytes inside of
 256-byte region [ffff88801d5c9800, ffff88801d5c9900)

The buggy address belongs to the physical page:
page:ffffea0000757200 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1d5c8
head:ffffea0000757200 order:1 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffffea000080e880 dead000000000003 ffff888011841b40
raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 12, tgid 12 (kworker/u4:1), ts 6626692195, free_ts 0
 prep_new_page mm/page_alloc.c:2532 [inline]
 get_page_from_freelist+0x109b/0x2ce0 mm/page_alloc.c:4283
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5549
 alloc_pages+0x1a6/0x270 mm/mempolicy.c:2270
 alloc_slab_page mm/slub.c:1829 [inline]
 allocate_slab+0x27e/0x3d0 mm/slub.c:1974
 new_slab mm/slub.c:2034 [inline]
 ___slab_alloc+0x84f/0xe80 mm/slub.c:3036
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3123
 slab_alloc_node mm/slub.c:3214 [inline]
 slab_alloc mm/slub.c:3256 [inline]
 kmem_cache_alloc_trace+0x323/0x3e0 mm/slub.c:3287
 kmalloc include/linux/slab.h:600 [inline]
 scsi_probe_and_add_lun+0x3ae/0x3650 drivers/scsi/scsi_scan.c:1187
 __scsi_scan_target+0x21f/0xdb0 drivers/scsi/scsi_scan.c:1665
 scsi_scan_channel drivers/scsi/scsi_scan.c:1753 [inline]
 scsi_scan_channel+0x148/0x1e0 drivers/scsi/scsi_scan.c:1729
 scsi_scan_host_selected+0x2df/0x3b0 drivers/scsi/scsi_scan.c:1782
 do_scsi_scan_host+0x1e8/0x260 drivers/scsi/scsi_scan.c:1921
 do_scan_async+0x3e/0x500 drivers/scsi/scsi_scan.c:1931
 async_run_entry_fn+0x98/0x530 kernel/async.c:127
 process_one_work+0x991/0x1610 kernel/workqueue.c:2289
 worker_thread+0x665/0x1080 kernel/workqueue.c:2436
page_owner free stack trace missing

Memory state around the buggy address:
 ffff88801d5c9700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff88801d5c9780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88801d5c9800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                     ^
 ffff88801d5c9880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88801d5c9900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================

Crashes (19):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-root 2022/10/15 20:37 upstream 55be6084c8e0 67cb024c .config log report syz C KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/09 19:29 upstream a6afa4199d3d aea5da89 .config log report syz C KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/06 16:51 upstream 833477fce7a1 131b38ac .config log report syz C KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/06 16:34 upstream 833477fce7a1 131b38ac .config log report syz C KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/06 16:13 upstream 833477fce7a1 131b38ac .config log report syz C KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/09/30 22:32 linux-next aaa11ce2ffc8 feb56351 .config log report syz C KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-selinux-root 2022/10/19 20:49 upstream 55be6084c8e0 b31320fc .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/16 17:52 upstream 55be6084c8e0 67cb024c .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/15 12:11 upstream 55be6084c8e0 67cb024c .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-selinux-root 2022/10/14 19:11 upstream 55be6084c8e0 4954e4b2 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/10 15:53 upstream 4899a36f91a9 aea5da89 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-root 2022/10/08 22:35 upstream e8bc52cb8df8 aea5da89 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-kasan-gce-selinux-root 2022/10/05 08:14 upstream a5088ee7251e eab8f949 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/10/15 19:54 linux-next aaa11ce2ffc8 67cb024c .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/10/11 10:14 linux-next aaa11ce2ffc8 2b253ced .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/10/09 03:34 linux-next aaa11ce2ffc8 aea5da89 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/10/03 22:07 linux-next aaa11ce2ffc8 feb56351 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/10/02 23:19 linux-next aaa11ce2ffc8 feb56351 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
ci-upstream-linux-next-kasan-gce-root 2022/09/30 21:58 linux-next aaa11ce2ffc8 feb56351 .config log report info KASAN: use-after-free Read in nilfs_segctor_confirm
* Struck through repros no longer work on HEAD.