public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: syzbot <syzbot+6cc93ec9a4035badb85f@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: Re: [syzbot] [mm?] KASAN: use-after-free Read in copy_folio_from_iter_atomic (2)
Date: Sun, 19 Apr 2026 21:08:34 -0700	[thread overview]
Message-ID: <69e5a6c2.050a0220.24bfd3.0021.GAE@google.com> (raw)
In-Reply-To: <69ca48ca.050a0220.183828.001a.GAE@google.com>

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

***

Subject: Re: [syzbot] [mm?] KASAN: use-after-free Read in copy_folio_from_iter_atomic (2)
Author: suresh.k.chandrappa@gmail.com

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

From 56a838ee6e3c6834a7e7705472144b1c84a4d8f8 Mon Sep 17 00:00:00 2001
From: Suresh K C <suresh.k.chandrappa@gmail.com>
Date: Sat, 18 Apr 2026 10:14:20 +0530
Subject: [PATCH] jfs: fix use-after-free in lbmIODone

Add an atomic io_inflight counter and a wait queue (io_waitq) to
struct jfs_log to track in-flight I/O operations. This ensures that
lbmLogShutdown() waits for all pending log I/O to complete before
freeing log buffers, preventing a use-after-free race condition where
the loop device workqueue could still be reading from log buffer pages
that have already been freed.

The io_inflight counter is incremented in lbmRead() and lbmStartIO()
before submitting bios, and decremented in lbmIODone() after I/O
completion processing is finished.

Reported-by: syzbot+6cc93ec9a4035badb85f@syzkaller.appspotmail.com
Signed-off-by: Suresh K C <suresh.k.chandrappa@gmail.com>
---
 fs/jfs/jfs_logmgr.c | 12 +++++++++++-
 fs/jfs/jfs_logmgr.h |  3 +++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 306165e61438..e8ae90be089b 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1804,6 +1804,7 @@ static int lbmLogInit(struct jfs_log * log)
      * avoid deadlock here.
      */
     init_waitqueue_head(&log->free_wait);
+    init_waitqueue_head(&log->io_waitq);

     log->lbuf_free = NULL;

@@ -1855,6 +1856,8 @@ static void lbmLogShutdown(struct jfs_log * log)

     jfs_info("lbmLogShutdown: log:0x%p", log);

+    wait_event(log->io_waitq, !atomic_read(&log->io_inflight));
+
     lbuf = log->lbuf_free;
     while (lbuf) {
         struct lbuf *next = lbuf->l_freelist;
@@ -1976,6 +1979,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_inflight);
     /*check if journaling to disk has been disabled*/
     if (log->no_integrity) {
         bio->bi_iter.bi_size = 0;
@@ -2123,6 +2128,7 @@ static void lbmStartIO(struct lbuf * bp)
     bio->bi_end_io = lbmIODone;
     bio->bi_private = bp;

+    atomic_inc(&log->io_inflight);
     /* check if journaling to disk has been disabled */
     if (log->no_integrity) {
         bio->bi_iter.bi_size = 0;
@@ -2186,6 +2192,8 @@ static void lbmIODone(struct bio *bio)

     bio_put(bio);

+    log = bp->l_log;
+
     /*
      *    pagein completion
      */
@@ -2214,7 +2222,6 @@ static void lbmIODone(struct bio *bio)
     INCREMENT(lmStat.pagedone);

     /* update committed lsn */
-    log = bp->l_log;
     log->clsn = (bp->l_pn << L2LOGPSIZE) + bp->l_ceor;

     if (bp->l_flag & lbmDIRECT) {
@@ -2299,6 +2306,9 @@ static void lbmIODone(struct bio *bio)
 out:
     bp->l_flag |= lbmDONE;
     LCACHE_UNLOCK(flags);
+
+    if (atomic_dec_and_test(&log->io_inflight))
+        wake_up(&log->io_waitq);
 }

 int jfsIOWait(void *arg)
diff --git a/fs/jfs/jfs_logmgr.h b/fs/jfs/jfs_logmgr.h
index 09e0ef6aecce..d8858448de6f 100644
--- a/fs/jfs/jfs_logmgr.h
+++ b/fs/jfs/jfs_logmgr.h
@@ -400,6 +400,9 @@ struct jfs_log {
     uuid_t uuid;        /* 16: 128-bit uuid of log device */

     int no_integrity;    /* 3: flag to disable journaling to disk */
+
+    atomic_t io_inflight;
+    wait_queue_head_t io_waitq;
 };

 /*
-- 
2.43.0

  parent reply	other threads:[~2026-04-20  4:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30  9:56 [syzbot] [mm?] KASAN: use-after-free Read in copy_folio_from_iter_atomic (2) syzbot
2026-04-16 10:23 ` syzbot
2026-04-17 20:43 ` Forwarded: " syzbot
2026-04-20  4:08 ` syzbot [this message]
2026-04-20  4:11 ` syzbot
2026-04-23 13:26 ` Forwarded: [PATCH 1/1] jfs: try syzbot fix 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=69e5a6c2.050a0220.24bfd3.0021.GAE@google.com \
    --to=syzbot+6cc93ec9a4035badb85f@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