KASAN: use-after-free Read in ext4_ext_rm_leaf

Status: fixed on 2023/05/24 12:43
Subsystems: ext4
[Documentation on labels]
Fix commit: 89eccb84959f ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop
First crash: 406d, last: 406d
Cause bisection: failed (error log, bisect log)
Fix bisection: fixed by (bisect log) :
commit 7192afa5e4bfa1316a3ad4875562e9b123af7c06
Author: Baokun Li <>
Date: Wed Aug 17 13:27:01 2022 +0000

  ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop

Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
android-5-10 KASAN: use-after-free Read in ext4_ext_rm_leaf ext4 C error inconclusive 1 406d 406d 2/2 fixed on 2023/05/24 12:43

Sample crash report:
BUG: KASAN: use-after-free in ext4_ext_rm_leaf+0x14d4/0x1800 fs/ext4/extents.c:2619
Read of size 4 at addr ffff888123a80ff4 by task syz-executor214/14902

CPU: 0 PID: 14902 Comm: syz-executor214 Not tainted 5.15.80-syzkaller-00318-g72d681a01da5 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
Call Trace:
 __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_load4_noabort+0x14/0x20 mm/kasan/report_generic.c:308
 ext4_ext_rm_leaf+0x14d4/0x1800 fs/ext4/extents.c:2619
 ext4_ext_remove_space+0xfc5/0x21b0 fs/ext4/extents.c:2957
 ext4_ext_truncate+0x19f/0x250 fs/ext4/extents.c:4419
 ext4_truncate+0x942/0xf50 fs/ext4/inode.c:4268
 ext4_setattr+0xfe4/0x1920 fs/ext4/inode.c:5529
 notify_change+0xd8f/0x1040 fs/attr.c:426
 do_truncate+0x214/0x300 fs/open.c:66
 handle_truncate fs/namei.c:3136 [inline]
 do_open fs/namei.c:3484 [inline]
 path_openat+0x2849/0x2ea0 fs/namei.c:3615
 do_filp_open+0x277/0x4f0 fs/namei.c:3642
 do_sys_openat2+0x13b/0x500 fs/open.c:1234
 do_sys_open fs/open.c:1250 [inline]
 __do_sys_openat fs/open.c:1266 [inline]
 __se_sys_openat fs/open.c:1261 [inline]
 __x64_sys_openat+0x243/0x290 fs/open.c:1261
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
RIP: 0033:0x7f1c3248a7f9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 71 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f1c2a0f42f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007f1c3250f7c0 RCX: 00007f1c3248a7f9
RDX: 000000000000275a RSI: 00000000200001c0 RDI: 00000000ffffff9c
RBP: 00007f1c324dc814 R08: 00007f1c2a0f4700 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: be734677a9d9a8be
R13: 0030656c69662f2e R14: 6f6f6c2f7665642f R15: 00007f1c3250f7c8

The buggy address belongs to the page:
page:ffffea00048ea000 refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x123a80
flags: 0x4000000000000000(zone=1)
raw: 4000000000000000 ffffea0004950488 ffffea000496e388 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 0x100cca(GFP_HIGHUSER_MOVABLE), pid 14254, ts 252534449862, free_ts 252822873974
 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
 __alloc_pages_node include/linux/gfp.h:591 [inline]
 alloc_pages_node include/linux/gfp.h:605 [inline]
 alloc_pages include/linux/gfp.h:618 [inline]
 shmem_alloc_page mm/shmem.c:1587 [inline]
 shmem_alloc_and_acct_page+0x4a0/0xa20 mm/shmem.c:1612
 shmem_getpage_gfp+0x1487/0x25f0 mm/shmem.c:1907
 shmem_getpage mm/shmem.c:152 [inline]
 shmem_write_begin+0xc8/0x1b0 mm/shmem.c:2478
 generic_perform_write+0x2cd/0x5d0 mm/filemap.c:3825
 __generic_file_write_iter+0x25b/0x4b0 mm/filemap.c:3952
 generic_file_write_iter+0xaf/0x1c0 mm/filemap.c:3984
 call_write_iter include/linux/fs.h:2138 [inline]
 new_sync_write fs/read_write.c:507 [inline]
 vfs_write+0xc8d/0x1050 fs/read_write.c:594
 ksys_write+0x198/0x2c0 fs/read_write.c:647
 __do_sys_write fs/read_write.c:659 [inline]
 __se_sys_write fs/read_write.c:656 [inline]
 __x64_sys_write+0x7b/0x90 fs/read_write.c:656
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:26 [inline]
 free_pages_prepare mm/page_alloc.c:1364 [inline]
 free_pcp_prepare+0x448/0x450 mm/page_alloc.c:1435
 free_unref_page_prepare mm/page_alloc.c:3433 [inline]
 free_unref_page_list+0x16a/0xad0 mm/page_alloc.c:3554
 release_pages+0xf3e/0xf90 mm/swap.c:1010
 __pagevec_release+0x81/0xf0 mm/swap.c:1030
 pagevec_release include/linux/pagevec.h:81 [inline]
 shmem_undo_range+0x64c/0x1c90 mm/shmem.c:965
 shmem_truncate_range mm/shmem.c:1064 [inline]
 shmem_evict_inode+0x228/0xa30 mm/shmem.c:1146
 evict+0x2a3/0x630 fs/inode.c:587
 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
 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

Memory state around the buggy address:
 ffff888123a80e80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888123a80f00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888123a80f80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888123a81000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888123a81080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/01/21 14:31 android13-5.15-lts 72d681a01da5 cc0f9968 .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-android-5-15 KASAN: use-after-free Read in ext4_ext_rm_leaf
* Struck through repros no longer work on HEAD.