From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E7883D890E; Wed, 8 Apr 2026 18:11:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775671884; cv=none; b=lvGdenUIU6SFybmZJ5z9kQhh+0uN5bw0eGYVofD36p+PoCsFxXAAZFmyqE79SqfqUjMPi7Y69BOySmSGa8tBEznmn3YUwibRYxneFQM+Nn4V/oVpRcDmXb5BQtD0YXbc2upcvexEGqiYdCm4N5w82Udt7tl42ND7rpInYctzvbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775671884; c=relaxed/simple; bh=ajnOFxDt6Rmk6FiCqW6X7wSfy3bPpA4AH/LOCnDjQXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nnWW7e645+tOFb06csPBQIllv4x4VmyTaMfUssgbcy2cJ2dDba/FpqZhiPloHQ2Tk8rBf8redmSs0BNEvmxsYxE8n7jwzAbJKDAf3kvqyv/x6CB6iI8bLxeS+nu+f/OklSm4L/E1Cf3Cl4Yy9R+Nwgn4NGo4tSasYv6eJh43aSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nFjCdMDQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="nFjCdMDQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16FE1C19425; Wed, 8 Apr 2026 18:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775671884; bh=ajnOFxDt6Rmk6FiCqW6X7wSfy3bPpA4AH/LOCnDjQXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nFjCdMDQw6/SbU/WadDLNkBZqQ6zoe2ywtjWCdaUxPeMFhww5quPnQ99/YtwNOSqB +duZANPmcim8WCdN4Et6nJ6D5UusNr/2xj5fi/91kTbo2ucus9+g4Okcd0jdRZmyiN x0jNbfe5TiK0hEKlnmJG1h2+kgbAl0mcizPq6jdU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Milos Nikic , Andreas Dilger , Zhang Yi , Baokun Li , Jan Kara , Theodore Tso , stable@kernel.org Subject: [PATCH 6.1 105/312] jbd2: gracefully abort on checkpointing state corruptions Date: Wed, 8 Apr 2026 20:00:22 +0200 Message-ID: <20260408175937.685075824@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.715315542@linuxfoundation.org> References: <20260408175933.715315542@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Milos Nikic commit bac3190a8e79beff6ed221975e0c9b1b5f2a21da upstream. This patch targets two internal state machine invariants in checkpoint.c residing inside functions that natively return integer error codes. - In jbd2_cleanup_journal_tail(): A blocknr of 0 indicates a severely corrupted journal superblock. Replaced the J_ASSERT with a WARN_ON_ONCE and a graceful journal abort, returning -EFSCORRUPTED. - In jbd2_log_do_checkpoint(): Replaced the J_ASSERT_BH checking for an unexpected buffer_jwrite state. If the warning triggers, we explicitly drop the just-taken get_bh() reference and call __flush_batch() to safely clean up any previously queued buffers in the j_chkpt_bhs array, preventing a memory leak before returning -EFSCORRUPTED. Signed-off-by: Milos Nikic Reviewed-by: Andreas Dilger Reviewed-by: Zhang Yi Reviewed-by: Baokun Li Reviewed-by: Jan Kara Link: https://patch.msgid.link/20260311041548.159424-1-nikic.milos@gmail.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/checkpoint.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c @@ -279,7 +279,15 @@ restart: */ BUFFER_TRACE(bh, "queue"); get_bh(bh); - J_ASSERT_BH(bh, !buffer_jwrite(bh)); + if (WARN_ON_ONCE(buffer_jwrite(bh))) { + put_bh(bh); /* drop the ref we just took */ + spin_unlock(&journal->j_list_lock); + /* Clean up any previously batched buffers */ + if (batch_count) + __flush_batch(journal, &batch_count); + jbd2_journal_abort(journal, -EFSCORRUPTED); + return -EFSCORRUPTED; + } journal->j_chkpt_bhs[batch_count++] = bh; transaction->t_chp_stats.cs_written++; transaction->t_checkpoint_list = jh->b_cpnext; @@ -337,7 +345,10 @@ int jbd2_cleanup_journal_tail(journal_t if (!jbd2_journal_get_log_tail(journal, &first_tid, &blocknr)) return 1; - J_ASSERT(blocknr != 0); + if (WARN_ON_ONCE(blocknr == 0)) { + jbd2_journal_abort(journal, -EFSCORRUPTED); + return -EFSCORRUPTED; + } /* * We need to make sure that any blocks that were recently written out