Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795046231; b=GkPGnTrlQlEAwzU8lE7quyXdkjazWiS9r8FG8BRCImeOhg1AQbq77bGodH1hGQRWvLJS lXP1Qs1p0wCd35CDnGJoqV4/K/iYVX+t/OCRL9HY1Ynji8Sml9x4O5dQiDO1ooosy4hpY 3O9AOVray5IMVV7MB/JkqmzC/047tws2fok1W0+FzovWyf9mCqMw/QU4nvcBOBHj7rAF3 UUyCz/Ci4RrMalpfIi8S6moKJ1m3yb4yeOzcrmNWWR84IyFOHsldonl2ES17YeO6cuJD1 Y7hbbQ+Qoi6ea5gO4basXyZZ7HYedr4fY27twV0853DTw0jotLhTmFgK0pcDxlIb7rQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795046231; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=BHt8Y4+GboND5HgLl4y2eI0YBlPx9iOIJjwh0WAs150=; b=sNzycmvDtC6ea2vCptIgomkxBPCmRgq+EX5fYjuOvbFV4O2P29C9TOwSwcXQksybukkg KDhUam+dLKrB6DSb2SON4BiTJZTfCCPNjo44ub+s0SPCj7uogNFr2mHAK8cMoTJiTpLsH mzf2rNmbvFXIPbt4ajFY8XXXDfHMf9u14WD6vhXsTNXe3moi6p91jwU9d9+oTSr3B8t1d x3DAhxo7PDhI4sWNxWb+BRuF9XBT+RdIa5JnzEeXB2/Q2IpGbKO367KpMuVk1eFPpCNts I8F8/uk8ynNPWL2nRuTL1K/pgxvWsSPcBzrKgxULv4y5uXpiSM+z/eUZ7qy/GdVpsKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Ks07gIFC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 930FB606A31C; Wed, 18 Nov 2026 23:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Ks07gIFC Received: by smtp.kernel.org (Postfix) with ESMTPSA id E85C81F000C4; Wed, 18 Nov 2026 23:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795046231; bh=BHt8Y4+GboND5HgLl4y2eI0YBlPx9iOIJjwh0WAs150=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ks07gIFCht6No0Rs61/dWS7WbUTBhYDkhDRgaueX6mP+KQYIDqUSa/yNO3KpuFBsc 6oNtmCyM43dsGTsfirVWNMTNffM7LEyi6x/Sh5JgWW56jQ8hvoP/ZeXRnkyo79y5r4 /J2YCBsKYKj3myKX4MDI2cIcfDR0NqRdfHl8LDYQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Yu Junzhe , Daejun Park , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 6.1 1167/2857] jbd2: dont advance j_fc_off before the buffer is recorded Date: Wed, 18 Nov 2026 15:36:41 +0100 Message-ID: <20261118150243.607207169@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daejun Park commit 9f359c031885bb50add7d23c7a5a0e9755b134c9 upstream. jbd2_fc_get_buf() increments journal->j_fc_off before jbd2_journal_bmap() and __getblk() have had a chance to fail. When either does, the slot j_fc_wbuf[fc_off] is never assigned, but j_fc_off already counts it. ext4 then fails the fast commit and falls back, and the fallback path reaches jbd2_fc_release_bufs() via ext4_fc_commit -> jbd2_fc_end_commit_fallback -> __jbd2_fc_end_commit -> ext4_fc_cleanup. That walks down from j_fc_off - 1 and put_bh()es every slot until it sees NULL, so it also touches the slot that was never written. j_fc_wbuf comes from a plain kmalloc() and is never zeroed, so a slot used for the first time holds uninitialised heap data. Advance j_fc_off only after the buffer head has been stored. That restores the invariant that j_fc_off covers exactly the filled slots, which is what jbd2_fc_release_bufs() relies on: the live buffers of the current fast commit sit above the NULLs the previous one released, so stopping at the first NULL is correct. Reproduced on a KASAN kernel with an ext4 fast_commit filesystem on a loop device, truncating the backing file under the live mount so that only the journal's fast-commit region falls past the end of the device. __getblk() then fails for the first fast-commit block while the rest of the journal is still addressable, so the journal is not aborted and the fast commit reaches the fallback path. j_fc_wbuf was poisoned to make the read of the never-written slot visible: BUG: KASAN: wild-memory-access in jbd2_fc_release_bufs+0x6b/0xd0 Write of size 4 at addr 5a5a5a5a5a5a5ab2 by task sync/961 jbd2_fc_release_bufs+0x6b/0xd0 ext4_fc_cleanup+0x97/0x830 __jbd2_fc_end_commit+0x37/0xc0 ext4_fc_commit+0x524/0x560 ext4_sync_file+0x3c4/0x4b0 __x64_sys_fsync+0x20/0x30 With this patch the same run leaves j_fc_off at 0 across repeated __getblk() failures and completes cleanly. [ Context: in 6.1.y, jbd2_fc_get_buf() still advances j_fc_off inside the if/else bounds check, so the increment is removed from there. The change is otherwise the same as upstream. ] Fixes: ff780b91efe9 ("jbd2: add fast commit machinery") Cc: stable@kernel.org Reported-by: Yu Junzhe Closes: https://lore.kernel.org/linux-ext4/7e4b109d-64c3-444f-a5dc-93c2ca4576cc@gmail.com/ Signed-off-by: Daejun Park Reviewed-by: Jan Kara Link: https://patch.msgid.link/20260819060939epcms2p37bb8589b2f8a52a2b14bef38fadcf69d@epcms2p3 Signed-off-by: Theodore Ts'o Signed-off-by: Daejun Park Signed-off-by: Sasha Levin --- fs/jbd2/journal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index f54836c1dae22..4d26457f2e906 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -881,7 +881,6 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out) if (journal->j_fc_off + journal->j_fc_first < journal->j_fc_last) { fc_off = journal->j_fc_off; blocknr = journal->j_fc_first + fc_off; - journal->j_fc_off++; } else { ret = -EINVAL; } @@ -899,6 +898,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out) journal->j_fc_wbuf[fc_off] = bh; + journal->j_fc_off++; *bh_out = bh; -- 2.53.0