KASAN: slab-use-after-free Read in ext4_discard_work

Status: upstream: reported on 2026/11/25 00:32
Subsystems: ext4
Labels: prio:high actionable
[Documentation on labels]
Reported-by: syzbot+a04f55598145a622ba5e@syzkaller.appspotmail.com
First crash: 5d02h, last: 17h31m
✨ AI cause bisection: introduced by (AI job) :
commit 55cdd0af2bc5ffc92a2deb745627755aecd5db33
Author: Wang Jianchao <wangjianchao@kuaishou.com>
Date: Sat Jul 24 07:41:23 2021 +0000

  ext4: get discard out of jbd2 commit kthread contex

✨ AI-generated root cause summary:

During a failed ext4 mount in __ext4_fill_super(), the error-cleanup path calls ext4_mb_release() (at failed_mount6) before calling ext4_journal_destroy() (at failed_mount_wq). Because sbi->s_journal->j_commit_callback (ext4_journal_commit_callback) remains active until ext4_journal_destroy() finishes, a transaction commit triggered during mount error handling or journal teardown invokes ext4_process_freed_data(), which queues &sbi->s_discard_work when the DISCARD mount option is set (even if freed_data_list is empty). Since ext4_mb_release() has already run and flushed s_discard_work earlier in the cleanup path, s_discard_work is never flushed again before ext4_fill_super() frees sbi via ext4_free_sbi(), resulting in a slab use-after-free when ext4_discard_work() subsequently reads sbi->s_sb.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit e8017d29067f:

Root Cause Analysis

The slab use-after-free occurs because the error-cleanup path in __ext4_fill_super() (fs/ext4/super.c) tears down mballoc (ext4_mb_release()) before shutting down the JBD2 journal (ext4_journal_destroy()), allowing a subsequent journal commit callback to re-queue sbi->s_discard_work after ext4_mb_release() has already flushed it and before ext4_free_sbi() frees sbi.

Detailed Mechanism

  1. Initialization during mount (fs/ext4/super.c):

  2. Mount failure triggers a journaled superblock update:

    • ext4_init_orphan_info(sb) (fs/ext4/super.c:5751) fails on a corrupted orphan file block checksum at fs/ext4/orphan.c:625 and calls ext4_error().
    • ext4_handle_error() (fs/ext4/super.c:734) schedules sbi->s_sb_upd_work (update_super_work), which starts and stops a JBD2 handle (jbd2_journal_start() / jbd2_journal_dirty_metadata() / jbd2_journal_stop() in fs/ext4/super.c:783-806) to record the error in the superblock.
    • ext4_init_orphan_info() returns -EIO, jumping to failed_mount7 in __ext4_fill_super().
  3. Inverted teardown order in __ext4_fill_super():

    • At failed_mount6, __ext4_fill_super() calls ext4_mb_release(sb) (fs/ext4/super.c:5823). Inside ext4_mb_release() (fs/ext4/mballoc.c:3898), flush_work(&sbi->s_discard_work) runs and drains any currently queued discard work, then mballoc structures are freed.
    • However, sbi->s_journal is still running with j_commit_callback still pointing to ext4_journal_commit_callback.
    • Later, at failed_mount_wq, __ext4_fill_super() calls ext4_journal_destroy(sbi, sbi->s_journal) (fs/ext4/super.c:5846, defined in fs/ext4/ext4_jbd2.h:437), which calls ext4_force_commit(), flush_work(&sbi->s_sb_upd_work), and jbd2_journal_destroy().
    • When kjournald2 commits the transaction in jbd2_journal_commit_transaction(), it invokes ext4_journal_commit_callback() (fs/ext4/super.c:526) -> ext4_process_freed_data() (fs/ext4/mballoc.c:4018).
    • In ext4_process_freed_data() (fs/ext4/mballoc.c:4031-4037), when test_opt(sb, DISCARD) is set and list_empty(&sbi->s_discard_list) is true, it unconditionally calls queue_work(system_dfl_wq, &sbi->s_discard_work)β€”even when freed_data_list is empty. (Note also that EXT4_MOUNT_DISCARD has not yet been cleared for non-discard devices because that check at fs/ext4/super.c:5787 comes after ext4_init_orphan_info().)
  4. Use-after-free:

    • After ext4_journal_destroy() finishes, __ext4_fill_super() returns the error without flushing sbi->s_discard_work again.
    • ext4_fill_super() frees sbi via ext4_free_sbi(sbi) (fs/ext4/super.c:5925 -> 4418).
    • When the worker thread subsequently runs ext4_discard_work() (fs/ext4/mballoc.c:3645), reading sbi->s_sb (at offset 1008 bytes in struct ext4_sb_info) accesses the freed kmalloc-8k slab object.

Note that normal unmount in ext4_put_super() (fs/ext4/super.c:1333-1345) avoids this by calling ext4_journal_destroy() before ext4_mb_release(sb). In __ext4_fill_super(), either the journal must be destroyed (or j_commit_callback / s_discard_work handled) before ext4_mb_release(), or s_discard_work must not be queued once teardown/mballoc release begins and must be flushed after ext4_journal_destroy(). Additionally, ext4_process_freed_data() does not need to queue s_discard_work if freed_data_list is empty.

▶ ▼ ✨ AI Jobs (4)
ID Workflow Result Correct Bug Created Started Finished Revision
75a04491 moderation Actionable: βœ… ❓ KASAN: slab-use-after-free Read in ext4_discard_work 2026/11/25 00:01 2026/11/25 00:01 2026/11/25 00:31 e76bb7a5
80e9600f repro-c Reproduced: βœ… ❓ KASAN: slab-use-after-free Read in ext4_discard_work 2026/11/22 00:02 2026/11/22 00:02 2026/11/22 03:40 b2c69459
40c391cc bisect-cause IsRelease: ❌ ❓ KASAN: slab-use-after-free Read in ext4_discard_work 2026/11/19 22:46 2026/11/19 22:46 2026/11/19 23:21 229865fb
d4b7c226 assessment-security DenialOfService: βœ… Exploitable: βœ… FilesystemTrigger: βœ… FuzzingArtifact: ❌ MemoryCorruption: βœ… NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: slab-use-after-free Read in ext4_discard_work 2026/11/19 22:45 2026/11/19 22:45 2026/11/19 23:49 229865fb
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [ext4?] KASAN: slab-use-after-free Read in ext4_discard_work 0 (1) 2026/11/25 00:32
▶ ▼ Last patch testing requests (1)
Created Duration User Patch Repo Result
2026/11/22 09:56 25m retest repro git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 909ef7a9a30fa139e69e555e3606680f5cca7726 no crash job log log

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in ext4_discard_work+0xa1/0x7f0 fs/ext4/mballoc.c:3645
Read of size 8 at addr ffff88807bfec3f0 by task kworker/u8:12/1466

CPU: 1 UID: 0 PID: 1466 Comm: kworker/u8:12 Tainted: G             L      syzkaller #0 PREEMPT(full) 
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Workqueue: events_unbound ext4_discard_work
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 print_address_description+0x55/0x1e0 mm/kasan/report.c:378
 print_report+0x58/0x70 mm/kasan/report.c:482
 kasan_report+0x117/0x150 mm/kasan/report.c:595
 ext4_discard_work+0xa1/0x7f0 fs/ext4/mballoc.c:3645
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3578
 worker_thread+0xa47/0xfb0 kernel/workqueue.c:3659
 kthread+0x38b/0x480 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

Allocated by task 12861:
 kasan_save_stack mm/kasan/common.c:57 [inline]
 kasan_save_track+0x3f/0x90 mm/kasan/common.c:79
 poison_kmalloc_redzone mm/kasan/common.c:412 [inline]
 __kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:429
 kasan_kmalloc include/linux/kasan.h:267 [inline]
 __kmalloc_cache_noprof+0x31c/0x600 mm/slub.c:5680
 _kmalloc_noprof include/linux/slab.h:991 [inline]
 _kzalloc_noprof include/linux/slab.h:1312 [inline]
 ext4_alloc_sbi fs/ext4/super.c:4424 [inline]
 ext4_fill_super+0x118/0x6630 fs/ext4/super.c:5886
 get_tree_bdev_flags+0x436/0x500 fs/super.c:1821
 vfs_get_tree+0x92/0x2a0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x325/0xb00 fs/namespace.c:3986
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x31d/0x420 fs/namespace.c:4540
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 12861:
 kasan_save_stack mm/kasan/common.c:57 [inline]
 kasan_save_track+0x3f/0x90 mm/kasan/common.c:79
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:599
 poison_slab_object mm/kasan/common.c:267 [inline]
 __kasan_slab_free+0x70/0x90 mm/kasan/common.c:299
 kasan_slab_free include/linux/kasan.h:239 [inline]
 slab_free_hook mm/slub.c:2780 [inline]
 slab_free mm/slub.c:6637 [inline]
 kfree+0x1c7/0x650 mm/slub.c:6930
 ext4_free_sbi fs/ext4/super.c:4417 [inline]
 ext4_fill_super+0x2962/0x6630 fs/ext4/super.c:5924
 get_tree_bdev_flags+0x436/0x500 fs/super.c:1821
 vfs_get_tree+0x92/0x2a0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x325/0xb00 fs/namespace.c:3986
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x31d/0x420 fs/namespace.c:4540
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Last potentially related work creation:
 kasan_save_stack+0x3e/0x60 mm/kasan/common.c:57
 __kasan_record_aux_stack+0xc5/0xe0 mm/kasan/generic.c:561
 insert_work+0x3d/0x330 kernel/workqueue.c:2356
 __queue_work+0xd3c/0x1360 kernel/workqueue.c:2546
 queue_work_on+0x106/0x1d0 kernel/workqueue.c:2599
 queue_work include/linux/workqueue.h:700 [inline]
 ext4_process_freed_data+0xa15/0xab0 fs/ext4/mballoc.c:4037
 ext4_journal_commit_callback+0x99/0x620 fs/ext4/super.c:526
 jbd2_journal_commit_transaction+0x4902/0x5c60 fs/jbd2/commit.c:1147
 jbd2_journal_destroy+0x25f/0x7e0 fs/jbd2/journal.c:2120
 ext4_journal_destroy+0xfb/0x130 fs/ext4/ext4_jbd2.h:456
 __ext4_fill_super fs/ext4/super.c:5845 [inline]
 ext4_fill_super+0x546f/0x6630 fs/ext4/super.c:5899
 get_tree_bdev_flags+0x436/0x500 fs/super.c:1821
 vfs_get_tree+0x92/0x2a0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x325/0xb00 fs/namespace.c:3986
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x31d/0x420 fs/namespace.c:4540
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Second to last potentially related work creation:
 kasan_save_stack+0x3e/0x60 mm/kasan/common.c:57
 __kasan_record_aux_stack+0xc5/0xe0 mm/kasan/generic.c:561
 insert_work+0x3d/0x330 kernel/workqueue.c:2356
 __queue_work+0xd3c/0x1360 kernel/workqueue.c:2546
 queue_work_on+0x106/0x1d0 kernel/workqueue.c:2599
 queue_work include/linux/workqueue.h:700 [inline]
 schedule_work include/linux/workqueue.h:761 [inline]
 ext4_handle_error+0x63b/0x940 fs/ext4/super.c:734
 __ext4_error+0x24d/0x360 fs/ext4/super.c:848
 ext4_init_orphan_info+0xb75/0xda0 fs/ext4/orphan.c:625
 __ext4_fill_super fs/ext4/super.c:5750 [inline]
 ext4_fill_super+0x5b11/0x6630 fs/ext4/super.c:5899
 get_tree_bdev_flags+0x436/0x500 fs/super.c:1821
 vfs_get_tree+0x92/0x2a0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x325/0xb00 fs/namespace.c:3986
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x31d/0x420 fs/namespace.c:4540
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff88807bfec000
 which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 1008 bytes inside of
 freed 8192-byte region [ffff88807bfec000, ffff88807bfee000)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7bfe8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88813ff2c280 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88813ff2c280 dead000000000100 dead000000000122
head: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000
head: 00fff00000000003 fffffffffffffe01 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 Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5338, tgid 5338 (dhcpcd-run-hook), ts 50822988154
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0x1f9/0x250 mm/page_alloc.c:1873
 prep_new_page+0x22/0xb0 mm/page_alloc.c:1881
 get_page_from_freelist+0x22a1/0x22e0 mm/page_alloc.c:3963
 __alloc_frozen_pages_noprof+0x211/0x450 mm/page_alloc.c:5505
 alloc_slab_page mm/slub.c:3384 [inline]
 allocate_slab+0x7d/0x5e0 mm/slub.c:3499
 new_slab mm/slub.c:3550 [inline]
 refill_objects+0x2d5/0x350 mm/slub.c:7546
 refill_sheaf mm/slub.c:2917 [inline]
 __pcs_replace_empty_main+0x2c8/0x6c0 mm/slub.c:4811
 alloc_from_pcs mm/slub.c:4887 [inline]
 slab_alloc_node mm/slub.c:5021 [inline]
 __kmalloc_cache_noprof+0x396/0x600 mm/slub.c:5676
 _kmalloc_noprof include/linux/slab.h:991 [inline]
 _kzalloc_noprof include/linux/slab.h:1312 [inline]
 tomoyo_print_bprm security/tomoyo/audit.c:26 [inline]
 tomoyo_init_log+0x10ef/0x1f60 security/tomoyo/audit.c:262
 tomoyo_supervisor+0x35f/0x1550 security/tomoyo/common.c:2232
 tomoyo_audit_env_log security/tomoyo/environ.c:37 [inline]
 tomoyo_env_perm+0x151/0x1f0 security/tomoyo/environ.c:64
 tomoyo_environ security/tomoyo/domain.c:673 [inline]
 tomoyo_find_next_domain+0x1332/0x1a90 security/tomoyo/domain.c:889
 tomoyo_bprm_check_security+0x11b/0x180 security/tomoyo/tomoyo.c:102
 security_bprm_check+0x85/0x240 security/security.c:834
 search_binary_handler fs/exec.c:1767 [inline]
 exec_binprm fs/exec.c:1809 [inline]
 bprm_execve+0x888/0x1590 fs/exec.c:1865
 do_execveat_common+0x99f/0xbd0 fs/exec.c:1963
page last free pid 30 tgid 30 ts 50814152040 stack trace:
 reset_page_owner include/linux/page_owner.h:26 [inline]
 __free_pages_prepare mm/page_alloc.c:1415 [inline]
 free_pages_prepare+0x9eb/0xaf0 mm/page_alloc.c:1460
 __free_contig_range_common+0x174/0x340 mm/page_alloc.c:7136
 __free_contig_range mm/page_alloc.c:7181 [inline]
 free_pages_bulk+0x48/0x120 mm/page_alloc.c:5389
 vm_area_free_pages mm/vmalloc.c:3498 [inline]
 vfree+0x22c/0x490 mm/vmalloc.c:3547
 delayed_vfree_work+0x55/0x80 mm/vmalloc.c:3451
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3578
 worker_thread+0xa47/0xfb0 kernel/workqueue.c:3659
 kthread+0x38b/0x480 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

Memory state around the buggy address:
 ffff88807bfec280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807bfec300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807bfec380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                             ^
 ffff88807bfec400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807bfec480: 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
2026/11/24 07:19 upstream 8d7fe9885c62 e9bfbe3a .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root KASAN: slab-use-after-free Read in ext4_discard_work
2026/11/20 18:00 upstream 65e4fd942f72 625aa117 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-badwrites-root KASAN: slab-use-after-free Read in ext4_discard_work
2026/11/19 22:48 linux-next e8017d29067f f836d119 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: slab-use-after-free Read in ext4_discard_work
2026/11/19 22:43 linux-next e8017d29067f f836d119 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: slab-use-after-free Read in ext4_discard_work
* Struck through repros no longer work on HEAD.