* [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio
@ 2026-02-02 6:20 李龙兴
2026-02-02 14:14 ` Matthew Wilcox
2026-06-30 15:24 ` Longxing Li
0 siblings, 2 replies; 6+ messages in thread
From: 李龙兴 @ 2026-02-02 6:20 UTC (permalink / raw)
To: syzkaller, willy, akpm, linux-fsdevel, linux-mm, linux-kernel
Dear Linux kernel developers and maintainers,
We would like to report a new kernel bug found by our tool. KASAN:
slab-use-after-free Read in filemap_free_folio. Details are as
follows.
Kernel commit: v6.18.2
Kernel config: see attachment
report: see attachment
We are currently analyzing the root cause and working on a
reproducible PoC. We will provide further updates in this thread as
soon as we have more information.
Best regards,
Longxing Li
==================================================================
BUG: KASAN: slab-use-after-free in filemap_free_folio+0x147/0x170
mm/filemap.c:234
Read of size 8 at addr ffff88805e6535a8 by task kworker/u9:28/46327
CPU: 1 UID: 0 PID: 46327 Comm: kworker/u9:28 Not tainted 6.18.2 #1 PREEMPT(full)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Workqueue: ext4-rsv-conversion ext4_end_io_rsv_work
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xcd/0x630 mm/kasan/report.c:482
kasan_report+0xe0/0x110 mm/kasan/report.c:595
filemap_free_folio+0x147/0x170 mm/filemap.c:234
folio_unmap_invalidate+0x514/0x850 mm/truncate.c:653
filemap_end_dropbehind+0x17f/0x1d0 mm/filemap.c:1616
folio_end_dropbehind mm/filemap.c:1637 [inline]
folio_end_dropbehind+0xbe/0xe0 mm/filemap.c:1624
folio_end_writeback+0xe4/0x1f0 mm/filemap.c:1695
ext4_finish_bio+0x78f/0xa20 fs/ext4/page-io.c:144
ext4_release_io_end+0x119/0x3a0 fs/ext4/page-io.c:159
ext4_end_io_end+0x13e/0x4a0 fs/ext4/page-io.c:210
ext4_do_flush_completed_IO fs/ext4/page-io.c:290 [inline]
ext4_end_io_rsv_work+0x205/0x380 fs/ext4/page-io.c:305
process_one_work+0x9cf/0x1b70 kernel/workqueue.c:3263
process_scheduled_works kernel/workqueue.c:3346 [inline]
worker_thread+0x6c8/0xf10 kernel/workqueue.c:3427
kthread+0x3c5/0x780 kernel/kthread.c:463
ret_from_fork+0x675/0x7d0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Allocated by task 49607:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:56
kasan_save_track+0x14/0x30 mm/kasan/common.c:77
unpoison_slab_object mm/kasan/common.c:342 [inline]
__kasan_slab_alloc+0x89/0x90 mm/kasan/common.c:368
kasan_slab_alloc include/linux/kasan.h:252 [inline]
slab_post_alloc_hook mm/slub.c:4978 [inline]
slab_alloc_node mm/slub.c:5288 [inline]
kmem_cache_alloc_lru_noprof+0x254/0x6e0 mm/slub.c:5307
ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393
alloc_inode+0x64/0x240 fs/inode.c:346
new_inode+0x22/0x1c0 fs/inode.c:1145
__ext4_new_inode+0x392/0x4f00 fs/ext4/ialloc.c:961
ext4_create+0x303/0x550 fs/ext4/namei.c:2822
lookup_open.isra.0+0x11d3/0x1580 fs/namei.c:3796
open_last_lookups fs/namei.c:3895 [inline]
path_openat+0x893/0x2cb0 fs/namei.c:4131
do_filp_open+0x20b/0x470 fs/namei.c:4161
do_sys_openat2+0x11b/0x1d0 fs/open.c:1437
do_sys_open fs/open.c:1452 [inline]
__do_sys_openat fs/open.c:1468 [inline]
__se_sys_openat fs/open.c:1463 [inline]
__x64_sys_openat+0x174/0x210 fs/open.c:1463
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 49611:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:56
kasan_save_track+0x14/0x30 mm/kasan/common.c:77
__kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:587
kasan_save_free_info mm/kasan/kasan.h:406 [inline]
poison_slab_object mm/kasan/common.c:252 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:284
kasan_slab_free include/linux/kasan.h:234 [inline]
slab_free_hook mm/slub.c:2543 [inline]
slab_free mm/slub.c:6642 [inline]
kmem_cache_free+0x2d4/0x6c0 mm/slub.c:6752
i_callback+0x46/0x70 fs/inode.c:325
rcu_do_batch kernel/rcu/tree.c:2605 [inline]
rcu_core+0x79c/0x1530 kernel/rcu/tree.c:2861
handle_softirqs+0x219/0x8e0 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
invoke_softirq kernel/softirq.c:496 [inline]
__irq_exit_rcu+0x109/0x170 kernel/softirq.c:723
irq_exit_rcu+0x9/0x30 kernel/softirq.c:739
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1052 [inline]
sysvec_apic_timer_interrupt+0xa4/0xc0 arch/x86/kernel/apic/apic.c:1052
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
Last potentially related work creation:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:56
kasan_record_aux_stack+0xa7/0xc0 mm/kasan/generic.c:559
__call_rcu_common.constprop.0+0xa5/0xa10 kernel/rcu/tree.c:3123
destroy_inode+0x12c/0x1b0 fs/inode.c:401
evict+0x5b4/0x920 fs/inode.c:834
iput_final fs/inode.c:1914 [inline]
iput.part.0+0x6a9/0xb00 fs/inode.c:1966
iput+0x35/0x40 fs/inode.c:1929
do_unlinkat+0x518/0x6a0 fs/namei.c:4744
__do_sys_unlink fs/namei.c:4783 [inline]
__se_sys_unlink fs/namei.c:4781 [inline]
__x64_sys_unlink+0xc5/0x110 fs/namei.c:4781
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Second to last potentially related work creation:
kasan_save_stack+0x33/0x60 mm/kasan/common.c:56
kasan_record_aux_stack+0xa7/0xc0 mm/kasan/generic.c:559
insert_work+0x36/0x230 kernel/workqueue.c:2186
__queue_work+0x97e/0x1160 kernel/workqueue.c:2341
queue_work_on+0x15f/0x1f0 kernel/workqueue.c:2392
queue_work include/linux/workqueue.h:669 [inline]
ext4_add_complete_io fs/ext4/page-io.c:266 [inline]
ext4_put_io_end_defer fs/ext4/page-io.c:325 [inline]
ext4_put_io_end_defer+0x398/0x460 fs/ext4/page-io.c:321
ext4_end_bio+0x2bc/0x580 fs/ext4/page-io.c:385
bio_endio+0x713/0x860 block/bio.c:1672
blk_update_request+0x93e/0x15f0 block/blk-mq.c:999
scsi_end_request+0x7c/0x9c0 drivers/scsi/scsi_lib.c:637
scsi_io_completion+0x17d/0x14c0 drivers/scsi/scsi_lib.c:1078
scsi_complete+0x124/0x250 drivers/scsi/scsi_lib.c:1547
blk_complete_reqs+0xb1/0xf0 block/blk-mq.c:1236
handle_softirqs+0x219/0x8e0 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
invoke_softirq kernel/softirq.c:496 [inline]
__irq_exit_rcu+0x109/0x170 kernel/softirq.c:723
irq_exit_rcu+0x9/0x30 kernel/softirq.c:739
instr_sysvec_call_function_single arch/x86/kernel/smp.c:266 [inline]
sysvec_call_function_single+0x57/0xc0 arch/x86/kernel/smp.c:266
asm_sysvec_call_function_single+0x1a/0x20 arch/x86/include/asm/idtentry.h:704
The buggy address belongs to the object at ffff88805e652fd0
which belongs to the cache ext4_inode_cache of size 2320
The buggy address is located 1496 bytes inside of
freed 2320-byte region [ffff88805e652fd0, ffff88805e6538e0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5e650
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
memcg:ffff8880268b4801
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff888101bc3a00 ffffea0001822400 dead000000000002
raw: 0000000000000000 00000000000d000d 00000000f5000000 ffff8880268b4801
head: 00fff00000000040 ffff888101bc3a00 ffffea0001822400 dead000000000002
head: 0000000000000000 00000000000d000d 00000000f5000000 ffff8880268b4801
head: 00fff00000000003 ffffea0001799401 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Reclaimable, gfp_mask
0xd2050(__GFP_RECLAIMABLE|__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC),
pid 15633, tgid 15633 (syz-executor.7), ts 460463106471, free_ts 0
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x1af/0x220 mm/page_alloc.c:1845
prep_new_page mm/page_alloc.c:1853 [inline]
get_page_from_freelist+0x10a3/0x3a30 mm/page_alloc.c:3879
__alloc_frozen_pages_noprof+0x25f/0x2470 mm/page_alloc.c:5178
alloc_pages_mpol+0x1fb/0x550 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:3059 [inline]
allocate_slab mm/slub.c:3232 [inline]
new_slab+0x24a/0x360 mm/slub.c:3286
___slab_alloc+0xd79/0x1a50 mm/slub.c:4655
__slab_alloc.constprop.0+0x63/0x110 mm/slub.c:4778
__slab_alloc_node mm/slub.c:4854 [inline]
slab_alloc_node mm/slub.c:5276 [inline]
kmem_cache_alloc_lru_noprof+0x443/0x6e0 mm/slub.c:5307
ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393
alloc_inode+0x64/0x240 fs/inode.c:346
new_inode+0x22/0x1c0 fs/inode.c:1145
__ext4_new_inode+0x392/0x4f00 fs/ext4/ialloc.c:961
ext4_symlink+0x462/0xde0 fs/ext4/namei.c:3388
vfs_symlink fs/namei.c:4817 [inline]
vfs_symlink+0x403/0x680 fs/namei.c:4801
do_symlinkat+0x261/0x310 fs/namei.c:4843
__do_sys_symlinkat fs/namei.c:4859 [inline]
__se_sys_symlinkat fs/namei.c:4856 [inline]
__x64_sys_symlinkat+0x93/0xc0 fs/namei.c:4856
page_owner free stack trace missing
Memory state around the buggy address:
ffff88805e653480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805e653500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88805e653580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88805e653600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805e653680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
https://drive.google.com/file/d/1ZjRNEOf0XFYtFl5UZ7dvpJpzmPhje8it/view?usp=drive_link
https://drive.google.com/file/d/1ShZndTsP1CZuwyZmbuZ-e5nHEdPjeIVX/view?usp=drive_link
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 2026-02-02 6:20 [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 李龙兴 @ 2026-02-02 14:14 ` Matthew Wilcox 2026-06-30 15:24 ` Longxing Li 1 sibling, 0 replies; 6+ messages in thread From: Matthew Wilcox @ 2026-02-02 14:14 UTC (permalink / raw) To: 李龙兴 Cc: syzkaller, akpm, linux-fsdevel, linux-mm, linux-kernel, linux-ext4 On Mon, Feb 02, 2026 at 02:20:50PM +0800, 李龙兴 wrote: > Dear Linux kernel developers and maintainers, > > We would like to report a new kernel bug found by our tool. KASAN: Don't be syzbot. Get your changes into syzkaller upstream and let syzbot do its thing. > Allocated by task 49607: > kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 > kasan_save_track+0x14/0x30 mm/kasan/common.c:77 > unpoison_slab_object mm/kasan/common.c:342 [inline] > __kasan_slab_alloc+0x89/0x90 mm/kasan/common.c:368 > kasan_slab_alloc include/linux/kasan.h:252 [inline] > slab_post_alloc_hook mm/slub.c:4978 [inline] > slab_alloc_node mm/slub.c:5288 [inline] > kmem_cache_alloc_lru_noprof+0x254/0x6e0 mm/slub.c:5307 > ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393 I'd suggest this is an ext4 problem, not a pagecache problem. syzbot has good heuristics for this kind of thing now. You don't. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 2026-02-02 6:20 [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 李龙兴 2026-02-02 14:14 ` Matthew Wilcox @ 2026-06-30 15:24 ` Longxing Li 2026-06-30 20:10 ` Andrew Morton 1 sibling, 1 reply; 6+ messages in thread From: Longxing Li @ 2026-06-30 15:24 UTC (permalink / raw) To: syzkaller, willy, akpm, linux-fsdevel, linux-mm, linux-kernel [-- Attachment #1: Type: text/plain, Size: 14213 bytes --] Dear maintainers, I'm trying to fix this issue. The bug analysis and patch fix are as follows. ======================================================== Bug Summary ext4_add_complete_io() queues i_rsv_conversion_work without holding an extra inode reference. If the inode is unlinked & evicted before the delayed work runs, ext4_do_flush_completed_IO() accesses a freed inode — use-after-free. ======================================================== Fix Take igrab(inode) when first queueing the work (detected via list_empty check), and iput() after processing in ext4_do_flush_completed_IO(). A per-inode bit (i_rsv_need_iput) tracks whether the reference was taken. Changes: fs/ext4/ext4.h - add i_rsv_need_iput bit to struct ext4_inode_info fs/ext4/super.c - init the bit to 0 in ext4_alloc_inode() fs/ext4/page-io.c - igrab() before queue_work, iput() after flush Full patch is as follows and is attached in the link. Best regards, Longxing Li ======================================================== Patch: From: Longxing Li <coregee2000@gmail.com> Date: Tue, 30 Jun 2026 Subject: [PATCH] ext4: fix use-after-free in ext4 delayed I/O completion ext4_add_complete_io() queues the inode's i_rsv_conversion_work without holding an extra reference to the inode. If the inode is unlinked and evicted before the delayed work runs, the inode slab object is freed. When ext4_do_flush_completed_IO() later accesses io_end->inode, it is accessing a freed/reallocated object — a use-after-free detected by KASAN. Fix: take an inode reference in ext4_add_complete_io() (when first queueing the work), and drop it in ext4_do_flush_completed_IO() after processing all io_ends. A per-inode flag tracks whether the extra reference was taken. Reported-by: Longxing Li Signed-off-by: Longxing Li <coregee2000@gmail.com> --- --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1158,10 +1158,12 @@ #endif spinlock_t i_block_reservation_lock; /* Lock protecting lists below */ spinlock_t i_completed_io_lock; + /* Track if ext4_add_complete_io() took an extra inode reference. */ + unsigned short i_rsv_need_iput:1; /* * Completed IOs that need unwritten extents handling and have * transaction reserved */ struct list_head i_rsv_conversion_list; --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1414,10 +1414,11 @@ memset(&ei->i_dquot, 0, sizeof(ei->i_dquot)); #endif ei->jinode = NULL; INIT_LIST_HEAD(&ei->i_rsv_conversion_list); spin_lock_init(&ei->i_completed_io_lock); + ei->i_rsv_need_iput = 0; ei->i_sync_tid = 0; ei->i_datasync_tid = 0; INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); ext4_fc_init_inode(&ei->vfs_inode); spin_lock_init(&ei->i_fc_lock); --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -260,12 +260,16 @@ !io_end->handle && sbi->s_journal); WARN_ON(!io_end->bio); spin_lock_irqsave(&ei->i_completed_io_lock, flags); wq = sbi->rsv_conversion_wq; - if (list_empty(&ei->i_rsv_conversion_list)) - queue_work(wq, &ei->i_rsv_conversion_work); + if (list_empty(&ei->i_rsv_conversion_list)) { + if (igrab(io_end->inode)) { + ei->i_rsv_need_iput = 1; + queue_work(wq, &ei->i_rsv_conversion_work); + } + } list_add_tail(&io_end->list, &ei->i_rsv_conversion_list); spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); } static int ext4_do_flush_completed_IO(struct inode *inode, @@ -289,10 +293,17 @@ err = ext4_end_io_end(io_end); if (unlikely(!ret && err)) ret = err; } + + /* Release inode reference from ext4_add_complete_io. */ + if (ei->i_rsv_need_iput) { + ei->i_rsv_need_iput = 0; + iput(&ei->vfs_inode); + } + return ret; } /* * Used to convert unwritten extents to written extents upon IO completion, ======================================================== Patch Link: https://drive.google.com/file/d/1rPdp91vPxDnc74LxOJcJV3juvWhRxUtR/view?usp=drive_link 李龙兴 <coregee2000@gmail.com> 于2026年2月2日周一 14:20写道: > > Dear Linux kernel developers and maintainers, > > We would like to report a new kernel bug found by our tool. KASAN: > slab-use-after-free Read in filemap_free_folio. Details are as > follows. > > Kernel commit: v6.18.2 > Kernel config: see attachment > report: see attachment > > We are currently analyzing the root cause and working on a > reproducible PoC. We will provide further updates in this thread as > soon as we have more information. > > Best regards, > Longxing Li > > ================================================================== > BUG: KASAN: slab-use-after-free in filemap_free_folio+0x147/0x170 > mm/filemap.c:234 > Read of size 8 at addr ffff88805e6535a8 by task kworker/u9:28/46327 > > CPU: 1 UID: 0 PID: 46327 Comm: kworker/u9:28 Not tainted 6.18.2 #1 PREEMPT(full) > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 > Workqueue: ext4-rsv-conversion ext4_end_io_rsv_work > Call Trace: > <TASK> > __dump_stack lib/dump_stack.c:94 [inline] > dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120 > print_address_description mm/kasan/report.c:378 [inline] > print_report+0xcd/0x630 mm/kasan/report.c:482 > kasan_report+0xe0/0x110 mm/kasan/report.c:595 > filemap_free_folio+0x147/0x170 mm/filemap.c:234 > folio_unmap_invalidate+0x514/0x850 mm/truncate.c:653 > filemap_end_dropbehind+0x17f/0x1d0 mm/filemap.c:1616 > folio_end_dropbehind mm/filemap.c:1637 [inline] > folio_end_dropbehind+0xbe/0xe0 mm/filemap.c:1624 > folio_end_writeback+0xe4/0x1f0 mm/filemap.c:1695 > ext4_finish_bio+0x78f/0xa20 fs/ext4/page-io.c:144 > ext4_release_io_end+0x119/0x3a0 fs/ext4/page-io.c:159 > ext4_end_io_end+0x13e/0x4a0 fs/ext4/page-io.c:210 > ext4_do_flush_completed_IO fs/ext4/page-io.c:290 [inline] > ext4_end_io_rsv_work+0x205/0x380 fs/ext4/page-io.c:305 > process_one_work+0x9cf/0x1b70 kernel/workqueue.c:3263 > process_scheduled_works kernel/workqueue.c:3346 [inline] > worker_thread+0x6c8/0xf10 kernel/workqueue.c:3427 > kthread+0x3c5/0x780 kernel/kthread.c:463 > ret_from_fork+0x675/0x7d0 arch/x86/kernel/process.c:158 > ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 > </TASK> > > Allocated by task 49607: > kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 > kasan_save_track+0x14/0x30 mm/kasan/common.c:77 > unpoison_slab_object mm/kasan/common.c:342 [inline] > __kasan_slab_alloc+0x89/0x90 mm/kasan/common.c:368 > kasan_slab_alloc include/linux/kasan.h:252 [inline] > slab_post_alloc_hook mm/slub.c:4978 [inline] > slab_alloc_node mm/slub.c:5288 [inline] > kmem_cache_alloc_lru_noprof+0x254/0x6e0 mm/slub.c:5307 > ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393 > alloc_inode+0x64/0x240 fs/inode.c:346 > new_inode+0x22/0x1c0 fs/inode.c:1145 > __ext4_new_inode+0x392/0x4f00 fs/ext4/ialloc.c:961 > ext4_create+0x303/0x550 fs/ext4/namei.c:2822 > lookup_open.isra.0+0x11d3/0x1580 fs/namei.c:3796 > open_last_lookups fs/namei.c:3895 [inline] > path_openat+0x893/0x2cb0 fs/namei.c:4131 > do_filp_open+0x20b/0x470 fs/namei.c:4161 > do_sys_openat2+0x11b/0x1d0 fs/open.c:1437 > do_sys_open fs/open.c:1452 [inline] > __do_sys_openat fs/open.c:1468 [inline] > __se_sys_openat fs/open.c:1463 [inline] > __x64_sys_openat+0x174/0x210 fs/open.c:1463 > do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] > do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94 > entry_SYSCALL_64_after_hwframe+0x77/0x7f > > Freed by task 49611: > kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 > kasan_save_track+0x14/0x30 mm/kasan/common.c:77 > __kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:587 > kasan_save_free_info mm/kasan/kasan.h:406 [inline] > poison_slab_object mm/kasan/common.c:252 [inline] > __kasan_slab_free+0x5f/0x80 mm/kasan/common.c:284 > kasan_slab_free include/linux/kasan.h:234 [inline] > slab_free_hook mm/slub.c:2543 [inline] > slab_free mm/slub.c:6642 [inline] > kmem_cache_free+0x2d4/0x6c0 mm/slub.c:6752 > i_callback+0x46/0x70 fs/inode.c:325 > rcu_do_batch kernel/rcu/tree.c:2605 [inline] > rcu_core+0x79c/0x1530 kernel/rcu/tree.c:2861 > handle_softirqs+0x219/0x8e0 kernel/softirq.c:622 > __do_softirq kernel/softirq.c:656 [inline] > invoke_softirq kernel/softirq.c:496 [inline] > __irq_exit_rcu+0x109/0x170 kernel/softirq.c:723 > irq_exit_rcu+0x9/0x30 kernel/softirq.c:739 > instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1052 [inline] > sysvec_apic_timer_interrupt+0xa4/0xc0 arch/x86/kernel/apic/apic.c:1052 > asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697 > > Last potentially related work creation: > kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 > kasan_record_aux_stack+0xa7/0xc0 mm/kasan/generic.c:559 > __call_rcu_common.constprop.0+0xa5/0xa10 kernel/rcu/tree.c:3123 > destroy_inode+0x12c/0x1b0 fs/inode.c:401 > evict+0x5b4/0x920 fs/inode.c:834 > iput_final fs/inode.c:1914 [inline] > iput.part.0+0x6a9/0xb00 fs/inode.c:1966 > iput+0x35/0x40 fs/inode.c:1929 > do_unlinkat+0x518/0x6a0 fs/namei.c:4744 > __do_sys_unlink fs/namei.c:4783 [inline] > __se_sys_unlink fs/namei.c:4781 [inline] > __x64_sys_unlink+0xc5/0x110 fs/namei.c:4781 > do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] > do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94 > entry_SYSCALL_64_after_hwframe+0x77/0x7f > > Second to last potentially related work creation: > kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 > kasan_record_aux_stack+0xa7/0xc0 mm/kasan/generic.c:559 > insert_work+0x36/0x230 kernel/workqueue.c:2186 > __queue_work+0x97e/0x1160 kernel/workqueue.c:2341 > queue_work_on+0x15f/0x1f0 kernel/workqueue.c:2392 > queue_work include/linux/workqueue.h:669 [inline] > ext4_add_complete_io fs/ext4/page-io.c:266 [inline] > ext4_put_io_end_defer fs/ext4/page-io.c:325 [inline] > ext4_put_io_end_defer+0x398/0x460 fs/ext4/page-io.c:321 > ext4_end_bio+0x2bc/0x580 fs/ext4/page-io.c:385 > bio_endio+0x713/0x860 block/bio.c:1672 > blk_update_request+0x93e/0x15f0 block/blk-mq.c:999 > scsi_end_request+0x7c/0x9c0 drivers/scsi/scsi_lib.c:637 > scsi_io_completion+0x17d/0x14c0 drivers/scsi/scsi_lib.c:1078 > scsi_complete+0x124/0x250 drivers/scsi/scsi_lib.c:1547 > blk_complete_reqs+0xb1/0xf0 block/blk-mq.c:1236 > handle_softirqs+0x219/0x8e0 kernel/softirq.c:622 > __do_softirq kernel/softirq.c:656 [inline] > invoke_softirq kernel/softirq.c:496 [inline] > __irq_exit_rcu+0x109/0x170 kernel/softirq.c:723 > irq_exit_rcu+0x9/0x30 kernel/softirq.c:739 > instr_sysvec_call_function_single arch/x86/kernel/smp.c:266 [inline] > sysvec_call_function_single+0x57/0xc0 arch/x86/kernel/smp.c:266 > asm_sysvec_call_function_single+0x1a/0x20 arch/x86/include/asm/idtentry.h:704 > > The buggy address belongs to the object at ffff88805e652fd0 > which belongs to the cache ext4_inode_cache of size 2320 > The buggy address is located 1496 bytes inside of > freed 2320-byte region [ffff88805e652fd0, ffff88805e6538e0) > > The buggy address belongs to the physical page: > page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5e650 > head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 > memcg:ffff8880268b4801 > flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff) > page_type: f5(slab) > raw: 00fff00000000040 ffff888101bc3a00 ffffea0001822400 dead000000000002 > raw: 0000000000000000 00000000000d000d 00000000f5000000 ffff8880268b4801 > head: 00fff00000000040 ffff888101bc3a00 ffffea0001822400 dead000000000002 > head: 0000000000000000 00000000000d000d 00000000f5000000 ffff8880268b4801 > head: 00fff00000000003 ffffea0001799401 00000000ffffffff 00000000ffffffff > head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008 > page dumped because: kasan: bad access detected > page_owner tracks the page as allocated > page last allocated via order 3, migratetype Reclaimable, gfp_mask > 0xd2050(__GFP_RECLAIMABLE|__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), > pid 15633, tgid 15633 (syz-executor.7), ts 460463106471, free_ts 0 > set_page_owner include/linux/page_owner.h:32 [inline] > post_alloc_hook+0x1af/0x220 mm/page_alloc.c:1845 > prep_new_page mm/page_alloc.c:1853 [inline] > get_page_from_freelist+0x10a3/0x3a30 mm/page_alloc.c:3879 > __alloc_frozen_pages_noprof+0x25f/0x2470 mm/page_alloc.c:5178 > alloc_pages_mpol+0x1fb/0x550 mm/mempolicy.c:2416 > alloc_slab_page mm/slub.c:3059 [inline] > allocate_slab mm/slub.c:3232 [inline] > new_slab+0x24a/0x360 mm/slub.c:3286 > ___slab_alloc+0xd79/0x1a50 mm/slub.c:4655 > __slab_alloc.constprop.0+0x63/0x110 mm/slub.c:4778 > __slab_alloc_node mm/slub.c:4854 [inline] > slab_alloc_node mm/slub.c:5276 [inline] > kmem_cache_alloc_lru_noprof+0x443/0x6e0 mm/slub.c:5307 > ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393 > alloc_inode+0x64/0x240 fs/inode.c:346 > new_inode+0x22/0x1c0 fs/inode.c:1145 > __ext4_new_inode+0x392/0x4f00 fs/ext4/ialloc.c:961 > ext4_symlink+0x462/0xde0 fs/ext4/namei.c:3388 > vfs_symlink fs/namei.c:4817 [inline] > vfs_symlink+0x403/0x680 fs/namei.c:4801 > do_symlinkat+0x261/0x310 fs/namei.c:4843 > __do_sys_symlinkat fs/namei.c:4859 [inline] > __se_sys_symlinkat fs/namei.c:4856 [inline] > __x64_sys_symlinkat+0x93/0xc0 fs/namei.c:4856 > page_owner free stack trace missing > > Memory state around the buggy address: > ffff88805e653480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb > ffff88805e653500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb > >ffff88805e653580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb > ^ > ffff88805e653600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb > ffff88805e653680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb > ================================================================== > > https://drive.google.com/file/d/1ZjRNEOf0XFYtFl5UZ7dvpJpzmPhje8it/view?usp=drive_link > > https://drive.google.com/file/d/1ShZndTsP1CZuwyZmbuZ-e5nHEdPjeIVX/view?usp=drive_link [-- Attachment #2: bug-fix.patch.txt --] [-- Type: text/plain, Size: 2705 bytes --] From: Longxing Li <coregee2000@gmail.com> Date: Tue, 30 Jun 2026 Subject: [PATCH] ext4: fix use-after-free in ext4 delayed I/O completion ext4_add_complete_io() queues the inode's i_rsv_conversion_work without holding an extra reference to the inode. If the inode is unlinked and evicted before the delayed work runs, the inode slab object is freed. When ext4_do_flush_completed_IO() later accesses io_end->inode, it is accessing a freed/reallocated object — a use-after-free detected by KASAN. Fix: take an inode reference in ext4_add_complete_io() (when first queueing the work), and drop it in ext4_do_flush_completed_IO() after processing all io_ends. A per-inode flag tracks whether the extra reference was taken. Reported-by: syzkaller Signed-off-by: Longxing Li <coregee2000@gmail.com> --- --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1158,10 +1158,12 @@ #endif spinlock_t i_block_reservation_lock; /* Lock protecting lists below */ spinlock_t i_completed_io_lock; + /* Track if ext4_add_complete_io() took an extra inode reference. */ + unsigned short i_rsv_need_iput:1; /* * Completed IOs that need unwritten extents handling and have * transaction reserved */ struct list_head i_rsv_conversion_list; --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1414,10 +1414,11 @@ memset(&ei->i_dquot, 0, sizeof(ei->i_dquot)); #endif ei->jinode = NULL; INIT_LIST_HEAD(&ei->i_rsv_conversion_list); spin_lock_init(&ei->i_completed_io_lock); + ei->i_rsv_need_iput = 0; ei->i_sync_tid = 0; ei->i_datasync_tid = 0; INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); ext4_fc_init_inode(&ei->vfs_inode); spin_lock_init(&ei->i_fc_lock); --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -260,12 +260,16 @@ !io_end->handle && sbi->s_journal); WARN_ON(!io_end->bio); spin_lock_irqsave(&ei->i_completed_io_lock, flags); wq = sbi->rsv_conversion_wq; - if (list_empty(&ei->i_rsv_conversion_list)) - queue_work(wq, &ei->i_rsv_conversion_work); + if (list_empty(&ei->i_rsv_conversion_list)) { + if (igrab(io_end->inode)) { + ei->i_rsv_need_iput = 1; + queue_work(wq, &ei->i_rsv_conversion_work); + } + } list_add_tail(&io_end->list, &ei->i_rsv_conversion_list); spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); } static int ext4_do_flush_completed_IO(struct inode *inode, @@ -289,10 +293,17 @@ err = ext4_end_io_end(io_end); if (unlikely(!ret && err)) ret = err; } + + /* Release inode reference from ext4_add_complete_io. */ + if (ei->i_rsv_need_iput) { + ei->i_rsv_need_iput = 0; + iput(&ei->vfs_inode); + } + return ret; } /* * Used to convert unwritten extents to written extents upon IO completion, ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 2026-06-30 15:24 ` Longxing Li @ 2026-06-30 20:10 ` Andrew Morton 2026-07-02 7:59 ` Longxing Li 0 siblings, 1 reply; 6+ messages in thread From: Andrew Morton @ 2026-06-30 20:10 UTC (permalink / raw) To: Longxing Li; +Cc: syzkaller, willy, linux-fsdevel, linux-mm, linux-kernel On Tue, 30 Jun 2026 23:24:58 +0800 Longxing Li <coregee2000@gmail.com> wrote: > Dear maintainers, > > I'm trying to fix this issue. Great, thanks. > The bug analysis and patch fix are as follows. > ======================================================== > Bug Summary > > ext4_add_complete_io() queues i_rsv_conversion_work without holding an > extra inode reference. If the inode is unlinked & evicted before the > delayed work runs, ext4_do_flush_completed_IO() accesses a freed inode — > use-after-free. You omitted the ext4 developers! scripts/get_maintainer.pl -f --no-rolestats fs/ext4 is a good way to find them. Also, your email client is converting tabs to spaces. So please fix those things up and resend? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 2026-06-30 20:10 ` Andrew Morton @ 2026-07-02 7:59 ` Longxing Li 2026-07-15 13:24 ` Zhou, Yun 0 siblings, 1 reply; 6+ messages in thread From: Longxing Li @ 2026-07-02 7:59 UTC (permalink / raw) To: Andrew Morton, syzkaller, willy, linux-fsdevel, linux-mm, linux-kernel, adilger.kernel, linux-ext4 [-- Attachment #1: Type: text/plain, Size: 13381 bytes --] Dear maintainers, I'm trying to fix this issue. The bug analysis and patch fix are as follows. ======================================================== Bug Summary ext4_add_complete_io() queues i_rsv_conversion_work without holding an extra inode reference. If the inode is unlinked & evicted before the delayed work runs, ext4_do_flush_completed_IO() accesses a freed inode — use-after-free. ======================================================== Fix Take igrab(inode) when first queueing the work (detected via list_empty check), and iput() after processing in ext4_do_flush_completed_IO(). A per-inode bit (i_rsv_need_iput) tracks whether the reference was taken. Changes: fs/ext4/ext4.h - add i_rsv_need_iput bit to struct ext4_inode_info fs/ext4/super.c - init the bit to 0 in ext4_alloc_inode() fs/ext4/page-io.c - igrab() before queue_work, iput() after flush Full patch is as follows and is attached in the link. Best regards, Longxing Li ======================================================== Patch: (Standard format patch Please see atachment and the link after this chunk.) From: Longxing Li <coregee2000@gmail.com> Date: Tue, 30 Jun 2026 Subject: [PATCH] ext4: fix use-after-free in ext4 delayed I/O completion ext4_add_complete_io() queues the inode's i_rsv_conversion_work without holding an extra reference to the inode. If the inode is unlinked and evicted before the delayed work runs, the inode slab object is freed. When ext4_do_flush_completed_IO() later accesses io_end->inode, it is accessing a freed/reallocated object — a use-after-free detected by KASAN. Fix: take an inode reference in ext4_add_complete_io() (when first queueing the work), and drop it in ext4_do_flush_completed_IO() after processing all io_ends. A per-inode flag tracks whether the extra reference was taken. Signed-off-by: Longxing Li <coregee2000@gmail.com> --- --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1158,10 +1158,12 @@ #endif spinlock_t i_block_reservation_lock; /* Lock protecting lists below */ spinlock_t i_completed_io_lock; + /* Track if ext4_add_complete_io() took an extra inode reference. */ + unsigned short i_rsv_need_iput:1; /* * Completed IOs that need unwritten extents handling and have * transaction reserved */ struct list_head i_rsv_conversion_list; --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1414,10 +1414,11 @@ memset(&ei->i_dquot, 0, sizeof(ei->i_dquot)); #endif ei->jinode = NULL; INIT_LIST_HEAD(&ei->i_rsv_conversion_list); spin_lock_init(&ei->i_completed_io_lock); + ei->i_rsv_need_iput = 0; ei->i_sync_tid = 0; ei->i_datasync_tid = 0; INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); ext4_fc_init_inode(&ei->vfs_inode); spin_lock_init(&ei->i_fc_lock); --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -260,12 +260,16 @@ !io_end->handle && sbi->s_journal); WARN_ON(!io_end->bio); spin_lock_irqsave(&ei->i_completed_io_lock, flags); wq = sbi->rsv_conversion_wq; - if (list_empty(&ei->i_rsv_conversion_list)) - queue_work(wq, &ei->i_rsv_conversion_work); + if (list_empty(&ei->i_rsv_conversion_list)) { + if (igrab(io_end->inode)) { + ei->i_rsv_need_iput = 1; + queue_work(wq, &ei->i_rsv_conversion_work); + } + } list_add_tail(&io_end->list, &ei->i_rsv_conversion_list); spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); } static int ext4_do_flush_completed_IO(struct inode *inode, @@ -289,10 +293,17 @@ err = ext4_end_io_end(io_end); if (unlikely(!ret && err)) ret = err; } + + /* Release inode reference from ext4_add_complete_io. */ + if (ei->i_rsv_need_iput) { + ei->i_rsv_need_iput = 0; + iput(&ei->vfs_inode); + } + return ret; } /* * Used to convert unwritten extents to written extents upon IO completion, ======================================================== Attachment: https://drive.google.com/file/d/1rPdp91vPxDnc74LxOJcJV3juvWhRxUtR/view?usp=drive_link ================================================================== Original Bug Report on Linux kernel v6.18.2: BUG: KASAN: slab-use-after-free in filemap_free_folio+0x147/0x170 mm/filemap.c:234 Read of size 8 at addr ffff88805e6535a8 by task kworker/u9:28/46327 CPU: 1 UID: 0 PID: 46327 Comm: kworker/u9:28 Not tainted 6.18.2 #1 PREEMPT(full) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 Workqueue: ext4-rsv-conversion ext4_end_io_rsv_work Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xcd/0x630 mm/kasan/report.c:482 kasan_report+0xe0/0x110 mm/kasan/report.c:595 filemap_free_folio+0x147/0x170 mm/filemap.c:234 folio_unmap_invalidate+0x514/0x850 mm/truncate.c:653 filemap_end_dropbehind+0x17f/0x1d0 mm/filemap.c:1616 folio_end_dropbehind mm/filemap.c:1637 [inline] folio_end_dropbehind+0xbe/0xe0 mm/filemap.c:1624 folio_end_writeback+0xe4/0x1f0 mm/filemap.c:1695 ext4_finish_bio+0x78f/0xa20 fs/ext4/page-io.c:144 ext4_release_io_end+0x119/0x3a0 fs/ext4/page-io.c:159 ext4_end_io_end+0x13e/0x4a0 fs/ext4/page-io.c:210 ext4_do_flush_completed_IO fs/ext4/page-io.c:290 [inline] ext4_end_io_rsv_work+0x205/0x380 fs/ext4/page-io.c:305 process_one_work+0x9cf/0x1b70 kernel/workqueue.c:3263 process_scheduled_works kernel/workqueue.c:3346 [inline] worker_thread+0x6c8/0xf10 kernel/workqueue.c:3427 kthread+0x3c5/0x780 kernel/kthread.c:463 ret_from_fork+0x675/0x7d0 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 </TASK> Allocated by task 49607: kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 kasan_save_track+0x14/0x30 mm/kasan/common.c:77 unpoison_slab_object mm/kasan/common.c:342 [inline] __kasan_slab_alloc+0x89/0x90 mm/kasan/common.c:368 kasan_slab_alloc include/linux/kasan.h:252 [inline] slab_post_alloc_hook mm/slub.c:4978 [inline] slab_alloc_node mm/slub.c:5288 [inline] kmem_cache_alloc_lru_noprof+0x254/0x6e0 mm/slub.c:5307 ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393 alloc_inode+0x64/0x240 fs/inode.c:346 new_inode+0x22/0x1c0 fs/inode.c:1145 __ext4_new_inode+0x392/0x4f00 fs/ext4/ialloc.c:961 ext4_create+0x303/0x550 fs/ext4/namei.c:2822 lookup_open.isra.0+0x11d3/0x1580 fs/namei.c:3796 open_last_lookups fs/namei.c:3895 [inline] path_openat+0x893/0x2cb0 fs/namei.c:4131 do_filp_open+0x20b/0x470 fs/namei.c:4161 do_sys_openat2+0x11b/0x1d0 fs/open.c:1437 do_sys_open fs/open.c:1452 [inline] __do_sys_openat fs/open.c:1468 [inline] __se_sys_openat fs/open.c:1463 [inline] __x64_sys_openat+0x174/0x210 fs/open.c:1463 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 49611: kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 kasan_save_track+0x14/0x30 mm/kasan/common.c:77 __kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:587 kasan_save_free_info mm/kasan/kasan.h:406 [inline] poison_slab_object mm/kasan/common.c:252 [inline] __kasan_slab_free+0x5f/0x80 mm/kasan/common.c:284 kasan_slab_free include/linux/kasan.h:234 [inline] slab_free_hook mm/slub.c:2543 [inline] slab_free mm/slub.c:6642 [inline] kmem_cache_free+0x2d4/0x6c0 mm/slub.c:6752 i_callback+0x46/0x70 fs/inode.c:325 rcu_do_batch kernel/rcu/tree.c:2605 [inline] rcu_core+0x79c/0x1530 kernel/rcu/tree.c:2861 handle_softirqs+0x219/0x8e0 kernel/softirq.c:622 __do_softirq kernel/softirq.c:656 [inline] invoke_softirq kernel/softirq.c:496 [inline] __irq_exit_rcu+0x109/0x170 kernel/softirq.c:723 irq_exit_rcu+0x9/0x30 kernel/softirq.c:739 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1052 [inline] sysvec_apic_timer_interrupt+0xa4/0xc0 arch/x86/kernel/apic/apic.c:1052 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697 Last potentially related work creation: kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 kasan_record_aux_stack+0xa7/0xc0 mm/kasan/generic.c:559 __call_rcu_common.constprop.0+0xa5/0xa10 kernel/rcu/tree.c:3123 destroy_inode+0x12c/0x1b0 fs/inode.c:401 evict+0x5b4/0x920 fs/inode.c:834 iput_final fs/inode.c:1914 [inline] iput.part.0+0x6a9/0xb00 fs/inode.c:1966 iput+0x35/0x40 fs/inode.c:1929 do_unlinkat+0x518/0x6a0 fs/namei.c:4744 __do_sys_unlink fs/namei.c:4783 [inline] __se_sys_unlink fs/namei.c:4781 [inline] __x64_sys_unlink+0xc5/0x110 fs/namei.c:4781 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Second to last potentially related work creation: kasan_save_stack+0x33/0x60 mm/kasan/common.c:56 kasan_record_aux_stack+0xa7/0xc0 mm/kasan/generic.c:559 insert_work+0x36/0x230 kernel/workqueue.c:2186 __queue_work+0x97e/0x1160 kernel/workqueue.c:2341 queue_work_on+0x15f/0x1f0 kernel/workqueue.c:2392 queue_work include/linux/workqueue.h:669 [inline] ext4_add_complete_io fs/ext4/page-io.c:266 [inline] ext4_put_io_end_defer fs/ext4/page-io.c:325 [inline] ext4_put_io_end_defer+0x398/0x460 fs/ext4/page-io.c:321 ext4_end_bio+0x2bc/0x580 fs/ext4/page-io.c:385 bio_endio+0x713/0x860 block/bio.c:1672 blk_update_request+0x93e/0x15f0 block/blk-mq.c:999 scsi_end_request+0x7c/0x9c0 drivers/scsi/scsi_lib.c:637 scsi_io_completion+0x17d/0x14c0 drivers/scsi/scsi_lib.c:1078 scsi_complete+0x124/0x250 drivers/scsi/scsi_lib.c:1547 blk_complete_reqs+0xb1/0xf0 block/blk-mq.c:1236 handle_softirqs+0x219/0x8e0 kernel/softirq.c:622 __do_softirq kernel/softirq.c:656 [inline] invoke_softirq kernel/softirq.c:496 [inline] __irq_exit_rcu+0x109/0x170 kernel/softirq.c:723 irq_exit_rcu+0x9/0x30 kernel/softirq.c:739 instr_sysvec_call_function_single arch/x86/kernel/smp.c:266 [inline] sysvec_call_function_single+0x57/0xc0 arch/x86/kernel/smp.c:266 asm_sysvec_call_function_single+0x1a/0x20 arch/x86/include/asm/idtentry.h:704 The buggy address belongs to the object at ffff88805e652fd0 which belongs to the cache ext4_inode_cache of size 2320 The buggy address is located 1496 bytes inside of freed 2320-byte region [ffff88805e652fd0, ffff88805e6538e0) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5e650 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 memcg:ffff8880268b4801 flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff) page_type: f5(slab) raw: 00fff00000000040 ffff888101bc3a00 ffffea0001822400 dead000000000002 raw: 0000000000000000 00000000000d000d 00000000f5000000 ffff8880268b4801 head: 00fff00000000040 ffff888101bc3a00 ffffea0001822400 dead000000000002 head: 0000000000000000 00000000000d000d 00000000f5000000 ffff8880268b4801 head: 00fff00000000003 ffffea0001799401 00000000ffffffff 00000000ffffffff head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008 page dumped because: kasan: bad access detected page_owner tracks the page as allocated page last allocated via order 3, migratetype Reclaimable, gfp_mask 0xd2050(__GFP_RECLAIMABLE|__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 15633, tgid 15633 (syz-executor.7), ts 460463106471, free_ts 0 set_page_owner include/linux/page_owner.h:32 [inline] post_alloc_hook+0x1af/0x220 mm/page_alloc.c:1845 prep_new_page mm/page_alloc.c:1853 [inline] get_page_from_freelist+0x10a3/0x3a30 mm/page_alloc.c:3879 __alloc_frozen_pages_noprof+0x25f/0x2470 mm/page_alloc.c:5178 alloc_pages_mpol+0x1fb/0x550 mm/mempolicy.c:2416 alloc_slab_page mm/slub.c:3059 [inline] allocate_slab mm/slub.c:3232 [inline] new_slab+0x24a/0x360 mm/slub.c:3286 ___slab_alloc+0xd79/0x1a50 mm/slub.c:4655 __slab_alloc.constprop.0+0x63/0x110 mm/slub.c:4778 __slab_alloc_node mm/slub.c:4854 [inline] slab_alloc_node mm/slub.c:5276 [inline] kmem_cache_alloc_lru_noprof+0x443/0x6e0 mm/slub.c:5307 ext4_alloc_inode+0x28/0x610 fs/ext4/super.c:1393 alloc_inode+0x64/0x240 fs/inode.c:346 new_inode+0x22/0x1c0 fs/inode.c:1145 __ext4_new_inode+0x392/0x4f00 fs/ext4/ialloc.c:961 ext4_symlink+0x462/0xde0 fs/ext4/namei.c:3388 vfs_symlink fs/namei.c:4817 [inline] vfs_symlink+0x403/0x680 fs/namei.c:4801 do_symlinkat+0x261/0x310 fs/namei.c:4843 __do_sys_symlinkat fs/namei.c:4859 [inline] __se_sys_symlinkat fs/namei.c:4856 [inline] __x64_sys_symlinkat+0x93/0xc0 fs/namei.c:4856 page_owner free stack trace missing Memory state around the buggy address: ffff88805e653480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88805e653500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88805e653580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88805e653600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88805e653680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== [-- Attachment #2: bug-fix.patch.txt --] [-- Type: text/plain, Size: 2705 bytes --] From: Longxing Li <coregee2000@gmail.com> Date: Tue, 30 Jun 2026 Subject: [PATCH] ext4: fix use-after-free in ext4 delayed I/O completion ext4_add_complete_io() queues the inode's i_rsv_conversion_work without holding an extra reference to the inode. If the inode is unlinked and evicted before the delayed work runs, the inode slab object is freed. When ext4_do_flush_completed_IO() later accesses io_end->inode, it is accessing a freed/reallocated object — a use-after-free detected by KASAN. Fix: take an inode reference in ext4_add_complete_io() (when first queueing the work), and drop it in ext4_do_flush_completed_IO() after processing all io_ends. A per-inode flag tracks whether the extra reference was taken. Reported-by: syzkaller Signed-off-by: Longxing Li <coregee2000@gmail.com> --- --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1158,10 +1158,12 @@ #endif spinlock_t i_block_reservation_lock; /* Lock protecting lists below */ spinlock_t i_completed_io_lock; + /* Track if ext4_add_complete_io() took an extra inode reference. */ + unsigned short i_rsv_need_iput:1; /* * Completed IOs that need unwritten extents handling and have * transaction reserved */ struct list_head i_rsv_conversion_list; --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1414,10 +1414,11 @@ memset(&ei->i_dquot, 0, sizeof(ei->i_dquot)); #endif ei->jinode = NULL; INIT_LIST_HEAD(&ei->i_rsv_conversion_list); spin_lock_init(&ei->i_completed_io_lock); + ei->i_rsv_need_iput = 0; ei->i_sync_tid = 0; ei->i_datasync_tid = 0; INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); ext4_fc_init_inode(&ei->vfs_inode); spin_lock_init(&ei->i_fc_lock); --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -260,12 +260,16 @@ !io_end->handle && sbi->s_journal); WARN_ON(!io_end->bio); spin_lock_irqsave(&ei->i_completed_io_lock, flags); wq = sbi->rsv_conversion_wq; - if (list_empty(&ei->i_rsv_conversion_list)) - queue_work(wq, &ei->i_rsv_conversion_work); + if (list_empty(&ei->i_rsv_conversion_list)) { + if (igrab(io_end->inode)) { + ei->i_rsv_need_iput = 1; + queue_work(wq, &ei->i_rsv_conversion_work); + } + } list_add_tail(&io_end->list, &ei->i_rsv_conversion_list); spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); } static int ext4_do_flush_completed_IO(struct inode *inode, @@ -289,10 +293,17 @@ err = ext4_end_io_end(io_end); if (unlikely(!ret && err)) ret = err; } + + /* Release inode reference from ext4_add_complete_io. */ + if (ei->i_rsv_need_iput) { + ei->i_rsv_need_iput = 0; + iput(&ei->vfs_inode); + } + return ret; } /* * Used to convert unwritten extents to written extents upon IO completion, ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 2026-07-02 7:59 ` Longxing Li @ 2026-07-15 13:24 ` Zhou, Yun 0 siblings, 0 replies; 6+ messages in thread From: Zhou, Yun @ 2026-07-15 13:24 UTC (permalink / raw) To: Longxing Li, Andrew Morton, syzkaller, willy, linux-fsdevel, linux-mm, linux-kernel, adilger.kernel, linux-ext4 Hi, On 7/2/2026 3:59 PM, Longxing Li wrote: > > Dear maintainers, > > I'm trying to fix this issue. The bug analysis and patch fix are as follows. > ======================================================== > Bug Summary > > ext4_add_complete_io() queues i_rsv_conversion_work without holding an > extra inode reference. If the inode is unlinked & evicted before the > delayed work runs, ext4_do_flush_completed_IO() accesses a freed inode — > use-after-free. > > ======================================================== > Fix > > Take igrab(inode) when first queueing the work (detected via > list_empty check), and iput() after processing in > ext4_do_flush_completed_IO(). A per-inode bit (i_rsv_need_iput) tracks > whether the reference was taken. > > Changes: > fs/ext4/ext4.h - add i_rsv_need_iput bit to struct ext4_inode_info > fs/ext4/super.c - init the bit to 0 in ext4_alloc_inode() > fs/ext4/page-io.c - igrab() before queue_work, iput() after flush > > Full patch is as follows and is attached in the link. > Although I'm also a newbie, I should point out that the way you're sending the patch isn't quite right. You can just use the git send-email command directly. For example: git send-email --to tytso@mit.edu --to adilger.kernel@dilger.ca --to libaokun@linux.alibaba.com --to jack@suse.cz --to ojaswin@linux.ibm.com --to ritesh.list@gmail.com --to yi.zhang@huawei.com --cc linux-ext4@vger.kernel.org --cc linux-kernel@vger.kernel.org bug-fix.patch If you're unsure which maintainers, reviewers, or mailing lists to send a patch to, you can use the ./scripts/get_maintainer.pl script in the source directory to find out. Before sending, it's best to do thorough functional and regression testing. You should also run the ./scripts/checkpatch.pl script to check for any formatting issues in your patch. It's a good idea to read the documentation in the Documentation/process/ directory first. No rush, take your time. Feel free to ask me if you have any more questions. Yun ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-15 13:25 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-02-02 6:20 [Kernel Bug] KASAN: slab-use-after-free Read in filemap_free_folio 李龙兴 2026-02-02 14:14 ` Matthew Wilcox 2026-06-30 15:24 ` Longxing Li 2026-06-30 20:10 ` Andrew Morton 2026-07-02 7:59 ` Longxing Li 2026-07-15 13:24 ` Zhou, Yun
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
Powered by JetHome