KASAN: slab-use-after-free Read in txUnlock (4)

Status: moderation: reported on 2026/11/27 03:23
Subsystems: jfs
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+dfdc97917ac4fcfe8623@syzkaller.appspotmail.com
First crash: 1h11m, last: 1h11m
✨ AI-generated root cause summary:

In fs/jfs/jfs_txnmgr.c, txAbort() iterates over all tlocks of an aborted transaction and calls LogSyncRelease(mp) (which decrements mp->nohomeok) whenever tlck->mp is a COMMIT_PAGE metapage with mp->lsn != 0, without filtering out tlckBTROOT locks. During txCommit(), diWrite() in fs/jfs/jfs_imap.c rebinds inline B+-tree root locks (jfs_ip->xtlid and jfs_ip->blid, marked tlckBTROOT) to the on-disk inode-extent metapage mp without incrementing mp->nohomeok. When a transaction aborts after diWrite() succeeds on one inode in cd.iplist and fails on a subsequent inode (e.g., due to an I/O read error) while mp also has mp->lsn != 0 from an earlier pending lazy transaction, txAbort() over-decrements mp->nohomeok to 0. This allows writeback and memory reclaim (metapage_release_folio()) to free mp before the earlier lazy transaction runs txUnlock(), resulting in a slab-use-after-free in jfsCommit.

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

Root Cause Analysis

The crash is a slab-use-after-free on a struct metapage object (from the jfs_mp slab cache) in txUnlock() (fs/jfs/jfs_txnmgr.c:927) executed by the jfsCommit kthread (jfs_lazycommit() -> txLazyCommit()). It is caused by a nohomeok reference count underflow in txAbort() when a transaction aborts mid-txCommit() after diWrite() has rebound tlckBTROOT locks to a COMMIT_PAGE metapage.


Involved Functions, Structs, and Invariants

  1. Metapage Pinning & Reclaim (fs/jfs/jfs_metapage.h, fs/jfs/jfs_metapage.c):

    • struct metapage holds mp->nohomeok, mp->count, mp->flag (META_dirty), mp->xflag (COMMIT_PAGE), mp->lsn, and mp->lid.
    • When a transaction locks a real metadata buffer via txLock() (fs/jfs/jfs_txnmgr.c:699-705), (mp->xflag & COMMIT_PAGE) is true, so metapage_nohomeok(mp) increments mp->nohomeok (taking a folio_get() reference on 0 -> 1) and marks mp dirty.
    • metapage_write_folio() (fs/jfs/jfs_metapage.c:456) refuses to write out and clear META_dirty while mp->nohomeok > 0 (unless META_forcewrite is set), and metapage_release_folio() (fs/jfs/jfs_metapage.c:626-637) only frees mp (free_metapage(mp)) when mp->count == 0 && mp->nohomeok == 0 && !test_bit(META_dirty, &mp->flag).
    • Invariant: every tlock on a tblock with tlck->mp != NULL and (tlck->type & tlckBTROOT) == 0 owns one mp->nohomeok reference until txUnlock() (or txAbort()) releases it.
  2. Rebinding tlckBTROOT Locks in diWrite() (fs/jfs/jfs_imap.c:653-713):

    • Initially, inline B+-tree root locks (e.g., from dtInitRoot() in fs/jfs/jfs_dtree.c:2571) are acquired on (struct metapage *)&jfs_ip->bxflag, where xflag == 0 (COMMIT_PAGE is not set), so metapage_nohomeok() is not called.
    • During txCommit() (fs/jfs/jfs_txnmgr.c:1197-1259), diWrite(tid, ip) reads the on-disk inode-extent metapage mp and calls:
    • Thus, txRelease(), txUnlock(), txForce(), and lmLog() all explicitly skip tlocks with tlck->type & tlckBTROOT so they do not treat tlck->mp as an independent nohomeok holder.
  3. Missing tlckBTROOT Check in txAbort() (fs/jfs/jfs_txnmgr.c:2605-2629):

    • Unlike the other transaction-lock iterators in fs/jfs/jfs_txnmgr.c, txAbort() does not check (tlck->type & tlckBTROOT) == 0:
      for (lid = tblk->next; lid; lid = next) {
          tlck = lid_to_tlock(lid);
          next = tlck->next;
          mp = tlck->mp;
          JFS_IP(tlck->ip)->xtlid = 0;
      
          if (mp) {
              mp->lid = 0;
              if (mp->xflag & COMMIT_PAGE && mp->lsn)
                  LogSyncRelease(mp);
          }
          ...
      }
      
    • LogSyncRelease(mp) (fs/jfs/jfs_txnmgr.c:2794-2801) calls metapage_homeok(mp) -> _metapage_homeok(mp), decrementing mp->nohomeok.
    • When diWrite() has run on an inode with blid (and/or xtlid) and mp->lsn != 0, tblk contains both ditlck and the tlckBTROOT tlock(s) pointing to the same COMMIT_PAGE metapage mp. If txAbort() is then invoked, it calls LogSyncRelease(mp) for both ditlck and the tlckBTROOT lock(s), decrementing mp->nohomeok two (or three) times when the aborted transaction only incremented it once.

How the Crash Occurs

  1. Initial Allocation and Pending Lazy Transaction (tblkA):

    • A jfs_mkdir() (task 5355) allocates a new inode extent in diNewExt() (fs/jfs/jfs_imap.c:2275) via get_metapage() -> alloc_metapage(), creating mp.
    • jfs_mkdir() commits tblkA via txCommit(..., flag = 0) (COMMIT_LAZY). diWrite() locks mp (mp->nohomeok == 1), lmLog() assigns mp->lsn != 0, lmGroupCommit() queues tblkA with tblkGC_LAZY without necessarily flushing immediately (fs/jfs/jfs_logmgr.c:672-690), and txRelease(tblkA) clears mp->lid = 0 while leaving mp->nohomeok == 1 until jfs_lazycommit runs txUnlock(tblkA).
  2. Second Transaction Aborts Mid-txCommit() (tblkB):

    • Another transaction tblkB (e.g., creating/modifying a child inode ip allocated in the same extent mp under parent dip with ip->i_ino > dip->i_ino) enters txCommit(), which sorts cd.iplist in descending i_ino order (fs/jfs/jfs_txnmgr.c:1197-1206).
    • diWrite(tidB, ip) runs first and succeeds: txLock() increments mp->nohomeok (1 -> 2) for ditlck, and diWrite() binds the inline blid (and/or xtlid) tlckBTROOT lock(s) to mp (tlck->mp = mp).
    • diWrite(tidB, dip) runs second, attempts read_metapage() on dip's disk-inode page (e.g., at 0x4000), and fails with -EIO (Read error 10 at 0x4000 / read_mapping_page failed!).
    • txCommit() jumps to out: (fs/jfs/jfs_txnmgr.c:1354-1356) and calls txAbort(tidB, 1).
    • Because mp->lsn != 0 from tblkA and txAbort() does not skip tlckBTROOT, txAbort(tidB, 1) calls LogSyncRelease(mp) for both the tlckBTROOT lock and ditlck, dropping mp->nohomeok from 2 -> 1 -> 0 (and calling folio_put(mp->folio)).
  3. Premature Reclaim and Use-After-Free:

    • With mp->nohomeok == 0, metapage_write_folio() is no longer blocked and clears META_dirty.
    • kswapd (task 83) runs shrink_folio_list() -> metapage_release_folio() (fs/jfs/jfs_metapage.c:626-637), observes mp->count == 0, mp->nohomeok == 0, and !META_dirty, and frees mp via free_metapage().
    • Later, jfsCommit (task 117) executes jfs_lazycommit() -> txLazyCommit(tblkA) -> txUnlock(tblkA) (fs/jfs/jfs_txnmgr.c:927) and reads mp->xflag on the dangling tlck->mp, triggering the KASAN slab-use-after-free read of size 2.

(Note: A similar over-decrement can occur if txAbort() is reached on a tlckBTROOT-rebound metapage for any other reason where mp->lsn != 0, and txAbort() also clears mp->lid = 0 on tlckBTROOT entries without checking (tlck->type & tlckBTROOT) == 0.)

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
b7f82411 bisect-cause 🏃 KASAN: slab-use-after-free Read in txUnlock (4) 2026/11/27 03:14 2026/11/27 03:14 f1f6b8bf
2f927122 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ✅ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: slab-use-after-free Read in txUnlock (4) 2026/11/27 02:43 2026/11/27 02:43 2026/11/27 03:23 f1f6b8bf
▶ ▼ Similar bugs (3)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: slab-use-after-free Read in txUnlock jfs 19 1 550d 546d 0/30 auto-obsoleted due to no activity on 2025/08/24 00:02
upstream KASAN: slab-use-after-free Read in txUnlock (2) prio:high jfs 19 1 279d 275d 0/30 auto-obsoleted due to no activity on 2026/05/22 02:39
upstream KASAN: slab-use-after-free Read in txUnlock (3) prio:high actionable jfs 19 4 122d 130d 0/30 auto-obsoleted due to no activity on 2026/11/04 04:15

Sample crash report:
Read error 10 at 0x4000
read_mapping_page failed!
Read error 10 at 0x4000
read_mapping_page failed!
Read error 10 at 0x4000
read_mapping_page failed!
==================================================================
BUG: KASAN: slab-use-after-free in txUnlock+0x951/0xde0 fs/jfs/jfs_txnmgr.c:927
Read of size 2 at addr ffff888033cf69b0 by task jfsCommit/117

CPU: 0 UID: 0 PID: 117 Comm: jfsCommit Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
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
 txUnlock+0x951/0xde0 fs/jfs/jfs_txnmgr.c:927
 txLazyCommit fs/jfs/jfs_txnmgr.c:2684 [inline]
 jfs_lazycommit+0x59f/0xac0 fs/jfs/jfs_txnmgr.c:2735
 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 5355:
 kasan_save_stack mm/kasan/common.c:57 [inline]
 kasan_save_track+0x3f/0x90 mm/kasan/common.c:79
 unpoison_slab_object mm/kasan/common.c:354 [inline]
 __kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:380
 kasan_slab_alloc include/linux/kasan.h:257 [inline]
 slab_post_alloc_hook mm/slub.c:4720 [inline]
 slab_alloc_node mm/slub.c:5033 [inline]
 kmem_cache_alloc_noprof+0x2b4/0x600 mm/slub.c:5047
 mempool_alloc_noprof+0x1ba/0x2f0 mm/mempool.c:572
 alloc_metapage fs/jfs/jfs_metapage.c:264 [inline]
 __get_metapage+0x4ef/0xee0 fs/jfs/jfs_metapage.c:761
 diNewExt+0xa53/0x3020 fs/jfs/jfs_imap.c:2275
 diAllocExt fs/jfs/jfs_imap.c:1952 [inline]
 diAllocAG+0xbed/0x1de0 fs/jfs/jfs_imap.c:1669
 diAlloc+0x1e2/0x16b0 fs/jfs/jfs_imap.c:1590
 ialloc+0x8c/0x8e0 fs/jfs/jfs_inode.c:56
 jfs_mkdir+0x1dd/0xaf0 fs/jfs/namei.c:226
 vfs_mkdir+0x411/0x660 fs/namei.c:5428
 filename_mkdirat+0x284/0x550 fs/namei.c:5461
 __do_sys_mkdirat fs/namei.c:5482 [inline]
 __se_sys_mkdirat+0x35/0x150 fs/namei.c:5479
 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 83:
 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]
 kmem_cache_free+0x184/0x660 mm/slub.c:6764
 mempool_free+0xec/0x130 mm/mempool.c:717
 free_metapage fs/jfs/jfs_metapage.c:280 [inline]
 metapage_release_folio+0x544/0x6b0 fs/jfs/jfs_metapage.c:637
 shrink_folio_list+0x22e2/0x4e80 mm/vmscan.c:1570
 evict_folios+0x3326/0x4390 mm/vmscan.c:5104
 try_to_shrink_lruvec+0xf22/0x1630 mm/vmscan.c:5278
 shrink_one+0x312/0x10f0 mm/vmscan.c:5325
 shrink_many mm/vmscan.c:5388 [inline]
 lru_gen_shrink_node mm/vmscan.c:5466 [inline]
 shrink_node+0x631e/0x6c50 mm/vmscan.c:6472
 kswapd_shrink_node mm/vmscan.c:7265 [inline]
 balance_pgdat mm/vmscan.c:7436 [inline]
 kswapd+0x1ff4/0x3a20 mm/vmscan.c:7712
 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

The buggy address belongs to the object at ffff888033cf69b0
 which belongs to the cache jfs_mp of size 184
The buggy address is located 0 bytes inside of
 freed 184-byte region [ffff888033cf69b0, ffff888033cf6a68)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x33cf6
flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000000 ffff888033cf4000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000200100010 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0xd2cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 7598019346
 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]
 kmem_cache_alloc_noprof+0x394/0x600 mm/slub.c:5047
 mempool_init_node+0x1f4/0x510 mm/mempool.c:272
 mempool_create_node_noprof+0xb8/0x150 mm/mempool.c:336
 metapage_init+0xed/0x150 fs/jfs/jfs_metapage.c:293
 init_jfs_fs+0xfd/0x4e0 fs/jfs/super.c:969
 do_one_initcall+0x250/0x870 init/main.c:1432
 do_initcall_level+0x10a/0x1a0 init/main.c:1494
 do_initcalls+0x59/0xa0 init/main.c:1510
 kernel_init_freeable+0x29d/0x3e0 init/main.c:1745
page_owner free stack trace missing

Memory state around the buggy address:
 ffff888033cf6880: fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb fb
 ffff888033cf6900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc
>ffff888033cf6980: fc fc fc fc fc fc fa fb fb fb fb fb fb fb fb fb
                                     ^
 ffff888033cf6a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc
 ffff888033cf6a80: fc fc fc fc fc 00 00 00 00 00 00 00 00 00 00 00
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/27 02:43 upstream 9437ee8b6cf6 f1f6b8bf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: slab-use-after-free Read in txUnlock
* Struck through repros no longer work on HEAD.