From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) (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 44CE039F166 for ; Fri, 17 Apr 2026 14:20:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776435609; cv=none; b=GlvfM1t9WV0ESesdJlQhddKyZko4tXWusMFqw+EYHQ2AylE9HCwzRNZISn+JgTCs4qBNuJ/eF8St9q4IW24iTxRkf0kY3U48x7p5NjAnIZpnLJ2hl7C1AA/0iAoJTX3YAH/I4ZTJY5md1IVg6ycsN7aAeMZSEItxn92+r46gaEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776435609; c=relaxed/simple; bh=4d3SaqP1eegNS95ktMyOdl1hcVDkOqmecnpWs5lKRVY=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=izCVpA288tIu+yoRK/CAhj0/4XU8YWiFlCGr58aCwJ8vA6rD21NXsSqP6F/em8RvGPxG98goKMobfLgB8xFH282x6sY1EEuDg80BM1sS3GjQG77bn8xQmMkQg+Mk8vHEv+pV93q87OJji6NNYNr1JcKGTE81QMQ62YQA7Cg6CKw= 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.70 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-f70.google.com with SMTP id 006d021491bc7-688c232dd72so1049497eaf.1 for ; Fri, 17 Apr 2026 07:20:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776435606; x=1777040406; 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=NWtt7u5LMj6Okz33c3QjOQBfgBl3apeTrl1AXF1QoZ4=; b=erp7BCdJqpEOoG67RXbtu0cPs0QVC7BwLOE7EZQwLaO0ozcLWKVVbWAdTwSnC0yheI QByIvUiWvI7+Z5DlmSbmMjSFzN3NZ0CverhQvVF1OxRt1itVXE1BEf7X9Hx17jCHFv7n wKWMm3oHRIr3AjPJdHSkWWAZXwCuFBpt+8+9AcueSKo6PqjHpqiZKQ0gQbPJua/a61WI CUDsSc4ymvUsSniymXWZ88QoD3/tO/wtxUfgzLHm3iGi5zSmVtJ+cj4KjmmGM4TJMlW0 GWECHNUW7sMC4BMVU/IqEtMcmNRwFz2XRnytIE9ozPQD8LPmoeSu5lV+upAdZ7KVyfqq kqnA== X-Gm-Message-State: AOJu0Ywwu3HTu4Uai8ZDwCpBq9C4cPAHBm6xrJ1BQQVf0NQZQQ1YXYe4 tnFG5CpyIcYGLYA27BG57gW2lpoBygQUel48DiFfYUYp82eNvfnZ6k/Ib6tohhsOygecrSpHKqS JO7/Q15VEUR8OqBXMGZxlkofrYCZGFwF2o8ElVKswrn0+nHR9dA9IH3kYcws= 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:2106:b0:685:7d77:3c with SMTP id 006d021491bc7-69462ee7115mr1520769eaf.37.1776435606253; Fri, 17 Apr 2026 07:20:06 -0700 (PDT) Date: Fri, 17 Apr 2026 07:20:06 -0700 In-Reply-To: <68da879e.050a0220.1696c6.0016.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69e24196.050a0220.1de265.0025.GAE@google.com> Subject: Forwarded: [PATCH] jfs: fix use-after-free in lbmIODone by waiting for in-flight I/O 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 in lbmIODone by waiting for in-flight I/O Author: tristmd@gmail.com #syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master >From b8abd9772daa211b13c6db417c5c09495e688c61 Mon Sep 17 00:00:00 2001 From: Tristan Madani Date: Fri, 17 Apr 2026 14:19:45 +0000 Subject: [PATCH] jfs: fix use-after-free in lbmIODone by waiting for in-flight I/O lbmLogShutdown() frees all log buffer heads from the freelist, but does not wait for outstanding block I/O completions. When a log buffer write is submitted via lbmStartIO() and the filesystem is unmounted before the bio completes, lbmIODone() runs against a freed lbuf, causing a use-after-free read. Add an atomic I/O counter (io_count) to struct jfs_log. Increment it in lbmStartIO() before submit_bio(), decrement it in lbmIODone() after processing. In lbmLogShutdown(), wait for io_count to reach zero before freeing buffer heads, ensuring no in-flight I/O references freed memory. Reported-by: syzbot+ecf51a7ccb6b1394e90c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=ecf51a7ccb6b1394e90c Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- fs/jfs/jfs_logmgr.c | 15 ++++++++++++++- fs/jfs/jfs_logmgr.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index 306165e61..e309e1bbb 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1805,6 +1805,9 @@ static int lbmLogInit(struct jfs_log * log) */ init_waitqueue_head(&log->free_wait); + atomic_set(&log->io_count, 0); + init_waitqueue_head(&log->io_wait); + log->lbuf_free = NULL; for (i = 0; i < LOGPAGES;) { @@ -1855,6 +1858,8 @@ static void lbmLogShutdown(struct jfs_log * log) jfs_info("lbmLogShutdown: log:0x%p", log); + wait_event(log->io_wait, atomic_read(&log->io_count) == 0); + lbuf = log->lbuf_free; while (lbuf) { struct lbuf *next = lbuf->l_freelist; @@ -2128,6 +2133,7 @@ static void lbmStartIO(struct lbuf * bp) bio->bi_iter.bi_size = 0; lbmIODone(bio); } else { + atomic_inc(&log->io_count); submit_bio(bio); INCREMENT(lmStat.submitted); } @@ -2170,12 +2176,16 @@ static void lbmIODone(struct bio *bio) struct lbuf *nextbp, *tail; struct jfs_log *log; unsigned long flags; + int is_write; /* * get back jfs buffer bound to the i/o buffer */ jfs_info("lbmIODone: bp:0x%p flag:0x%x", bp, bp->l_flag); + log = bp->l_log; + is_write = !(bp->l_flag & lbmREAD); + LCACHE_LOCK(flags); /* disable+lock */ if (bio->bi_status) { @@ -2214,7 +2224,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 +2308,10 @@ static void lbmIODone(struct bio *bio) out: bp->l_flag |= lbmDONE; LCACHE_UNLOCK(flags); + + if (is_write && !log->no_integrity) + if (atomic_dec_and_test(&log->io_count)) + wake_up(&log->io_wait); } int jfsIOWait(void *arg) diff --git a/fs/jfs/jfs_logmgr.h b/fs/jfs/jfs_logmgr.h index 09e0ef6ae..50388562b 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_count; /* outstanding I/O count */ + wait_queue_head_t io_wait; /* wait for all I/O to complete */ }; /* -- 2.47.3