From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f79.google.com (mail-ot1-f79.google.com [209.85.210.79]) (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 1E5711F4611 for ; Tue, 5 May 2026 12:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.79 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777984451; cv=none; b=jc4eNpcF48toWPAp0DrOByfIn1vzbAoH5Fwz8XGbiyn7sg4tHpe1hHqTOSFa+lN25vk8oA2nbRxB97xkOU10U5Pq7Vu94C4IkcUfG7ou+S+St52mmOjoxG/n/GliFG0ANrD7TDyrF18WwPOa+y23DcJ1farpe8XrEMOdMc5zbk8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777984451; c=relaxed/simple; bh=kCHj/mRd8E0cqifL470FPymXLUFq9agG7J4KeX1dwY0=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=Uibei2c380C+SXKocdz0Mh2v0xq5PlvMnA8H4/XxqO2Bl+YBp3PUKwxIasGhNTGeN8VYLy/KYZr1rAwh/LFlCGAqSkAwukE4DsghQ/89wWVqcZ1aIuaiJmfVNNnhw8j0brm9sALLyzPyCGAK7KVjbFvD1iKP3fjJ1dAXUjTLMXE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.210.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-ot1-f79.google.com with SMTP id 46e09a7af769-7dbe76e3abcso13440660a34.0 for ; Tue, 05 May 2026 05:34:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777984449; x=1778589249; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A+wzd+QmDRNGuuqiR3Gos2HvkW02o67jl0fBo5RWdH0=; b=Jg58uL9hY936ygavSLUL82aVZL+5SUA1tl7v83rWqzhse8g97Fj/SMOFhkmLn7a5D9 vVKZR2cQBZnPasegW3Ds8RvpYShcTkbR7AGj6jaB1Tu+ttJiw9H5hWhJlCDRYOfaI7Zt f7kYY7FVvRZ2Cuzr90Z4ofrMNJqvFnGE97P2E0rmpfNClpsZCsQHEAo47lMq8kIu7UE8 YDokMXSFS8I5Ttfd5z32AK/ET0W3DTnfhzv2ZnAUne2buR/GkUzrf2EC/x9uqhIo4cN8 UPDNl6E4DfRIiKTZ5kG2Lus+y1AcH6BJLW2FlZW7+TPXfegmOU7tTbsz0TI1ch7TXnS9 jcCg== X-Gm-Message-State: AOJu0Yw3VwSnU84vVEoVn0yNSlG08K3lafjxyHDwosgch5f1rfabafGe 9s82/AAZxR6S5Or6Pm9GDp8iahDsJ7GmtpdtYiEn/iDMza4q3RZPj572RtZs5506vCfk5hcXm54 jn/Val2GHSsybLacw5MxwsLTypKJG3l3X5SWxl1NjFmEySWlZIeWMGkRuaBiFFw== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a4a:e90b:0:b0:696:924d:2fec with SMTP id 006d021491bc7-69697e0e633mr6590697eaf.56.1777984449080; Tue, 05 May 2026 05:34:09 -0700 (PDT) Date: Tue, 05 May 2026 05:34:09 -0700 In-Reply-To: <00000000000034ae0f05e9f94c79@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69f9e3c1.050a0220.e8b39.0003.GAE@google.com> Subject: Forwarded: Re: [syz] KASAN: use-after-free Read in jfs_lazycommit From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: Re: [syz] KASAN: use-after-free Read in jfs_lazycommit Author: tristmd@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master >>From 64dbdc17da30507784d68f1803ae5c7cfc0cf5bf Mon Sep 17 00:00:00 2001 From: Tristan Madani Date: Thu, 30 Apr 2026 23:12:58 +0000 Subject: [PATCH v2 1/2] jfs: drain lazy commit queue during unmount to prevent use-after-free 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 >>From 69cbc1419b1a8ed32475f8d04df420ff575c3f80 Mon Sep 17 00:00:00 2001 From: Tristan Madani Date: Tue, 5 May 2026 12:14:28 +0000 Subject: [PATCH v2 2/2] jfs: wait for in-flight log I/O before freeing lbufs in lbmLogShutdown lbmLogShutdown() frees log buffer (lbuf) pages and structures from log->lbuf_free. However, BIO completions (lbmIODone) may still be executing in softirq context when lbmLogShutdown() runs, because lbmIODone accesses lbuf fields (l_flag, l_log, l_freelist) before returning the buffer to the freelist. If lbmLogShutdown() runs concurrently with lbmIODone in-flight, it can free an lbuf that lbmIODone is still accessing -- resulting in a use-after-free. Fix this by adding an atomic io_count to struct jfs_log that tracks in-flight BIO operations. lbmStartIO increments it before submit_bio (or before calling lbmIODone directly for no_integrity mode), and lbmIODone decrements it after all lbuf accesses are complete. lbmLogShutdown waits for io_count to reach zero before freeing any lbufs. Reported-by: syzbot+c244f4a09ca85dd2ebc1@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c244f4a09ca85dd2ebc1 Reported-by: syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=885a4f3281b8d99c48d8 Fixes: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- fs/jfs/jfs_logmgr.c | 12 ++++++++++++ fs/jfs/jfs_logmgr.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index 306165e61438c..95e95f71ec0fa 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1804,6 +1804,8 @@ static int lbmLogInit(struct jfs_log * log) * avoid deadlock here. */ init_waitqueue_head(&log->free_wait); + atomic_set(&log->io_count, 0); + init_waitqueue_head(&log->io_done_wait); log->lbuf_free = NULL; @@ -1855,6 +1857,9 @@ static void lbmLogShutdown(struct jfs_log * log) jfs_info("lbmLogShutdown: log:0x%p", log); + /* Wait for all in-flight log I/O to complete */ + wait_event(log->io_done_wait, !atomic_read(&log->io_count)); + lbuf = log->lbuf_free; while (lbuf) { struct lbuf *next = lbuf->l_freelist; @@ -1976,6 +1981,8 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp) bio->bi_end_io = lbmIODone; bio->bi_private = bp; + + atomic_inc(&log->io_count); /*check if journaling to disk has been disabled*/ if (log->no_integrity) { bio->bi_iter.bi_size = 0; @@ -2123,6 +2130,8 @@ static void lbmStartIO(struct lbuf * bp) bio->bi_end_io = lbmIODone; bio->bi_private = bp; + atomic_inc(&log->io_count); + /* check if journaling to disk has been disabled */ if (log->no_integrity) { bio->bi_iter.bi_size = 0; @@ -2299,6 +2308,9 @@ static void lbmIODone(struct bio *bio) out: bp->l_flag |= lbmDONE; LCACHE_UNLOCK(flags); + + if (atomic_dec_and_test(&bp->l_log->io_count)) + wake_up(&bp->l_log->io_done_wait); } int jfsIOWait(void *arg) diff --git a/fs/jfs/jfs_logmgr.h b/fs/jfs/jfs_logmgr.h index 09e0ef6aeccef..cbf38ed27c950 100644 --- a/fs/jfs/jfs_logmgr.h +++ b/fs/jfs/jfs_logmgr.h @@ -367,6 +367,8 @@ struct jfs_log { struct lbuf *lbuf_free; /* 4: free lbufs */ wait_queue_head_t free_wait; /* 4: */ + atomic_t io_count; /* in-flight log I/O count */ + wait_queue_head_t io_done_wait; /* wait for io_count == 0 */ /* log write */ int logtid; /* 4: log tid */ -- 2.47.3