syzbot


KASAN: use-after-free Write in ext4_stop_mmpd

Status: fixed on 2021/11/10 00:32
Reported-by: syzbot+572522e86664231eadff@syzkaller.appspotmail.com
Fix commit: b663890d8544 ext4: fix possible UAF when remounting r/o a mmp-protected file system
First crash: 1124d, last: 1122d
Cause bisection: introduced by (bisect log) :
commit 5e4f5138bd8522ebe231a137682d3857209a2c07
Author: Pavel Skripkin <paskripkin@gmail.com>
Date: Fri Apr 30 18:50:46 2021 +0000

  ext4: fix memory leak in ext4_fill_super

Crash: KASAN: use-after-free Write in ext4_stop_mmpd (log)
Repro: C syz .config
  
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Write in ext4_stop_mmpd ext4 1 1233d 1228d 0/28 auto-closed as invalid on 2021/11/03 23:21

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
BUG: KASAN: use-after-free in atomic_fetch_add_relaxed include/asm-generic/atomic-instrumented.h:142 [inline]
BUG: KASAN: use-after-free in __refcount_add include/linux/refcount.h:193 [inline]
BUG: KASAN: use-after-free in __refcount_inc include/linux/refcount.h:250 [inline]
BUG: KASAN: use-after-free in refcount_inc include/linux/refcount.h:267 [inline]
BUG: KASAN: use-after-free in get_task_struct include/linux/sched/task.h:104 [inline]
BUG: KASAN: use-after-free in kthread_stop+0x36/0x3d0 kernel/kthread.c:638
Write of size 4 at addr ffff888114b727a0 by task syz-executor051/370

CPU: 1 PID: 370 Comm: syz-executor051 Not tainted 5.10.75-syzkaller-01082-g234d53d2bb60 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack_lvl+0x1e2/0x24b lib/dump_stack.c:118
 print_address_description+0x8d/0x3d0 mm/kasan/report.c:233
 __kasan_report+0x142/0x220 mm/kasan/report.c:419
 kasan_report+0x51/0x70 mm/kasan/report.c:436
 check_region_inline mm/kasan/generic.c:135 [inline]
 kasan_check_range+0x2b6/0x2f0 mm/kasan/generic.c:186
 __kasan_check_write+0x14/0x20 mm/kasan/shadow.c:37
 instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
 atomic_fetch_add_relaxed include/asm-generic/atomic-instrumented.h:142 [inline]
 __refcount_add include/linux/refcount.h:193 [inline]
 __refcount_inc include/linux/refcount.h:250 [inline]
 refcount_inc include/linux/refcount.h:267 [inline]
 get_task_struct include/linux/sched/task.h:104 [inline]
 kthread_stop+0x36/0x3d0 kernel/kthread.c:638
 ext4_stop_mmpd+0x47/0xb0 fs/ext4/mmp.c:254
 ext4_put_super+0xa09/0xe90 fs/ext4/super.c:1263
 generic_shutdown_super+0x13f/0x2c0 fs/super.c:464
 kill_block_super+0x80/0xe0 fs/super.c:1446
 deactivate_locked_super+0xb0/0x100 fs/super.c:335
 deactivate_super+0xa5/0xd0 fs/super.c:366
 cleanup_mnt+0x45f/0x510 fs/namespace.c:1118
 __cleanup_mnt+0x19/0x20 fs/namespace.c:1125
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:164 [inline]
 exit_to_user_mode_prepare+0xc3/0xe0 kernel/entry/common.c:191
 syscall_exit_to_user_mode+0x24/0x40 kernel/entry/common.c:266
 do_syscall_64+0x3d/0x70 arch/x86/entry/common.c:56
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fa3cca8c537
Code: 07 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 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd35796d88 EFLAGS: 00000206 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 00000000000069fe RCX: 00007fa3cca8c537
RDX: 00007ffd35796e4a RSI: 0000000000000002 RDI: 00007ffd35796e40
RBP: 00007ffd35796e40 R08: 00000000ffffffff R09: 00007ffd35796c20
R10: 0000555556a2f633 R11: 0000000000000206 R12: 00007ffd35797eb0
R13: 0000555556a2f5f0 R14: 00007ffd35796db0 R15: 0000000000000013

Allocated by task 2:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:428 [inline]
 __kasan_slab_alloc+0xb2/0xe0 mm/kasan/common.c:461
 kasan_slab_alloc include/linux/kasan.h:259 [inline]
 slab_post_alloc_hook mm/slab.h:583 [inline]
 slab_alloc_node mm/slub.c:2941 [inline]
 slab_alloc mm/slub.c:2949 [inline]
 kmem_cache_alloc+0x1a2/0x380 mm/slub.c:2954
 kmem_cache_alloc_node include/linux/slab.h:423 [inline]
 alloc_task_struct_node kernel/fork.c:176 [inline]
 dup_task_struct+0xbc/0xea0 kernel/fork.c:895
 copy_process+0x665/0x5330 kernel/fork.c:1987
 kernel_clone+0x21f/0x9a0 kernel/fork.c:2507
 kernel_thread+0x16c/0x1e0 kernel/fork.c:2561
 create_kthread kernel/kthread.c:336 [inline]
 kthreadd+0x3cd/0x510 kernel/kthread.c:680
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Freed by task 0:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track+0x4c/0x80 mm/kasan/common.c:46
 kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:357
 ____kasan_slab_free+0x133/0x170 mm/kasan/common.c:360
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:368
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:1596 [inline]
 slab_free_freelist_hook+0xb2/0x180 mm/slub.c:1621
 slab_free mm/slub.c:3195 [inline]
 kmem_cache_free+0xaa/0x1e0 mm/slub.c:3211
 free_task_struct kernel/fork.c:181 [inline]
 free_task+0xb9/0x1e0 kernel/fork.c:473
 __put_task_struct+0x2e0/0x440 kernel/fork.c:776
 put_task_struct include/linux/sched/task.h:113 [inline]
 delayed_put_task_struct+0x67/0x190 kernel/exit.c:174
 rcu_do_batch+0x4cd/0xb40 kernel/rcu/tree.c:2484
 rcu_core+0x822/0x10d0 kernel/rcu/tree.c:2721
 rcu_core_si+0x9/0x10 kernel/rcu/tree.c:2734
 __do_softirq+0x27e/0x598 kernel/softirq.c:305

Last potentially related work creation:
 kasan_save_stack+0x36/0x60 mm/kasan/common.c:38
 kasan_record_aux_stack+0xd3/0xf0 mm/kasan/generic.c:345
 __call_rcu kernel/rcu/tree.c:2962 [inline]
 call_rcu+0x134/0x1470 kernel/rcu/tree.c:3036
 put_task_struct_rcu_user+0x58/0xa0 kernel/exit.c:180
 finish_task_switch+0x251/0x5f0 kernel/sched/core.c:3888
 context_switch kernel/sched/core.c:4018 [inline]
 __schedule+0x94c/0xda0 kernel/sched/core.c:4776
 schedule_idle+0x60/0x90 kernel/sched/core.c:4882
 do_idle+0x584/0x5e0 kernel/sched/idle.c:330
 cpu_startup_entry+0x25/0x30 kernel/sched/idle.c:398
 start_secondary+0xd7/0xe0 arch/x86/kernel/smpboot.c:265
 secondary_startup_64_no_verify+0xb0/0xbb

The buggy address belongs to the object at ffff888114b72780
 which belongs to the cache task_struct of size 4800
The buggy address is located 32 bytes inside of
 4800-byte region [ffff888114b72780, ffff888114b73a40)
The buggy address belongs to the page:
page:ffffea000452dc00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x114b70
head:ffffea000452dc00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x8000000000010200(slab|head)
raw: 8000000000010200 dead000000000100 dead000000000122 ffff888100067500
raw: 0000000000000000 0000000000060006 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 2, ts 27247234899, free_ts 27228028224
 set_page_owner include/linux/page_owner.h:35 [inline]
 post_alloc_hook mm/page_alloc.c:2385 [inline]
 prep_new_page mm/page_alloc.c:2391 [inline]
 get_page_from_freelist+0xa74/0xa90 mm/page_alloc.c:4063
 __alloc_pages_nodemask+0x3c8/0x820 mm/page_alloc.c:5106
 alloc_slab_page mm/slub.c:1800 [inline]
 allocate_slab+0x6b/0x350 mm/slub.c:1802
 new_slab mm/slub.c:1863 [inline]
 new_slab_objects mm/slub.c:2622 [inline]
 ___slab_alloc+0x143/0x2f0 mm/slub.c:2785
 __slab_alloc mm/slub.c:2825 [inline]
 slab_alloc_node mm/slub.c:2907 [inline]
 slab_alloc mm/slub.c:2949 [inline]
 kmem_cache_alloc+0x26f/0x380 mm/slub.c:2954
 kmem_cache_alloc_node include/linux/slab.h:423 [inline]
 alloc_task_struct_node kernel/fork.c:176 [inline]
 dup_task_struct+0xbc/0xea0 kernel/fork.c:895
 copy_process+0x665/0x5330 kernel/fork.c:1987
 kernel_clone+0x21f/0x9a0 kernel/fork.c:2507
 kernel_thread+0x16c/0x1e0 kernel/fork.c:2561
 create_kthread kernel/kthread.c:336 [inline]
 kthreadd+0x3cd/0x510 kernel/kthread.c:680
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:28 [inline]
 free_pages_prepare mm/page_alloc.c:1331 [inline]
 __free_pages_ok+0xbe7/0xc20 mm/page_alloc.c:1611
 free_the_page mm/page_alloc.c:5167 [inline]
 __free_pages+0x2d6/0x4a0 mm/page_alloc.c:5173
 __free_slab+0xdf/0x1a0 mm/slub.c:1888
 free_slab mm/slub.c:1903 [inline]
 discard_slab mm/slub.c:1909 [inline]
 unfreeze_partials+0x17d/0x1b0 mm/slub.c:2403
 put_cpu_partial+0xc8/0x190 mm/slub.c:2439
 __slab_free+0x2eb/0x4e0 mm/slub.c:3089
 do_slab_free mm/slub.c:3183 [inline]
 ___cache_free+0x131/0x150 mm/slub.c:3202
 qlink_free+0x38/0x40 mm/kasan/quarantine.c:146
 qlist_free_all mm/kasan/quarantine.c:165 [inline]
 kasan_quarantine_reduce+0x178/0x1d0 mm/kasan/quarantine.c:272
 __kasan_slab_alloc+0x2f/0xe0 mm/kasan/common.c:438
 kasan_slab_alloc include/linux/kasan.h:259 [inline]
 slab_post_alloc_hook mm/slab.h:583 [inline]
 slab_alloc_node mm/slub.c:2941 [inline]
 slab_alloc mm/slub.c:2949 [inline]
 kmem_cache_alloc_trace+0x1a5/0x3a0 mm/slub.c:2966
 kmalloc include/linux/slab.h:552 [inline]
 kzalloc include/linux/slab.h:664 [inline]
 alloc_fs_context+0x64/0x680 fs/fs_context.c:234
 fs_context_for_mount+0x24/0x30 fs/fs_context.c:281
 do_new_mount fs/namespace.c:2884 [inline]
 path_mount+0x12fb/0x2ab0 fs/namespace.c:3229
 do_mount fs/namespace.c:3242 [inline]
 __do_sys_mount fs/namespace.c:3450 [inline]
 __se_sys_mount+0x2f7/0x3b0 fs/namespace.c:3427
 __x64_sys_mount+0xbf/0xd0 fs/namespace.c:3427

Memory state around the buggy address:
 ffff888114b72680: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888114b72700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888114b72780: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
 ffff888114b72800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888114b72880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
------------[ cut here ]------------
refcount_t: addition on 0; use-after-free.
WARNING: CPU: 0 PID: 370 at lib/refcount.c:25 refcount_warn_saturate+0x147/0x1b0 lib/refcount.c:25
Modules linked in:
CPU: 0 PID: 370 Comm: syz-executor051 Tainted: G    B             5.10.75-syzkaller-01082-g234d53d2bb60 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:refcount_warn_saturate+0x147/0x1b0 lib/refcount.c:25
Code: c7 e0 b0 49 85 31 c0 e8 e7 7d eb fe 0f 0b eb a1 e8 1e 9b 18 ff c6 05 4b cb 68 04 01 48 c7 c7 80 b1 49 85 31 c0 e8 c9 7d eb fe <0f> 0b eb 83 e8 00 9b 18 ff c6 05 2e cb 68 04 01 48 c7 c7 e0 b1 49
RSP: 0018:ffffc9000096fc60 EFLAGS: 00010246
RAX: 074051a822b27300 RBX: 0000000000000002 RCX: 1ffff9200012df44
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc9000096fc70 R08: ffffffff81545368 R09: fffff5200012deb5
R10: fffff5200012deb5 R11: 0000000000000000 R12: ffff888114b72780
R13: dffffc0000000000 R14: 0000000000000002 R15: dffffc0000000000
FS:  0000555556a2e300(0000) GS:ffff8881f7000000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ffd35797e58 CR3: 0000000106985000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 __refcount_add include/linux/refcount.h:200 [inline]
 __refcount_inc include/linux/refcount.h:250 [inline]
 refcount_inc include/linux/refcount.h:267 [inline]
 get_task_struct include/linux/sched/task.h:104 [inline]
 kthread_stop+0x1b0/0x3d0 kernel/kthread.c:638
 ext4_stop_mmpd+0x47/0xb0 fs/ext4/mmp.c:254
 ext4_put_super+0xa09/0xe90 fs/ext4/super.c:1263
 generic_shutdown_super+0x13f/0x2c0 fs/super.c:464
 kill_block_super+0x80/0xe0 fs/super.c:1446
 deactivate_locked_super+0xb0/0x100 fs/super.c:335
 deactivate_super+0xa5/0xd0 fs/super.c:366
 cleanup_mnt+0x45f/0x510 fs/namespace.c:1118
 __cleanup_mnt+0x19/0x20 fs/namespace.c:1125
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:164 [inline]
 exit_to_user_mode_prepare+0xc3/0xe0 kernel/entry/common.c:191
 syscall_exit_to_user_mode+0x24/0x40 kernel/entry/common.c:266
 do_syscall_64+0x3d/0x70 arch/x86/entry/common.c:56
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fa3cca8c537
Code: 07 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 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd35796d88 EFLAGS: 00000206 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 00000000000069fe RCX: 00007fa3cca8c537
RDX: 00007ffd35796e4a RSI: 0000000000000002 RDI: 00007ffd35796e40
RBP: 00007ffd35796e40 R08: 00000000ffffffff R09: 00007ffd35796c20
R10: 0000555556a2f633 R11: 0000000000000206 R12: 00007ffd35797eb0
R13: 0000555556a2f5f0 R14: 00007ffd35796db0 R15: 0000000000000013
---[ end trace 133fa59ff5904ec7 ]---
------------[ cut here ]------------
refcount_t: underflow; use-after-free.
WARNING: CPU: 1 PID: 370 at lib/refcount.c:28 refcount_warn_saturate+0x165/0x1b0 lib/refcount.c:28
Modules linked in:
CPU: 1 PID: 370 Comm: syz-executor051 Tainted: G    B   W         5.10.75-syzkaller-01082-g234d53d2bb60 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:refcount_warn_saturate+0x165/0x1b0 lib/refcount.c:28
Code: c7 80 b1 49 85 31 c0 e8 c9 7d eb fe 0f 0b eb 83 e8 00 9b 18 ff c6 05 2e cb 68 04 01 48 c7 c7 e0 b1 49 85 31 c0 e8 ab 7d eb fe <0f> 0b e9 62 ff ff ff e8 df 9a 18 ff c6 05 0e cb 68 04 01 48 c7 c7
RSP: 0018:ffffc9000096fc60 EFLAGS: 00010246
RAX: 074051a822b27300 RBX: 0000000000000003 RCX: 1ffff9200012df44
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc9000096fc70 R08: ffffffff81545368 R09: fffff5200012deb5
R10: fffff5200012deb5 R11: 0000000000000000 R12: 00000000ffffffff
R13: dffffc0000000000 R14: 0000000000000003 R15: 0000000000000000
FS:  0000555556a2e300(0000) GS:ffff8881f7100000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000056315a9e4028 CR3: 0000000106985000 CR4: 00000000003506a0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 __refcount_sub_and_test include/linux/refcount.h:283 [inline]
 __refcount_dec_and_test include/linux/refcount.h:315 [inline]
 refcount_dec_and_test include/linux/refcount.h:333 [inline]
 put_task_struct include/linux/sched/task.h:112 [inline]
 kthread_stop+0x1c7/0x3d0 kernel/kthread.c:645
 ext4_stop_mmpd+0x47/0xb0 fs/ext4/mmp.c:254
 ext4_put_super+0xa09/0xe90 fs/ext4/super.c:1263
 generic_shutdown_super+0x13f/0x2c0 fs/super.c:464
 kill_block_super+0x80/0xe0 fs/super.c:1446
 deactivate_locked_super+0xb0/0x100 fs/super.c:335
 deactivate_super+0xa5/0xd0 fs/super.c:366
 cleanup_mnt+0x45f/0x510 fs/namespace.c:1118
 __cleanup_mnt+0x19/0x20 fs/namespace.c:1125
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:164 [inline]
 exit_to_user_mode_prepare+0xc3/0xe0 kernel/entry/common.c:191
 syscall_exit_to_user_mode+0x24/0x40 kernel/entry/common.c:266
 do_syscall_64+0x3d/0x70 arch/x86/entry/common.c:56
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fa3cca8c537
Code: 07 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 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd35796d88 EFLAGS: 00000206 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 00000000000069fe RCX: 00007fa3cca8c537
RDX: 00007ffd35796e4a RSI: 0000000000000002 RDI: 00007ffd35796e40
RBP: 00007ffd35796e40 R08: 00000000ffffffff R09: 00007ffd35796c20
R10: 0000555556a2f633 R11: 0000000000000206 R12: 00007ffd35797eb0
R13: 0000555556a2f5f0 R14: 00007ffd35796db0 R15: 0000000000000013
---[ end trace 133fa59ff5904ec8 ]---

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2021/10/26 04:44 android12-5.10-lts 234d53d2bb60 c1132b49 .config console log report syz C ci2-android-5-10 KASAN: use-after-free Write in ext4_stop_mmpd
2021/10/24 10:51 android12-5.10-lts 234d53d2bb60 282f03fb .config console log report syz C ci2-android-5-10 KASAN: use-after-free Write in ext4_stop_mmpd
2021/10/24 10:35 android12-5.10-lts 234d53d2bb60 282f03fb .config console log report info ci2-android-5-10 KASAN: use-after-free Write in ext4_stop_mmpd
* Struck through repros no longer work on HEAD.