[PATCH] jfs: fix UAF of log in remount-ro path

From: Shuai Liu

Date: Sun Dec 06 2026 - 01:21:15 EST


Remounting read-only closes the log via jfs_umount_rw(), and for
inline logs lmLogClose() frees it, while in-flight transactions may
still hold on to the log pointer. A transaction that has begun but
not yet reached lmLog() is invisible to jfs_flush_journal(), which
only drains log->cqueue and log->synclist; such a transaction later
dereferences the freed log in lmLog(), resulting in a
slab-use-after-free, as reported by syzbot.

Extend txQuiesce() to block until log->active drops to zero: txEnd()
wakes log->syncwait when the last transaction completes with
log_SYNCBARRIER set. Call it from jfs_umount_rw() before flushing
and closing the log. An inline log is private to its mount, so no
txResume() is needed; external logs are shared between mounts and are
not freed by lmLogClose(), so they are left untouched.

This also closes the same window in the freeze path, which uses
txQuiesce() followed by lmLogShutdown().

Reported-by: syzbot+5e630048345c54c4d7f4@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=5e630048345c54c4d7f4
Signed-off-by: Shuai Liu <847807867@xxxxxx>
---
fs/jfs/jfs_txnmgr.c | 11 +++++++++++
fs/jfs/jfs_umount.c | 9 +++++++++
2 files changed, 20 insertions(+)

diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
index 083dbbb0c3268..3a4e5defabb10 100644
--- a/fs/jfs/jfs_txnmgr.c
+++ b/fs/jfs/jfs_txnmgr.c
@@ -2855,6 +2855,17 @@ void txQuiesce(struct super_block *sb)
}
TXN_UNLOCK();

+ /*
+ * Block until all in-flight transactions complete. txEnd()
+ * wakes this wait queue when the last transaction completes
+ * with log_SYNCBARRIER set.
+ */
+ set_bit(log_SYNCBARRIER, &log->flag);
+ TXN_LOCK();
+ while (log->active)
+ TXN_SLEEP(&log->syncwait);
+ TXN_UNLOCK();
+
/*
* We may need to kick off the group commit
*/
diff --git a/fs/jfs/jfs_umount.c b/fs/jfs/jfs_umount.c
index 18569f1eaabdb..6683ebf67a2d9 100644
--- a/fs/jfs/jfs_umount.c
+++ b/fs/jfs/jfs_umount.c
@@ -136,6 +136,15 @@ int jfs_umount_rw(struct super_block *sb)
if (!log)
return 0;

+ /*
+ * lmLogClose() frees the log for inline logs, while in-flight
+ * transactions may still hold on to the log pointer. Quiesce
+ * them first. External logs stay alive for other mounts and
+ * must not be quiesced without a matching txResume().
+ */
+ if (test_bit(log_INLINELOG, &log->flag))
+ txQuiesce(sb);
+
/*
* close log:
*
--
2.43.0