From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 26F1B429811 for ; Tue, 5 May 2026 12:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777984416; cv=none; b=f2IFMe7iDcaU6Qyhza/Gbq9RRhyz7296jy2j49H94jUJfyuKJEmCcV0bB0Yak1Sm/6959Y8zIspCCX4vkPgNVUbpUjSbRF5t56yPF7jttpQ88RbIElnek+gfs4fFil+bDZ/YlYH2JJJsIN+8I7wVaaJf4IMFMZH0+YwjTLKSWC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777984416; c=relaxed/simple; bh=TLIH/Tgx3dg9i1TNN4EsgmGal4HuOLfx7/7fIa8ct+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=crgjMHQhO7cGE+TIQ6pQeZKtkH9u6sP0B6gjN4X8alJLiPhpil46kq8uB7DwIs68mdx3SjT3OVUd9zjvAm7BTilmPhFTKBgocKlNmGtnp3flwuqd8wPd2DwjVk54/PDmXA/l/IzRoeFxTMNFgZRlNPKNKeMj41B4ec1gpmu2yns= 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=U8WQEN6y; arc=none smtp.client-ip=209.85.128.44 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="U8WQEN6y" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4891e5b9c1fso50042155e9.2 for ; Tue, 05 May 2026 05:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777984413; x=1778589213; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K2WNU8nICgt72CKBqTTHtMF4K06yXBKs3UcZ/HI1eik=; b=U8WQEN6ytTntXP/0KyTyQf+3O17R5hg8UnF3SS1MqIM9k05SBLctBUA92sy9gLOgDX xDUFvr1sLsXWjWkOhRCsEXYn00KA0XdF4P/iqfFVCLv4i9KgyZi8lIS6zNRJgJMbjXcS zsPmACh+8CGgcfPGVm8oMzMuA28AWI44s437b/rFX/0OJhkytrmUBaEXbNGvWyzqaSWk CuWHcctI6DF4rdZpcwRpSzzHexL0Hq5RQbTjWHwKpxBlOvkzycGXXjcSJ8oU1Fb2I2h+ UtyJNpwoj7tr9xCZPCA7WzLJ+IaNLCMOC+ms1H1OcJIhVXFv17eN3/vnoir5962zlbUE RsHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777984413; x=1778589213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=K2WNU8nICgt72CKBqTTHtMF4K06yXBKs3UcZ/HI1eik=; b=B/Msxmied/qcWfrSepdXYccufZFFT+DAAw35M2gTbo6Oe1AL933VOe99cGJFLAKlug dI/kYyOgYYWV+jj0feZ5lUU2zqZMB9dfCu+1L5n757Qi2G+j1Ln5y7NPyZZl/VV3JpEM y0u/jFhi6IOA/ksZfU7oj1jmlSfsQyG9m9JpcIN7QEl/9zy+nVQVwUy8hcNvqajNwA0R mMz+RTu/cAtWbrIN7g5KIxbU3M8dA7imZ3vkdXsJWcewQxtZqIIan1n29VpFs6tZqFBG n11HgpBELlDs6FR3jg12g4SqA2I9bwPW1xkFbNDT/vmDIf2LKwvZXsBrg+pkZGac+gyS VZaQ== X-Forwarded-Encrypted: i=1; AFNElJ/6uYATakQZXuzNCAnvvbY6b3aCTSGAiUKboYdCEYqxaktxUj8NaonKTz6/rykbTh8PtXpc9BQy415P6wg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxyuc+ReROr4RcMFhaVtQ8r/y4PY72NfCmdDXX9D1L1NcwTwZzk KtqwKjcIfu3VuduOehHXgm3rxQv1wjFnnxb+h6pP9eG/GP/lGUUT8fM= X-Gm-Gg: AeBDiesr3KCgk13PI9+piTonlsLx+rp1zgcyw1kPH1zvlDyzpqUQw5cc99w/IPdEZ2P 85Mp6DT+Ibp/bKY+AGrxshmgGXxmqY3imaHvAIFS0D4f5o3Gz4Otv8k0EtzXNQeMfw7g2pytq+S h24AwXQj12zpiYwRqhOQJJWG7E+X/7BO0RvKF0KC6SLn1dT34HcmRUBIWuPpRnSRA1Osqznw4Go A3mQeBdML4pzlf/JNHUeECjxCmtADvmBZkZgRxMiY7EoYk7HiOsr9ncAqdhqXjdiDC7rHDCvHsK Tavuk9iy4cGnzI0ASGCNKMNiGl4S7J+VHXR9fhwJgvqgWIZSwcfA0wvZuzRQ4YUV3uU6A1OccTO DE9i942BB9YPu6l81dbv6cI23qy629hWlclqZXzSkmfnpI9CXd9t5J+0x01rW+wSq4dJW3KQtpp /3Z74d21NlWmgVkw== X-Received: by 2002:a05:600c:a11:b0:487:12c:e7e1 with SMTP id 5b1f17b1804b1-48d187d95d2mr49896755e9.11.1777984412421; Tue, 05 May 2026 05:33:32 -0700 (PDT) Received: from debian.. ([2001:41d0:303:db6b::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a822bf3ffsm431044285e9.7.2026.05.05.05.33.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 05:33:31 -0700 (PDT) From: Tristan Madani To: Dave Kleikamp Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+c244f4a09ca85dd2ebc1@syzkaller.appspotmail.com, syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com, stable@vger.kernel.org, Tristan Madani Subject: [PATCH v2 1/2] jfs: drain lazy commit queue during unmount to prevent use-after-free Date: Tue, 5 May 2026 12:33:29 +0000 Message-ID: <20260505123330.2822833-2-tristmd@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260505123330.2822833-1-tristmd@gmail.com> References: <20260501110236.43226-1-tristmd@gmail.com> <20260505123330.2822833-1-tristmd@gmail.com> 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..80ce468eadde0 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