syzbot


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

Status: fixed on 2023/03/28 17:56
Reported-by: syzbot+1a9a1140c275f0b4b9cc@syzkaller.appspotmail.com
Fix commit: dd887f83ea54 BACKPORT: ext4: fix use-after-free in ext4_rename_dir_prepare
First crash: 530d, last: 516d
Cause bisection: failed (error log, bisect log)
  
Fix bisection the fix commit could be any of (bisect log):
  416c4356f372 Merge 5.10.161 into android12-5.10-lts
  90eb02302b5e Revert "HID: core: Provide new max_buffer_size attribute to over-ride the default"
  
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 516d 612d 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 578d 613d 2/2 fixed on 2023/01/17 16:18
android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare (3) C error 4 450d 450d 2/2 fixed on 2023/05/08 19:06
Last patch testing requests (1)
Created Duration User Patch Repo Result
2023/03/22 14:31 4m tudor.ambarus@linaro.org android12-5.10-lts error

Sample crash report:
ext4 filesystem being mounted at /root/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 ffff88811cb4c000 by task syz-executor241/367

CPU: 1 PID: 367 Comm: syz-executor241 Not tainted 5.10.161-syzkaller-00019-g416c4356f372 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/21/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:0x7f85c66e82b9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 14 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:00007ffc25e70e38 EFLAGS: 00000246 ORIG_RAX: 000000000000013c
RAX: ffffffffffffffda RBX: 0030656c69662f2e RCX: 00007f85c66e82b9
RDX: 0000000000000004 RSI: 0000000020000240 RDI: 0000000000000004
RBP: 0000000000000000 R08: 0000000000000002 R09: 00007f85c6756ec0
R10: 0000000020000000 R11: 0000000000000246 R12: 00007ffc25e70e60
R13: 0000000000000000 R14: 431bde82d7b634db R15: 0000000000000000

The buggy address belongs to the page:
page:ffffea000472d300 refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x11cb4c
flags: 0x8000000000000000()
raw: 8000000000000000 ffffea000472d348 ffff8881f715acc0 0000000000000000
raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 0, migratetype Movable, gfp_mask 0x3100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO|0x2000000), pid 360, ts 48288182492, free_ts 48295631287
 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_pages include/linux/gfp.h:529 [inline]
 __alloc_pages_node include/linux/gfp.h:542 [inline]
 alloc_pages_node include/linux/gfp.h:556 [inline]
 alloc_pages include/linux/gfp.h:575 [inline]
 do_anonymous_page+0x307/0x1050 mm/memory.c:3922
 handle_pte_fault+0x4cd/0x9d0 mm/memory.c:4735
 __handle_mm_fault mm/memory.c:4895 [inline]
 handle_mm_fault+0xf22/0x19f0 mm/memory.c:5259
 do_user_addr_fault+0x67e/0xce0 arch/x86/mm/fault.c:1396
 handle_page_fault arch/x86/mm/fault.c:1462 [inline]
 exc_page_fault+0x71/0x1b0 arch/x86/mm/fault.c:1518
 asm_exc_page_fault+0x1e/0x30 arch/x86/include/asm/idtentry.h:571
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_pcp_prepare+0x18c/0x1c0 mm/page_alloc.c:1406
 free_unref_page_prepare mm/page_alloc.c:3293 [inline]
 free_unref_page_list+0x11d/0x660 mm/page_alloc.c:3367
 release_pages+0xc24/0xc60 mm/swap.c:1082
 free_pages_and_swap_cache+0x97/0xb0 mm/swap_state.c:356
 tlb_batch_pages_flush mm/mmu_gather.c:49 [inline]
 tlb_flush_mmu_free mm/mmu_gather.c:240 [inline]
 tlb_flush_mmu+0x8a0/0xa80 mm/mmu_gather.c:247
 tlb_finish_mmu+0xd2/0x1f0 mm/mmu_gather.c:326
 unmap_region+0x346/0x390 mm/mmap.c:2798
 __do_munmap+0x696/0x8c0 mm/mmap.c:3027
 __vm_munmap mm/mmap.c:3050 [inline]
 __do_sys_munmap mm/mmap.c:3076 [inline]
 __se_sys_munmap+0x121/0x1b0 mm/mmap.c:3072
 __x64_sys_munmap+0x5b/0x70 mm/mmap.c:3072
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x61/0xc6

Memory state around the buggy address:
 ffff88811cb4bf00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff88811cb4bf80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88811cb4c000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                   ^
 ffff88811cb4c080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff88811cb4c100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/02/22 23:35 android12-5.10-lts 416c4356f372 9f1e2cb3 .config console log report syz C [mounted in repro] ci2-android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare
2023/02/22 23:17 android12-5.10-lts 416c4356f372 9f1e2cb3 .config console log report info ci2-android-5-10 KASAN: use-after-free Read in ext4_rename_dir_prepare
2023/02/08 19:41 android12-5.10-lts 416c4356f372 fc9c934e .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.