mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jie Wang <jie.wang@intel.com>
To: shaggy@kernel.org
Cc: jfs-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	syzbot+ea7ed3bb2f444cb4dfeb@syzkaller.appspotmail.com,
	Jie Wang <jie.wang@intel.com>
Subject: [PATCH] jfs: fix use-after-free in lmLogSync during unmount
Date: Wed,  3 Jun 2026 17:16:20 +0000	[thread overview]
Message-ID: <20260603171620.2532527-1-jie.wang@intel.com> (raw)
In-Reply-To: <6a1eb319.c1435f33.112120.0156.GAE@google.com>

jfs_flush_journal(log, 2) waits for log->cqueue and log->synclist to
drain, but lazy commit transactions already moved to the global
TxAnchor.unlock_queue are not accounted for. The jfsCommit thread may
still be processing these through txEnd -> jfs_syncpt -> lmLogSync
after lmLogClose frees the log structure.

Fix by adding wait_event() in lmLogClose before kfree(log) to ensure
log->active has dropped to zero and log_SYNCBARRIER is clear. Add a
corresponding wakeup in txEnd when log->active reaches zero.

Reported-by: syzbot+ea7ed3bb2f444cb4dfeb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ea7ed3bb2f444cb4dfeb
Signed-off-by: Jie Wang <jie.wang@intel.com>
---
 fs/jfs/jfs_logmgr.c | 6 ++++++
 fs/jfs/jfs_txnmgr.c | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 306165e61438..9977c1359dbc 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1454,6 +1454,9 @@ int lmLogClose(struct super_block *sb)
 		/*
 		 *	in-line log in host file system
 		 */
+		/* wait for lazy commit thread to finish txEnd() */
+		wait_event(log->syncwait, !log->active &&
+			   !test_bit(log_SYNCBARRIER, &log->flag));
 		rc = lmLogShutdown(log);
 		kfree(log);
 		goto out;
@@ -1478,6 +1481,9 @@ int lmLogClose(struct super_block *sb)
 	/*
 	 *	external log as separate logical volume
 	 */
+	/* wait for lazy commit thread to finish txEnd() */
+	wait_event(log->syncwait, !log->active &&
+		   !test_bit(log_SYNCBARRIER, &log->flag));
 	list_del(&log->journal_list);
 	bdev_file = log->bdev_file;
 	rc = lmLogShutdown(log);
diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
index 083dbbb0c326..75d5c2a10600 100644
--- a/fs/jfs/jfs_txnmgr.c
+++ b/fs/jfs/jfs_txnmgr.c
@@ -560,6 +560,9 @@ void txEnd(tid_t tid)
 
 			goto wakeup;
 		}
+
+		/* wakeup lmLogClose waiting for all txn completion */
+		TXN_WAKEUP(&log->syncwait);
 	}
 
 	TXN_UNLOCK();
-- 
2.34.1


  reply	other threads:[~2026-06-03  9:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 10:40 [syzbot] [jfs?] KASAN: slab-use-after-free Write in lmLogSync syzbot
2026-06-03 17:16 ` Jie Wang [this message]
2026-06-25 19:01 ` syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260603171620.2532527-1-jie.wang@intel.com \
    --to=jie.wang@intel.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shaggy@kernel.org \
    --cc=syzbot+ea7ed3bb2f444cb4dfeb@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®