Kernel bug: KASAN: use-after-free Read in ext4_find_extent (4)
Subsystem: ext4
Status: open

Crash report:
EXT4-fs: Ignoring removed orlov option
EXT4-fs: inline encryption not supported
EXT4-fs (loop0): mounted filesystem 00000000-0000-0000-0000-000000000000 r/w without journal. Quota mode: writeback.
==================================================================
BUG: KASAN: use-after-free in ext4_ext_binsearch fs/ext4/extents.c:841 [inline]
BUG: KASAN: use-after-free in ext4_find_extent+0xae6/0xcc0 fs/ext4/extents.c:956
Read of size 4 at addr ffff888054ee7d6c by task syz.0.20/6108

CPU: 0 UID: 0 PID: 6108 Comm: syz.0.20 Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:378 [inline]
 print_report+0xca/0x240 mm/kasan/report.c:482
 kasan_report+0x118/0x150 mm/kasan/report.c:595
 ext4_ext_binsearch fs/ext4/extents.c:841 [inline]
 ext4_find_extent+0xae6/0xcc0 fs/ext4/extents.c:956
 ext4_ext_map_blocks+0x278/0x69c0 fs/ext4/extents.c:4208
 ext4_map_query_blocks+0x135/0x9f0 fs/ext4/inode.c:549
 ext4_map_blocks+0x4b8/0x16f0 fs/ext4/inode.c:778
 _ext4_get_block+0x1fa/0x4c0 fs/ext4/inode.c:916
 ext4_block_write_begin+0xb03/0x1940 fs/ext4/inode.c:1203
 ext4_write_begin+0xb3a/0x1870 fs/ext4/ext4_jbd2.h:-1
 ext4_da_write_begin+0x352/0xd30 fs/ext4/inode.c:3130
 generic_perform_write+0x29d/0x8c0 mm/filemap.c:4314
 ext4_buffered_write_iter+0xd0/0x3a0 fs/ext4/file.c:299
 ext4_file_write_iter+0x293/0x1be0 fs/ext4/file.c:-1
 new_sync_write fs/read_write.c:593 [inline]
 vfs_write+0x5d5/0xb40 fs/read_write.c:686
 ksys_pwrite64 fs/read_write.c:793 [inline]
 __do_sys_pwrite64 fs/read_write.c:801 [inline]
 __se_sys_pwrite64 fs/read_write.c:798 [inline]
 __x64_sys_pwrite64+0x196/0x220 fs/read_write.c:798
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1b9f20f749
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f1b9e876038 EFLAGS: 00000246 ORIG_RAX: 0000000000000012
RAX: ffffffffffffffda RBX: 00007f1b9f465fa0 RCX: 00007f1b9f20f749
RDX: 000000000000fdef RSI: 0000200000000140 RDI: 0000000000000004
RBP: 00007f1b9f293f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000e7c R11: 0000000000000246 R12: 0000000000000000
R13: 00007f1b9f466038 R14: 00007f1b9f465fa0 R15: 00007fff436979b8
 </TASK>

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x2c0 pfn:0x54ee7
flags: 0x80000000000000(node=0|zone=1)
raw: 0080000000000000 dead000000000100 dead000000000122 0000000000000000
raw: 00000000000002c0 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 0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), pid 5919, tgid 5919 (syz-executor), ts 107453677173, free_ts 112360916870
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x234/0x290 mm/page_alloc.c:1846
 prep_new_page mm/page_alloc.c:1854 [inline]
 get_page_from_freelist+0x28c0/0x2960 mm/page_alloc.c:3915
 __alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5210
 alloc_pages_mpol+0xd1/0x380 mm/mempolicy.c:2486
 folio_alloc_mpol_noprof mm/mempolicy.c:2505 [inline]
 vma_alloc_folio_noprof+0xe4/0x280 mm/mempolicy.c:2540
 folio_prealloc+0x30/0x180 mm/memory.c:-1
 do_cow_fault mm/memory.c:5779 [inline]
 do_fault mm/memory.c:5891 [inline]
 do_pte_missing+0x509/0x27a0 mm/memory.c:4401
 handle_pte_fault mm/memory.c:6273 [inline]
 __handle_mm_fault mm/memory.c:6411 [inline]
 handle_mm_fault+0xcc1/0x1330 mm/memory.c:6580
 do_user_addr_fault+0xa7c/0x1380 arch/x86/mm/fault.c:1336
 handle_page_fault arch/x86/mm/fault.c:1476 [inline]
 exc_page_fault+0x71/0xd0 arch/x86/mm/fault.c:1532
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
page last free pid 5920 tgid 5920 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1395 [inline]
 free_unref_folios+0xc28/0x1810 mm/page_alloc.c:3000
 folios_put_refs+0x569/0x670 mm/swap.c:1002
 free_pages_and_swap_cache+0x277/0x520 mm/swap_state.c:355
 __tlb_batch_free_encoded_pages mm/mmu_gather.c:136 [inline]
 tlb_batch_pages_flush mm/mmu_gather.c:149 [inline]
 tlb_flush_mmu_free mm/mmu_gather.c:397 [inline]
 tlb_flush_mmu+0x3a0/0x680 mm/mmu_gather.c:404
 tlb_finish_mmu+0xc3/0x1d0 mm/mmu_gather.c:497
 exit_mmap+0x439/0xb10 mm/mmap.c:1290
 __mmput+0xcb/0x3d0 kernel/fork.c:1173
 exit_mm+0x169/0x230 kernel/exit.c:581
 do_exit+0x627/0x22f0 kernel/exit.c:959
 do_group_exit+0x21c/0x2d0 kernel/exit.c:1112
 get_signal+0x125d/0x1310 kernel/signal.c:3034
 arch_do_signal_or_restart+0x9a/0x7a0 arch/x86/kernel/signal.c:337
 __exit_to_user_mode_loop kernel/entry/common.c:41 [inline]
 exit_to_user_mode_loop+0x87/0x4e0 kernel/entry/common.c:75
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:226 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:256 [inline]
 syscall_exit_to_user_mode_work include/linux/entry-common.h:159 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:194 [inline]
 do_syscall_64+0x2b7/0xf80 arch/x86/entry/syscall_64.c:100
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff888054ee7c00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888054ee7c80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888054ee7d00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                                          ^
 ffff888054ee7d80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888054ee7e00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================