From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1658139D6C5 for ; Fri, 1 May 2026 11:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777633361; cv=none; b=GjNtq2Ywqh7XTIcqZhVCgoXBo4wAoVw5lWZHgLbS5vBVa2zfSOEAypWf4vmsbkcCkMOD/Low0w0uVilKC4lyyhBVlpiYPWhoV5YzbJ2gKDrf+6/a3sQcN5bJmnIoma4qDgYQjfh9nINdrwFjiM7kCEaxGZNdvM9x6QryJQaIo5E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777633361; c=relaxed/simple; bh=F8u6jKI7D27MbEeW5xGCVvTgUbqVVT1yLqWITRrJmYg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KRoRtiOen0+AxvS9iZ9zAHeQx1Tqmq2g0acnhs/7Y7LuevGZ4Rechx0ONdKO5oGWGjk/Ziidg6DWzNnfvA091m3Xkzj4vZ5EIzuzRywPXFdOsmeLyVbaMfXF5G/YSGC/dIYb9H1SGoSneLHUTRTKwWJSiiyWjTsEpH+GBzbsLtw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iFmFksQA; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iFmFksQA" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-488ff90d6c7so18065515e9.2 for ; Fri, 01 May 2026 04:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777633358; x=1778238158; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=t6/GzFE2IPmBpClk7dJcDRUbOhvrcqXJNzoTjRHtmKk=; b=iFmFksQAA32GWUi/6O2vlYiSIxzB9ORFvSCaTeB242v23WdnNpS54Xc6lKHnqtOxG/ 7I6gev/qCo33lZowOx9wgR3SfOt+CTJOgg/XDKiwx/2mR26aMfHg4zHZos05Csen4aHj qy87hrIUMDPd8bvJtWSVY9Rnv9tyISE6isq3oG8jyq7Z7zyiisF+ccAWPUIDjQK2gVt5 g0tFrvTTDsh2wFy3YxzIAvjk4BX9i3zwesiv1G7K4gqdsZSXav8uJhpL2hJ5yWoywx4K aEPRFZ+0SphH/IRSrLnLztp0kZoQ9rYIQx3Zw9gyNvkJRHzJUbvC2tpaSesPM305PlJR sPXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777633358; x=1778238158; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=t6/GzFE2IPmBpClk7dJcDRUbOhvrcqXJNzoTjRHtmKk=; b=GYWwqlQqwBKEX1r6CXzlmN6sIGxWR56ZKsWviDxvVzI9WlqhuM+ueGwzsVWUvMOZGm 3Y9n2sP9jSQfxz34BF29ZqYZF3Oq1/KPgRYociwD8wBL/fyfnuvvBj2udQhM4gGSoK6l l+MrWKZ8hNT8Lwe1gBC40Vssr8h7MZ4Y0nBDu5S038L1bS3KikjrqeNAU4zo2GUIQlkM fJRLX0lS+IOA4D0vi0lUFPb/E2iCiN0i+QUJkh7h/FsDExwu0GnZxmHdE/4FEaUMhpZX E4b0zWe9OJALbdSBC7bm+84J30TXJmwwyKcaSN0z3ftgRqpkgUv6QPn/6X4ipr3JAuzD 3u8A== X-Forwarded-Encrypted: i=1; AFNElJ97NftjcDotZ9Q0ew+I9W0B2/D3iik9QZIzfBTopMLUhUfwJs9itqE01wMSVPKgZpm5JIeNDonykjHoUgs=@vger.kernel.org X-Gm-Message-State: AOJu0YzUC2h4IAOxSgBByP/vz/x/PjhPBk8ReMEzQ8ZUCHxHhCOgXS+1 KjLMh3PJO0swD5S37c67qvTSh0Zp+U7Hl0MUlTEJXjcu2PmoiMSKnjHjUo2s X-Gm-Gg: AeBDieuQCNjQTU+5N/ccQBw6s9uM9OZaReT842Lm3uVKT/0MOVHHrTW0hIKXJD+geWo 1lyQ4xlhfHXoIdV1lAvHUgNbIA913x+K0bpWILo/pEFg2NTP3qiYhsoNV7z1NGrSNsaAAE1dj53 IjRGDu0bhwlK3kLRzt9NJrUq41UMulG3esdxDGCGmb4gRTWh9giQq/5L5Rl+1LiaisoZozqvCQZ jaTrmOQHmiU2h2Bj22c4gqUh/azW5M2IJuBPGk1+kn/M0ral4euafvCeSa3JvumOgXfUGs0MHLx wndR3m+PiVkCB0Xhn8b0Ht5McT2gKFhuImUdeyy8FtdqvpMQohxqmOBbrZC895JJax6DpxwF8vX 7xXV3s6n/S23TlnMo6Ihq2s6t4YbRk/G81tKyVSLnRzbntqbSlmDCGnK/bSEwEA6E0wnC+DeJIM 48gCA= X-Received: by 2002:a05:600c:c0c2:b0:489:1b10:d896 with SMTP id 5b1f17b1804b1-48a83d09d5dmr77193445e9.0.1777633358043; Fri, 01 May 2026 04:02:38 -0700 (PDT) Received: from debian.. ([2001:41d0:303:db6b::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8fef1db8sm10780005e9.29.2026.05.01.04.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 04:02:37 -0700 (PDT) From: Tristan Madani To: Dave Kleikamp Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Tristan Madani , syzbot+c244f4a09ca85dd2ebc1@syzkaller.appspotmail.com, syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com Subject: [PATCH] jfs: drain lazy commit queue during unmount to prevent use-after-free Date: Fri, 1 May 2026 11:02:36 +0000 Message-ID: <20260501110236.43226-1-tristmd@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tristan Madani The jfsCommit kernel thread processes committed transactions from TxAnchor.unlock_queue via jfs_lazycommit(). During filesystem unmount, jfs_umount() calls jfs_flush_journal(log, 2) which waits for the log commit queue (log->cqueue) to drain. However, after log I/O completes, lazy transactions are moved to TxAnchor.unlock_queue for asynchronous processing by jfsCommit. If jfs_umount() proceeds to free the jfs_log (via lmLogClose) or jfs_sb_info (via kfree in jfs_put_super) while entries referencing this superblock remain on unlock_queue, the jfsCommit thread will access freed memory when it later processes these entries: - jfs_lazycommit reads sbi->commit_state (UAF of jfs_sb_info) - txLazyCommit accesses JFS_SBI(tblk->sb)->log and takes log->gclock (UAF of jfs_log) Add txLazyDrain() which waits for all entries in TxAnchor.unlock_queue belonging to the unmounting superblock to be processed, and also waits for any in-flight txLazyCommit (IN_LAZYCOMMIT) for this superblock to complete. Call it from both jfs_umount() and jfs_umount_rw() after jfs_flush_journal(). Reported-by: syzbot+c244f4a09ca85dd2ebc1@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c244f4a09ca85dd2ebc1 Tested-by: syzbot+c244f4a09ca85dd2ebc1@syzkaller.appspotmail.com Reported-by: syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=885a4f3281b8d99c48d8 Tested-by: syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com Fixes: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- fs/jfs/jfs_txnmgr.c | 35 +++++++++++++++++++++++++++++++++++ fs/jfs/jfs_txnmgr.h | 1 + fs/jfs/jfs_umount.c | 8 ++++++++ 3 files changed, 44 insertions(+) diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index 083dbbb0c3268..67a9908b5a4d9 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c @@ -2791,6 +2791,41 @@ void txLazyUnlock(struct tblock * tblk) LAZY_UNLOCK(flags); } + +/* + * txLazyDrain + * + * Wait for all pending lazy commit entries for this superblock + * to be processed by the jfsCommit thread. Must be called + * before freeing per-filesystem structures during unmount. + */ +void txLazyDrain(struct super_block *sb) +{ + struct jfs_sb_info *sbi = JFS_SBI(sb); + struct tblock *tblk; + unsigned long flags; + bool found; + + do { + found = false; + LAZY_LOCK(flags); + list_for_each_entry(tblk, &TxAnchor.unlock_queue, cqueue) { + if (tblk->sb == sb) { + found = true; + break; + } + } + if (!found && (sbi->commit_state & IN_LAZYCOMMIT)) + found = true; + LAZY_UNLOCK(flags); + + if (found) { + wake_up(&jfs_commit_thread_wait); + schedule_timeout_uninterruptible(1); + } + } while (found); +} + static void LogSyncRelease(struct metapage * mp) { struct jfs_log *log = mp->log; diff --git a/fs/jfs/jfs_txnmgr.h b/fs/jfs/jfs_txnmgr.h index ba71eb5ced567..fbbaed26c52bd 100644 --- a/fs/jfs/jfs_txnmgr.h +++ b/fs/jfs/jfs_txnmgr.h @@ -291,6 +291,7 @@ extern void txFreelock(struct inode *); extern int lmLog(struct jfs_log *, struct tblock *, struct lrd *, struct tlock *); extern void txQuiesce(struct super_block *); +extern void txLazyDrain(struct super_block *sb); extern void txResume(struct super_block *); extern void txLazyUnlock(struct tblock *); extern int jfs_lazycommit(void *); diff --git a/fs/jfs/jfs_umount.c b/fs/jfs/jfs_umount.c index 18569f1eaabdb..657707361be2a 100644 --- a/fs/jfs/jfs_umount.c +++ b/fs/jfs/jfs_umount.c @@ -58,6 +58,13 @@ int jfs_umount(struct super_block *sb) */ jfs_flush_journal(log, 2); + /* + * Drain any pending lazy commit entries for this filesystem so + * the jfsCommit thread does not access freed structures. + */ + if (log) + txLazyDrain(sb); + /* * Hold log lock so write_special_inodes (lmLogSync) cannot see * this sbi with a NULL inode pointer while iterating log->sb_list. @@ -142,6 +149,7 @@ int jfs_umount_rw(struct super_block *sb) * remove file system from log active file system list. */ jfs_flush_journal(log, 2); + txLazyDrain(sb); /* * Make sure all metadata makes it to disk -- 2.47.3