public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: syzbot <syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: Re: [PATCH v2 2/2] jfs: wait for in-flight log I/O before freeing lbufs in lbmLogShutdown
Date: Wed, 06 May 2026 04:50:18 -0700	[thread overview]
Message-ID: <69fb2afa.050a0220.e8b39.000f.GAE@google.com> (raw)
In-Reply-To: <00000000000034ae0f05e9f94c79@google.com>

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: Re: [PATCH v2 2/2] jfs: wait for in-flight log I/O before freeing lbufs in lbmLogShutdown
Author: tristmd@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

>From f8c2cc086d8f3f38d3a30402d093d7be05fb7397 Mon Sep 17 00:00:00 2001
From: Tristan Madani <tristan@talencesecurity.com>
Date: Wed, 6 May 2026 08:27:02 +0000
Subject: [PATCH] jfs: fix lbmLogShutdown race with redriven log buffers

lbmRedrive() adds a log buffer to the global log_redrive_list and wakes
jfsIOthread, but does not increment the log io_count.  This creates a
window where io_count reaches zero while redriven buffers are still
pending on the list.  If lbmLogShutdown() observes io_count == 0 in
this window, it proceeds to free all lbufs while jfsIOWait() later
dequeues and dereferences them, causing a use-after-free:

    lbmIODone(bp)
      lbmRedrive(nextbp)      <-- nextbp added to list, io_count not bumped
      atomic_dec(io_count)     <-- io_count drops to 0
    lbmLogShutdown()
      wait_event(io_count==0)  <-- satisfied, frees all lbufs
    jfsIOWait()
      bp = log_redrive_list    <-- UAF: bp already freed

Fix this by incrementing io_count in lbmRedrive() before adding the
buffer to the redrive list, and cancelling the reference in jfsIOWait()
after lbmStartIO() has taken its own.  This keeps io_count elevated for
the entire time a buffer sits on the redrive list.

Fixes: 69cbc1419b1a ("jfs: wait for in-flight log I/O before freeing lbufs in lbmLogShutdown")
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
 fs/jfs/jfs_logmgr.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 95e95f71ec0fa..fa3de31d9c682 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1949,6 +1949,9 @@ static inline void lbmRedrive(struct lbuf *bp)
 {
 	unsigned long flags;
 
+	/* keep io_count elevated while bp is on the redrive list */
+	atomic_inc(&bp->l_log->io_count);
+
 	spin_lock_irqsave(&log_redrive_lock, flags);
 	bp->l_redrive_next = log_redrive_list;
 	log_redrive_list = bp;
@@ -2324,7 +2327,14 @@ int jfsIOWait(void *arg)
 			log_redrive_list = bp->l_redrive_next;
 			bp->l_redrive_next = NULL;
 			spin_unlock_irq(&log_redrive_lock);
-			lbmStartIO(bp);
+			{
+				struct jfs_log *log = bp->l_log;
+
+				lbmStartIO(bp);
+				/* cancel redrive ref; lbmStartIO took its own */
+				if (atomic_dec_and_test(&log->io_count))
+					wake_up(&log->io_done_wait);
+			}
 			spin_lock_irq(&log_redrive_lock);
 		}
 
-- 
2.47.3


      parent reply	other threads:[~2026-05-06 11:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-01 13:43 [syzbot] KASAN: use-after-free Read in jfs_lazycommit syzbot
2022-10-12  5:33 ` syzbot
2024-10-13  3:29 ` Qianqiang Liu
2024-10-13  4:49   ` [syzbot] [jfs?] " syzbot
2024-10-13  6:05     ` [PATCH] jfs: Fix use-after-free read issue " Qianqiang Liu
2024-10-30 14:30       ` Dave Kleikamp
2026-04-30 23:13 ` Forwarded: Re: [syz] KASAN: use-after-free Read " syzbot
2026-05-04 22:42 ` Forwarded: Re: [syzbot] [jfs?] " syzbot
2026-05-05 12:34 ` Forwarded: Re: [syz] " syzbot
2026-05-05 15:17 ` Forwarded: Private message regarding: [syzbot] [jfs?] " syzbot
2026-05-05 15:21 ` Forwarded: Private message regarding: " syzbot
2026-05-06 11:50 ` syzbot [this message]

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=69fb2afa.050a0220.e8b39.000f.GAE@google.com \
    --to=syzbot+885a4f3281b8d99c48d8@syzkaller.appspotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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