From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f80.google.com (mail-ot1-f80.google.com [209.85.210.80]) (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 A80103603F7 for ; Sat, 25 Apr 2026 11:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.80 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777116284; cv=none; b=N/uqmE7EKViaSS7+3wB9M1IpqtvqCoh6LbLNNX5WqSIM8IxZcCjH012B3seakO57XShrsIyUivGCb+Etk7/TeL64oWYiLbJ6wAA2bQRJNXyZ5r+6qXwOUbPFvHjrHlhTAdgeQbMvNvqXDLyne+07IZl/UNFOm1dqvq2WcgnvXBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777116284; c=relaxed/simple; bh=JTXGe5xaq4daPsYoaPN6cncUYMuae2irYjI4PgLE1nk=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=Zn10KM9goEJPTD0K6WP8GPEhENPawnit2+ZatAliKoAR6Mma8f0M1rlJIbujPE4UzyNNYtoTjVnXCzKwt8pDcY0fHlL9c08PxoJTbIRgY906NM/RXVlNSYAi7C89+7z8K2kyBOdkdi3xqHAX7BO8mQ3jLg0qWre2coPj73v1fGY= 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.80 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-f80.google.com with SMTP id 46e09a7af769-7dc41904354so18738812a34.0 for ; Sat, 25 Apr 2026 04:24:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777116281; x=1777721081; 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=3xbdb3jowE07yYKJrbinRy9hLdscT01kNkYeyspVkck=; b=qzNCkWyyZsFCvkomCDxuK/oiJ5aMW3owTgWytNE99x+CWm3TYb8/tbWV3hS7I8yiOw EvjGS1jnitB9Jrt0TMWDEK2QrLX/CHuSJ4Mo61H0lyUVGPRSARljOLruR3eDS4ZbwiCi L69jptlt2UwBqyrQwvjb1OncSPH0r5/je/52F4f5Fly1+/+jNRkP4ncKp6axkLGW7+1a P+4njWlZQLnTo1daIMBEDQJ38j8qGpzJZkZ7tkhVhb9r/r4UUCOdXtfE1/Wzedp15ncS WUChaC7vrKn/v/m5fKXLNfsdFF08Vb9palA3Rb9f7niiIWh5dH1nbvPE8PUeFuTYtSF8 WEqA== X-Gm-Message-State: AOJu0YxsoaOlB8LDWgDj273IdlwZAuI7FE43wUkJnenMbbX1w1mFy68V of0/7HWye0MIE8mNG1pFO91iUM9ycal9PsKZDiTOyOIvLTgEp7YuVo5PDytIHtSsIFTlBmMnTGq TW3Fpc1uoa8jZl9Jnj+X12gyyToC6vfpVIVt612m74A9rQoJfQEByeP5pLgCYrg== 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:518c:b0:694:21fa:4ef5 with SMTP id 006d021491bc7-69462e29ecamr13014209eaf.5.1777116281718; Sat, 25 Apr 2026 04:24:41 -0700 (PDT) Date: Sat, 25 Apr 2026 04:24:41 -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: <69eca479.a00a0220.7773.0017.GAE@google.com> Subject: Forwarded: [PATCH] jfs: fix use-after-free on log shutdown 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: [PATCH] jfs: fix use-after-free on log shutdown Author: mashiro.chen@mailbox.org 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 in lbmIODone() at the unified out: label, which all completion paths including READ, DIRECT, synchronous, GC, asynchronous converge on. 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 --- #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master fs/jfs/jfs_logmgr.c | 11 +++++++++-- fs/jfs/jfs_logmgr.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index 306165e61438..a567dae3b908 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); + init_waitqueue_head(&log->io_waitq); + atomic_set(&log->io_inflight, 0); log->lbuf_free = NULL; @@ -1855,6 +1857,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 +1980,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; @@ -2122,6 +2127,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) { @@ -2168,7 +2174,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; /* @@ -2214,7 +2220,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 +2304,8 @@ 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..31b826d546c0 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