syzbot
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: 1h25m, last: 1h25m
✨ AI cause bisection: inconclusive
(AI job)
✨ 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
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
-
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.
-
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.
-
Missing tlckBTROOT Check in txAbort() (fs/jfs/jfs_txnmgr.c:2605-2629):
How the Crash Occurs
-
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).
-
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)).
-
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.)
Sample crash report:
* Struck through repros no longer work on HEAD.