syzbot


KASAN: use-after-free Read in move_expired_inodes

Status: fixed on 2023/01/27 09:47
Subsystems: fat
[Documentation on labels]
Reported-by: syzbot+d599b0d654db599a8cbd@syzkaller.appspotmail.com
Fix commit: 8ce9b1c97fce fs: do not update freeing inode i_io_list
First crash: 452d, last: 415d
Cause bisection: introduced by (bisect log) :
commit 0d942303430824f785ac7ed8434a05d87bf4bb13
Author: Lukas Czerner <lczerner@redhat.com>
Date: Thu Aug 25 10:06:57 2022 +0000

  fs: record I_DIRTY_TIME even if inode already has I_DIRTY_INODE

Crash: KASAN: use-after-free Read in __mark_inode_dirty (log)
Repro: C syz .config
  
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in move_expired_inodes ext4 1 1620d 1619d 0/26 auto-closed as invalid on 2020/01/23 02:07
upstream KASAN: use-after-free Read in move_expired_inodes (2) exfat C done 4 468d 508d 22/26 fixed on 2023/02/24 13:50
Last patch testing requests (3)
Created Duration User Patch Repo Result
2022/12/14 07:19 16m tudor.ambarus@linaro.org https://github.com/ambarus/linux.git syzkaller-id-5ecbc557fcdb8a2864e876f690ef377db999c50f OK log
2022/12/13 09:31 0m tudor.ambarus@linaro.org git@github.com:ambarus/linux.git syzkaller-id-5ecbc557fcdb8a2864e876f690ef377db999c50f error OK
2022/12/09 09:59 15m tudor.ambarus@linaro.org https://github.com/ambarus/linux-0day.git syzkaller-id-5ecbc557fcdb8a2864e876f690ef377db999c50f OK log

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in inode_dirtied_after fs/fs-writeback.c:1370 [inline]
BUG: KASAN: use-after-free in move_expired_inodes+0x181/0x890 fs/fs-writeback.c:1402
Read of size 8 at addr ffff88811d9a0590 by task kworker/u4:2/94

CPU: 1 PID: 94 Comm: kworker/u4:2 Not tainted 5.15.78-syzkaller-00911-gc73b4619ad86 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Workqueue: writeback wb_workfn (flush-7:0)
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x151/0x1b7 lib/dump_stack.c:106
 print_address_description+0x87/0x3d0 mm/kasan/report.c:256
 __kasan_report mm/kasan/report.c:435 [inline]
 kasan_report+0x1a6/0x1f0 mm/kasan/report.c:452
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report_generic.c:309
 inode_dirtied_after fs/fs-writeback.c:1370 [inline]
 move_expired_inodes+0x181/0x890 fs/fs-writeback.c:1402
 queue_io+0x29f/0x500 fs/fs-writeback.c:1462
 wb_writeback+0x3c3/0x9e0 fs/fs-writeback.c:2069
 wb_do_writeback+0x222/0xbd0 fs/fs-writeback.c:2214
 wb_workfn+0xf8/0x3e0 fs/fs-writeback.c:2255
 process_one_work+0x6db/0xc00 kernel/workqueue.c:2313
 worker_thread+0xb3e/0x1340 kernel/workqueue.c:2460
 kthread+0x41c/0x500 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
 </TASK>

Allocated by task 431:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:433 [inline]
 __kasan_slab_alloc+0xb2/0xe0 mm/kasan/common.c:466
 kasan_slab_alloc include/linux/kasan.h:244 [inline]
 slab_post_alloc_hook mm/slab.h:550 [inline]
 slab_alloc_node mm/slub.c:3236 [inline]
 slab_alloc mm/slub.c:3244 [inline]
 kmem_cache_alloc+0x189/0x2f0 mm/slub.c:3249
 fat_alloc_inode+0x1d/0xa0 fs/fat/inode.c:748
 alloc_inode fs/inode.c:236 [inline]
 new_inode_pseudo+0x64/0x220 fs/inode.c:937
 new_inode+0x28/0x1c0 fs/inode.c:966
 fat_build_inode+0x1d9/0x3a0 fs/fat/inode.c:601
 msdos_create+0x480/0x580 fs/fat/namei_msdos.c:292
 lookup_open fs/namei.c:3334 [inline]
 open_last_lookups fs/namei.c:3404 [inline]
 path_openat+0x1323/0x2ea0 fs/namei.c:3612
 do_filp_open+0x277/0x4f0 fs/namei.c:3642
 file_open_name fs/open.c:1158 [inline]
 filp_open+0x255/0x2b0 fs/open.c:1178
 do_coredump+0x1ca9/0x2320 fs/coredump.c:767
 get_signal+0x48c/0x1600 kernel/signal.c:2876
 arch_do_signal_or_restart+0x9f/0x670 arch/x86/kernel/signal.c:865
 handle_signal_work kernel/entry/common.c:148 [inline]
 exit_to_user_mode_loop+0xd4/0x110 kernel/entry/common.c:172
 exit_to_user_mode_prepare+0x3b/0x40 kernel/entry/common.c:207
 irqentry_exit_to_user_mode+0x9/0x20 kernel/entry/common.c:313
 irqentry_exit+0x12/0x40 kernel/entry/common.c:404
 exc_page_fault+0x75/0x1a0 arch/x86/mm/fault.c:1620
 asm_exc_page_fault+0x27/0x30 arch/x86/include/asm/idtentry.h:568

Freed by task 0:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track+0x4c/0x70 mm/kasan/common.c:45
 kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:370
 ____kasan_slab_free+0x126/0x160 mm/kasan/common.c:365
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:373
 kasan_slab_free include/linux/kasan.h:220 [inline]
 slab_free_hook mm/slub.c:1721 [inline]
 slab_free_freelist_hook+0xc9/0x1a0 mm/slub.c:1747
 slab_free mm/slub.c:3515 [inline]
 kmem_cache_free+0x11a/0x2e0 mm/slub.c:3531
 fat_free_inode+0x20/0x30 fs/fat/inode.c:765
 i_callback+0x4b/0x70 fs/inode.c:225
 rcu_do_batch+0x55b/0xbe0 kernel/rcu/tree.c:2509
 rcu_core+0x506/0x1000 kernel/rcu/tree.c:2749
 rcu_core_si+0x9/0x10 kernel/rcu/tree.c:2762
 __do_softirq+0x27e/0x5dc kernel/softirq.c:565

Last potentially related work creation:
 kasan_save_stack+0x3b/0x60 mm/kasan/common.c:38
 __kasan_record_aux_stack+0xd3/0xf0 mm/kasan/generic.c:348
 kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:358
 __call_rcu kernel/rcu/tree.c:2993 [inline]
 call_rcu+0x140/0x1400 kernel/rcu/tree.c:3073
 destroy_inode fs/inode.c:291 [inline]
 evict+0x5de/0x630 fs/inode.c:602
 iput_final fs/inode.c:1663 [inline]
 iput+0x61c/0x7d0 fs/inode.c:1689
 dentry_unlink_inode+0x349/0x430 fs/dcache.c:376
 __dentry_kill+0x3e2/0x5d0 fs/dcache.c:582
 dentry_kill+0xc0/0x2a0
 dput+0x175/0x320 fs/dcache.c:888
 __fput+0x65a/0x910 fs/file_table.c:288
 ____fput+0x15/0x20 fs/file_table.c:308
 task_work_run+0x147/0x1b0 kernel/task_work.c:164
 ptrace_notify+0x29a/0x340 kernel/signal.c:2382
 ptrace_event include/linux/ptrace.h:152 [inline]
 do_exit+0x1c65/0x24d0 kernel/exit.c:768
 do_group_exit+0x13a/0x300 kernel/exit.c:925
 get_signal+0x77e/0x1600 kernel/signal.c:2890
 arch_do_signal_or_restart+0x9f/0x670 arch/x86/kernel/signal.c:865
 handle_signal_work kernel/entry/common.c:148 [inline]
 exit_to_user_mode_loop+0xd4/0x110 kernel/entry/common.c:172
 exit_to_user_mode_prepare+0x3b/0x40 kernel/entry/common.c:207
 irqentry_exit_to_user_mode+0x9/0x20 kernel/entry/common.c:313
 irqentry_exit+0x12/0x40 kernel/entry/common.c:404
 exc_page_fault+0x75/0x1a0 arch/x86/mm/fault.c:1620
 asm_exc_page_fault+0x27/0x30 arch/x86/include/asm/idtentry.h:568

The buggy address belongs to the object at ffff88811d9a0410
 which belongs to the cache fat_inode_cache of size 912
The buggy address is located 384 bytes inside of
 912-byte region [ffff88811d9a0410, ffff88811d9a07a0)
The buggy address belongs to the page:
page:ffffea0004766800 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11d9a0
head:ffffea0004766800 order:2 compound_mapcount:0 compound_pincount:0
flags: 0x4000000000010200(slab|head|zone=1)
raw: 4000000000010200 0000000000000000 dead000000000122 ffff888108586a80
raw: 0000000000000000 00000000800f000f 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Reclaimable, gfp_mask 0xd2050(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_RECLAIMABLE), pid 423, ts 26584952315, free_ts 0
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0x1ab/0x1b0 mm/page_alloc.c:2495
 prep_new_page mm/page_alloc.c:2501 [inline]
 get_page_from_freelist+0x38b/0x400 mm/page_alloc.c:4281
 __alloc_pages+0x3a8/0x7c0 mm/page_alloc.c:5548
 allocate_slab+0x62/0x580 mm/slub.c:1928
 new_slab mm/slub.c:1991 [inline]
 ___slab_alloc+0x2e2/0x6f0 mm/slub.c:3024
 __slab_alloc+0x4a/0x90 mm/slub.c:3111
 slab_alloc_node mm/slub.c:3202 [inline]
 slab_alloc mm/slub.c:3244 [inline]
 kmem_cache_alloc+0x205/0x2f0 mm/slub.c:3249
 fat_alloc_inode+0x1d/0xa0 fs/fat/inode.c:748
 alloc_inode fs/inode.c:236 [inline]
 new_inode_pseudo+0x64/0x220 fs/inode.c:937
 new_inode+0x28/0x1c0 fs/inode.c:966
 fat_build_inode+0x1d9/0x3a0 fs/fat/inode.c:601
 msdos_create+0x480/0x580 fs/fat/namei_msdos.c:292
 lookup_open fs/namei.c:3334 [inline]
 open_last_lookups fs/namei.c:3404 [inline]
 path_openat+0x1323/0x2ea0 fs/namei.c:3612
 do_filp_open+0x277/0x4f0 fs/namei.c:3642
 file_open_name fs/open.c:1158 [inline]
 filp_open+0x255/0x2b0 fs/open.c:1178
 do_coredump+0x1ca9/0x2320 fs/coredump.c:767
page_owner free stack trace missing

Memory state around the buggy address:
 ffff88811d9a0480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88811d9a0500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88811d9a0580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                         ^
 ffff88811d9a0600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88811d9a0680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/01/12 02:22 android13-5.15-lts c73b4619ad86 96166539 .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-android-5-15 KASAN: use-after-free Read in move_expired_inodes
2023/01/05 00:30 android13-5.15-lts c73b4619ad86 1dac8c7a .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-android-5-15 KASAN: use-after-free Read in move_expired_inodes
2022/12/21 21:54 android13-5.15-lts c73b4619ad86 4067838e .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-android-5-15 KASAN: use-after-free Read in move_expired_inodes
2022/12/06 11:32 android13-5.15-lts 92f701cae0bc 045cbb84 .config strace log report syz C [mounted in repro] ci2-android-5-15 KASAN: use-after-free Read in move_expired_inodes
* Struck through repros no longer work on HEAD.