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 3A8453A1E98 for ; Mon, 29 Dec 2025 23:34:29 +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=1767051270; cv=none; b=Jyk6rnyrRR5l40uas5QMywOCCK87GhMIyLowGB62OvAbo7Ii6do69PE8QJPt6mlO6e5BNRDRUWQMIbIFoDdrJpPXsUqaDp6rYAhVmA2lJm2lcFKKqATdIx+BO1ddTMg0R5UokNSq294VFO94gBVgFQochku888tbHZ/3O4yPCQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767051270; c=relaxed/simple; bh=eoKqpOB4aoHEemBqRTD8ggKROYhzap+mo55dHP6XZxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=npqu37S4HyrSjP1wTl/nvjEHnqzOg3fq0h0skjFVybQOv9z+Z/wJudrduXa4ZtQfETQX9SWRfkcrZmUM7/mASl9SJZt5AEbT6dwbHJB+LUHoX76AZQHaJNyfFxsxI9g78Y3SQsX7c5PKF1B4cHVEs9qQZQwBWrc6C2xARVISo00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=niXCLxqE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="niXCLxqE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8892C4CEF7; Mon, 29 Dec 2025 23:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767051269; bh=eoKqpOB4aoHEemBqRTD8ggKROYhzap+mo55dHP6XZxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=niXCLxqEsbj0M7EYjqYJ8Wr4cWwg5kbitUhSOKa/PKLZSakIbPHYY5ARl1banzfdf 3BGLHYLQbN5Q0Bv5AMCk/2THZUzeEay6q/TLU9/G6o1MtV5nqTBIAfnoKjO83G6agh dFcpzHDfeUQi9J54gd2XmOEwzxCwmyUijXhZY6r5upjdp2gyPFcBbXKuDZMCIYE42d 4OhaAnid+c45gz4hx1hADv9juSLFB2RPOFzr3CmgaxBUFT8zKl+ZitLQIhI2Izeqjx u4pjTIipp9fDBueeahDz7xnMICeyupKoE3HCEg21+Pa2vzRLhImD/KenBJfzBCZZUW RtXwm36l2xY6Q== From: Sasha Levin To: stable@vger.kernel.org Cc: Ye Bin , Baokun Li , "Darrick J. Wong" , Jan Kara , Theodore Ts'o , stable@kernel.org, Sasha Levin Subject: [PATCH 6.12.y] jbd2: fix the inconsistency between checksum and data in memory for journal sb Date: Mon, 29 Dec 2025 18:34:27 -0500 Message-ID: <20251229233427.1825600-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025122927-germicide-venus-61d2@gregkh> References: <2025122927-germicide-venus-61d2@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ye Bin [ Upstream commit 6abfe107894af7e8ce3a2e120c619d81ee764ad5 ] Copying the file system while it is mounted as read-only results in a mount failure: [~]# mkfs.ext4 -F /dev/sdc [~]# mount /dev/sdc -o ro /mnt/test [~]# dd if=/dev/sdc of=/dev/sda bs=1M [~]# mount /dev/sda /mnt/test1 [ 1094.849826] JBD2: journal checksum error [ 1094.850927] EXT4-fs (sda): Could not load journal inode mount: mount /dev/sda on /mnt/test1 failed: Bad message The process described above is just an abstracted way I came up with to reproduce the issue. In the actual scenario, the file system was mounted read-only and then copied while it was still mounted. It was found that the mount operation failed. The user intended to verify the data or use it as a backup, and this action was performed during a version upgrade. Above issue may happen as follows: ext4_fill_super set_journal_csum_feature_set(sb) if (ext4_has_metadata_csum(sb)) incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3; if (test_opt(sb, JOURNAL_CHECKSUM) jbd2_journal_set_features(sbi->s_journal, compat, 0, incompat); lock_buffer(journal->j_sb_buffer); sb->s_feature_incompat |= cpu_to_be32(incompat); //The data in the journal sb was modified, but the checksum was not updated, so the data remaining in memory has a mismatch between the data and the checksum. unlock_buffer(journal->j_sb_buffer); In this case, the journal sb copied over is in a state where the checksum and data are inconsistent, so mounting fails. To solve the above issue, update the checksum in memory after modifying the journal sb. Fixes: 4fd5ea43bc11 ("jbd2: checksum journal superblock") Signed-off-by: Ye Bin Reviewed-by: Baokun Li Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Message-ID: <20251103010123.3753631-1-yebin@huaweicloud.com> Signed-off-by: Theodore Ts'o Cc: stable@kernel.org [ jbd2_superblock_csum() also takes a journal param ] Signed-off-by: Sasha Levin --- fs/jbd2/journal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index c073f5fb9859..ce51aac13f29 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -2373,6 +2373,12 @@ int jbd2_journal_set_features(journal_t *journal, unsigned long compat, sb->s_feature_compat |= cpu_to_be32(compat); sb->s_feature_ro_compat |= cpu_to_be32(ro); sb->s_feature_incompat |= cpu_to_be32(incompat); + /* + * Update the checksum now so that it is valid even for read-only + * filesystems where jbd2_write_superblock() doesn't get called. + */ + if (jbd2_journal_has_csum_v2or3(journal)) + sb->s_checksum = jbd2_superblock_csum(journal, sb); unlock_buffer(journal->j_sb_buffer); jbd2_journal_init_transaction_limits(journal); @@ -2402,9 +2408,17 @@ void jbd2_journal_clear_features(journal_t *journal, unsigned long compat, sb = journal->j_superblock; + lock_buffer(journal->j_sb_buffer); sb->s_feature_compat &= ~cpu_to_be32(compat); sb->s_feature_ro_compat &= ~cpu_to_be32(ro); sb->s_feature_incompat &= ~cpu_to_be32(incompat); + /* + * Update the checksum now so that it is valid even for read-only + * filesystems where jbd2_write_superblock() doesn't get called. + */ + if (jbd2_journal_has_csum_v2or3(journal)) + sb->s_checksum = jbd2_superblock_csum(journal, sb); + unlock_buffer(journal->j_sb_buffer); jbd2_journal_init_transaction_limits(journal); } EXPORT_SYMBOL(jbd2_journal_clear_features); -- 2.51.0