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 5BDB53F8E04; Tue, 31 Mar 2026 16:42:09 +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=1774975329; cv=none; b=UIQ2DR0u3C/Mp8PXtvXc1mfZQMfVY4jC1zs4wrMc95KTzX5/mZXcai8d4rMu7OYhpWrFCbkY2TI3Anu5G7GF78seocxtutkm+s6Zuaqw//qpM8sKuOTNrV4AHIwst8v620/dKgvgnOV6jXnhZS3AIlUmtObh6jJXM7jfY/bXdSc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774975329; c=relaxed/simple; bh=Wy+opoYXVzAc0E/xL64dk/BVPT1/LtCwMxqI8XaNl90=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FR0HGcPgf9YmoHCZZDGo9hyRzmX1CCrEY1z9Uyc8NOUT1TwMV8nIssaSjrnqmlDueRk7LBKswC5lz7Mg3n+pZc5TdMcrDZyIUviKaWzMNcZaaVd6Abik9G6JKgqWksYiFB7ULL8ATcfwDCgwIj52VuS0i5s2zML0ExkMpHdV2cs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=aehYkz8v; 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="aehYkz8v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7CE2C19423; Tue, 31 Mar 2026 16:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774975329; bh=Wy+opoYXVzAc0E/xL64dk/BVPT1/LtCwMxqI8XaNl90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aehYkz8vMgOK7e0xBiRMQF8kNvdDiszHDuaX5BM109b+s1OxxqesfvREfB+r6dEyl AYi1De2j+12Jb1twexkTDYPGnFA/4bEvfI3oNsIhlM0Iby1tNC2b5ks3BPuE5QeEcu DKd1xnjleIy2lCMLWxwKMb8BsF49zMkBysoPoCbY= 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.19 252/342] jbd2: gracefully abort on checkpointing state corruptions Date: Tue, 31 Mar 2026 18:21:25 +0200 Message-ID: <20260331161808.230460332@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331161758.909578033@linuxfoundation.org> References: <20260331161758.909578033@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.19-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 @@ -267,7 +267,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; @@ -325,7 +333,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