From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f79.google.com (mail-oo1-f79.google.com [209.85.161.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 F3E52347C7 for ; Fri, 24 Apr 2026 21:16:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.79 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777065386; cv=none; b=q1w42M8rFE1ZrPxr3JJRD9Fz4I/9g3lfNSi0ywT8JomZQ/wcVLBe8JP+mami7Vlb6IZqahqG+K7Pto25EOYfqtb7HoyXK691W/CfalFfUdLd7auE1E55mV/gXCXwx5nqyUssfZjUy5GwsI75juMh1lrIi6WgHlvr7INeADOxIEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777065386; c=relaxed/simple; bh=K87sdV5mm6eeu5UmGZv/doCQM8+ZFnBTcUfKV2EfDoo=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=H0ES1KRtljuJ4CsSHOicDRoZKI1rJTMFVBp/b5zs8+oJdfkmYWJbW8QIF9qE6NruAh+jJsBjhNx1T+caxSl+iQJcmz6XFAJMhv6sUUhR7V1Xp6t6lZM2qDlJyLV89VqUY/KJwSAnADFjLoBQa2SxSKDmcgFWRDPFP8unb4hgZ0Y= 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.161.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-oo1-f79.google.com with SMTP id 006d021491bc7-6961cacdd3aso2644219eaf.0 for ; Fri, 24 Apr 2026 14:16:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777065384; x=1777670184; 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=TTE6b5atnT2X50oeGwG/5RusJRmI1WzV5W0tF4AMaSs=; b=HPhPNAeU4/0JXr7uNgTpyfNKr2y78tW1wwz84SbcmCuN6qQzTU0TsSIIgZQyKSZZDC ifLUKp5ucyOwOTmXorWx1pBx1blTjktfpy0G230WuyNO6L+bdWMO8vspnmGAv3QNxvP8 bEaPf7xdDxkGjhau0//9pfTwWOtejfj2UUFQ7MMrrOILkG1sZ3ElmzetF290JYdbjTPu wacxv0oPPCGiXY2nBwQc9LkgcAlLvrx8UpL82VNvAUQYE6O59kjAw0ageKFhxiR6GTCI na5Fl0fg5oJn65pmw5by6HrrdfFUznIwTjbgToNteLWIj0vSUYW2ighFhD/5KDBg7ouI Nrig== X-Gm-Message-State: AOJu0Yxl/P36kvURcUm+JhHFClKAWMZTelTA4EjhenRXqbJuaRW0u+YB 0Kd2PPGWvTz3CrLmKqTwr/2cHOdfv376V7/Cz1sshJLXir/hJjLzjjW8tC5j3UPG1Xz5rAUYOPs iBy+e7igov948k874jrkuHF4Kk3zvcXdJdTNDQQEWFRgtdZdHbfUNK/YoVCrklg== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:4b08:b0:67e:16b4:aa1a with SMTP id 006d021491bc7-69462f3f209mr19203338eaf.54.1777065384040; Fri, 24 Apr 2026 14:16:24 -0700 (PDT) Date: Fri, 24 Apr 2026 14:16:24 -0700 In-Reply-To: <69ca48ca.050a0220.183828.001a.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69ebdda8.a00a0220.7773.0008.GAE@google.com> Subject: Forwarded: Re: [syzbot] [mm?] KASAN: use-after-free Read in copy_folio_from_iter_atomic (2) 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: [syzbot] [mm?] KASAN: use-after-free Read in copy_folio_from_iter_atomic (2) Author: mashiro.chen@mailbox.org #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master >From 14bc67ec17b9a209d97c08e9136eead0bd0c0914 Mon Sep 17 00:00:00 2001 From: Mashiro Chen Date: Sat, 25 Apr 2026 01:56:00 +0800 Subject: [PATCH] jfs: fix use-after-free on log shutdown During JFS log shutdown, log buffer pages can be freed while lower-layer loop workers are still copying from them, triggering a use-after-free reported by syzbot in copy_folio_from_iter_atomic(). Track in-flight log I/O in struct jfs_log and wait for completion before freeing log buffers. Add io_inflight/io_waitq, increment io_inflight before submitting BIOs in lbmRead() and lbmStartIO(), and decrement it from lbmIODone() on all completion paths, including READ and DIRECT early-return paths. This closes the teardown race between buffer page free and late I/O completion. Reported-by: syzbot+6cc93ec9a4035badb85f@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6cc93ec9a4035badb85f Signed-off-by: Mashiro Chen --- fs/jfs/jfs_logmgr.c | 17 +++++++++++++++-- fs/jfs/jfs_logmgr.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index ada00d5bc214..a45c8e2559e4 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1806,6 +1806,8 @@ static int lbmLogInit(struct jfs_log * log) * avoid deadlock here. */ init_waitqueue_head(&log->free_wait); + init_waitqueue_head(&log->io_waitq); + atomic_set(&log->io_inflight, 0); log->lbuf_free = NULL; @@ -1857,6 +1859,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; @@ -1978,6 +1982,7 @@ 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; @@ -2124,6 +2129,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) { @@ -2170,7 +2176,7 @@ static void lbmIODone(struct bio *bio) { struct lbuf *bp = bio->bi_private; struct lbuf *nextbp, *tail; - struct jfs_log *log; + struct jfs_log *log = bp->l_log; unsigned long flags; /* @@ -2201,6 +2207,9 @@ static void lbmIODone(struct bio *bio) /* wakeup I/O initiator */ LCACHE_WAKEUP(&bp->l_ioevent); + if (atomic_dec_and_test(&log->io_inflight)) + wake_up(&log->io_waitq); + return; } @@ -2220,12 +2229,13 @@ 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) { LCACHE_WAKEUP(&bp->l_ioevent); LCACHE_UNLOCK(flags); + if (atomic_dec_and_test(&log->io_inflight)) + wake_up(&log->io_waitq); return; } @@ -2305,6 +2315,9 @@ static void lbmIODone(struct bio *bio) LCACHE_UNLOCK(flags); /* unlock+enable */ } + + 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 8b8994e48cd0..59cb0aca99c5 100644 --- a/fs/jfs/jfs_logmgr.h +++ b/fs/jfs/jfs_logmgr.h @@ -400,6 +400,8 @@ 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.54.0