syzbot


KASAN: use-after-free Read in ext4_rename_dir_prepare (3)

Status: fixed on 2023/05/08 19:06
Reported-by: syzbot+feecbbf039dd054a80e1@syzkaller.appspotmail.com
Fix commit: dd887f83ea54 BACKPORT: ext4: fix use-after-free in ext4_rename_dir_prepare
First crash: 595d, last: 573d
Cause bisection: failed (error log, bisect log)
  
Similar bugs (3)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 KASAN: use-after-free Read in ext4_rename_dir_prepare C error 2 639d 735d 0/1 upstream: reported C repro on 2022/11/19 04:34
android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare C error 2 701d 736d 2/2 fixed on 2023/01/17 16:18
android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare (2) C error inconclusive 3 639d 639d 2/2 fixed on 2023/03/28 17:56

Sample crash report:
ext4 filesystem being mounted at /root/syzkaller.uYsrAf/1/file0 supports timestamps until 2038 (0x7fffffff)
==================================================================
BUG: KASAN: use-after-free in ext4_rename_dir_prepare+0x42e/0x4a0 fs/ext4/namei.c:3704
Read of size 4 at addr ffff888119c14000 by task syz-executor122/376

CPU: 1 PID: 376 Comm: syz-executor122 Not tainted 5.10.161-syzkaller-00019-g416c4356f372 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/14/2023
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack_lvl+0x1e2/0x24b lib/dump_stack.c:118
 print_address_description+0x81/0x3c0 mm/kasan/report.c:233
 __kasan_report mm/kasan/report.c:419 [inline]
 kasan_report+0x1a4/0x1f0 mm/kasan/report.c:436
 __asan_report_load4_noabort+0x14/0x20 mm/kasan/report_generic.c:308
 ext4_rename_dir_prepare+0x42e/0x4a0 fs/ext4/namei.c:3704
 ext4_cross_rename fs/ext4/namei.c:4212 [inline]
 ext4_rename2+0x1f37/0x45a0 fs/ext4/namei.c:4296
 vfs_rename+0x95e/0xde0 fs/namei.c:4389
 do_renameat2+0x83e/0x1190 fs/namei.c:4536
 __do_sys_renameat2 fs/namei.c:4571 [inline]
 __se_sys_renameat2 fs/namei.c:4568 [inline]
 __x64_sys_renameat2+0xbf/0xd0 fs/namei.c:4568
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x61/0xc6
RIP: 0033:0x7f95898f4a29
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 11 15 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 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:00007ffcca6970d8 EFLAGS: 00000246 ORIG_RAX: 000000000000013c
RAX: ffffffffffffffda RBX: 0000000000005426 RCX: 00007f95898f4a29
RDX: 0000000000000004 RSI: 0000000020000080 RDI: 0000000000000005
RBP: 0000000000000000 R08: 0000000000000002 R09: 00007ffcca697100
R10: 00000000200000c0 R11: 0000000000000246 R12: 00007ffcca6970fc
R13: 00007ffcca697130 R14: 00007ffcca697110 R15: 0000000000000001

Allocated by task 345:
 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 include/../mm/slab.h:583 [inline]
 slab_alloc_node mm/slub.c:2956 [inline]
 slab_alloc mm/slub.c:2964 [inline]
 kmem_cache_alloc+0x16c/0x300 mm/slub.c:2969
 dup_mm+0x29/0x320 kernel/fork.c:1403
 copy_mm+0x108/0x1b0 kernel/fork.c:1468
 copy_process+0x133a/0x33a0 kernel/fork.c:2152
 kernel_clone+0x22d/0x900 kernel/fork.c:2524
 __do_sys_clone kernel/fork.c:2643 [inline]
 __se_sys_clone kernel/fork.c:2627 [inline]
 __x64_sys_clone+0x271/0x2e0 kernel/fork.c:2627
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x61/0xc6

Freed by task 345:
 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+0x121/0x160 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:1604 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1630
 slab_free mm/slub.c:3212 [inline]
 kmem_cache_free+0xa9/0x1f0 mm/slub.c:3228
 __mmdrop+0x295/0x390 kernel/fork.c:722
 mmdrop include/linux/sched/mm.h:49 [inline]
 finish_task_switch+0x1e4/0x580 kernel/sched/core.c:3892
 context_switch kernel/sched/core.c:4038 [inline]
 __schedule+0x86e/0xc00 kernel/sched/core.c:4796
 schedule+0x14b/0x1e0 kernel/sched/core.c:4874
 pipe_read+0x9c8/0x1070 fs/pipe.c:378
 call_read_iter include/linux/fs.h:1963 [inline]
 new_sync_read fs/read_write.c:415 [inline]
 vfs_read+0x9e2/0xbf0 fs/read_write.c:496
 ksys_read+0x198/0x2c0 fs/read_write.c:634
 __do_sys_read fs/read_write.c:644 [inline]
 __se_sys_read fs/read_write.c:642 [inline]
 __x64_sys_read+0x7b/0x90 fs/read_write.c:642
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x61/0xc6

The buggy address belongs to the object at ffff888119c14000
 which belongs to the cache mm_struct of size 1104
The buggy address is located 0 bytes inside of
 1104-byte region [ffff888119c14000, ffff888119c14450)
The buggy address belongs to the page:
page:ffffea0004670500 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x119c14
head:ffffea0004670500 order:2 compound_mapcount:0 compound_pincount:0
flags: 0x8000000000010200(slab|head)
raw: 8000000000010200 dead000000000100 dead000000000122 ffff888100066300
raw: 0000000000000000 00000000000c000c 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 345, ts 16125248987, free_ts 16122080680
 set_page_owner include/linux/page_owner.h:35 [inline]
 post_alloc_hook mm/page_alloc.c:2386 [inline]
 prep_new_page mm/page_alloc.c:2392 [inline]
 get_page_from_freelist+0x755/0x810 mm/page_alloc.c:4073
 __alloc_pages_nodemask+0x3b6/0x890 mm/page_alloc.c:5160
 alloc_slab_page mm/slub.c:1815 [inline]
 allocate_slab+0x78/0x540 mm/slub.c:1817
 new_slab mm/slub.c:1878 [inline]
 new_slab_objects mm/slub.c:2636 [inline]
 ___slab_alloc+0x131/0x2e0 mm/slub.c:2800
 __slab_alloc+0x63/0xa0 mm/slub.c:2840
 slab_alloc_node mm/slub.c:2922 [inline]
 slab_alloc mm/slub.c:2964 [inline]
 kmem_cache_alloc+0x1ef/0x300 mm/slub.c:2969
 dup_mm+0x29/0x320 kernel/fork.c:1403
 copy_mm+0x108/0x1b0 kernel/fork.c:1468
 copy_process+0x133a/0x33a0 kernel/fork.c:2152
 kernel_clone+0x22d/0x900 kernel/fork.c:2524
 __do_sys_clone kernel/fork.c:2643 [inline]
 __se_sys_clone kernel/fork.c:2627 [inline]
 __x64_sys_clone+0x271/0x2e0 kernel/fork.c:2627
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x61/0xc6
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:28 [inline]
 free_pages_prepare mm/page_alloc.c:1332 [inline]
 __free_pages_ok+0x7f8/0x830 mm/page_alloc.c:1612
 free_compound_page+0x72/0x90 mm/page_alloc.c:717
 destroy_compound_page include/linux/mm.h:959 [inline]
 __put_compound_page+0x72/0xb0 mm/swap.c:115
 __put_page+0xc0/0xd0 mm/swap.c:131
 put_page include/linux/mm.h:1255 [inline]
 __skb_frag_unref include/linux/skbuff.h:3065 [inline]
 skb_release_data+0x22d/0x630 net/core/skbuff.c:619
 skb_release_all net/core/skbuff.c:680 [inline]
 __kfree_skb+0x59/0x1c0 net/core/skbuff.c:694
 sk_eat_skb include/net/sock.h:2599 [inline]
 tcp_recvmsg+0x1637/0x35a0 net/ipv4/tcp.c:2317
 inet_recvmsg+0x157/0x500 net/ipv4/af_inet.c:852
 sock_recvmsg_nosec net/socket.c:886 [inline]
 sock_recvmsg net/socket.c:904 [inline]
 sock_read_iter+0x3a7/0x4d0 net/socket.c:977
 call_read_iter include/linux/fs.h:1963 [inline]
 new_sync_read fs/read_write.c:415 [inline]
 vfs_read+0x9e2/0xbf0 fs/read_write.c:496
 ksys_read+0x198/0x2c0 fs/read_write.c:634
 __do_sys_read fs/read_write.c:644 [inline]
 __se_sys_read fs/read_write.c:642 [inline]
 __x64_sys_read+0x7b/0x90 fs/read_write.c:642
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x61/0xc6

Memory state around the buggy address:
 ffff888119c13f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff888119c13f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff888119c14000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff888119c14080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888119c14100: 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/04/30 11:42 android12-5.10-lts 416c4356f372 62df2017 .config strace log report syz C [mounted in repro] ci2-android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare
2023/04/30 11:27 android12-5.10-lts 416c4356f372 62df2017 .config console log report info ci2-android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare
2023/04/28 20:20 android12-5.10-lts 416c4356f372 62df2017 .config console log report info ci2-android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare
2023/04/07 19:01 android12-5.10-lts 416c4356f372 f7ba566d .config console log report info ci2-android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare
* Struck through repros no longer work on HEAD.