1 jbd2: gate checksum calculations on crc driver presence, not sb flags
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 Change the journal's checksum functions to gate on whether or not the
6 crc32c driver is loaded, and gate the loading on the superblock bits.
7 This prevents a journal crash if someone loads a journal in no-csum
8 mode and then randomizes the superblock, thus flipping on the feature
11 Tested-By: Nikolay Borisov <kernel@kyup.com>
12 Reported-by: Nikolay Borisov <kernel@kyup.com>
13 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 fs/jbd2/journal.c | 6 +++---
17 include/linux/jbd2.h | 13 +++++++++----
18 2 files changed, 12 insertions(+), 7 deletions(-)
21 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
22 index 8270fe9..00f7dbd 100644
23 --- a/fs/jbd2/journal.c
24 +++ b/fs/jbd2/journal.c
25 @@ -124,7 +124,7 @@ EXPORT_SYMBOL(__jbd2_debug);
26 /* Checksumming functions */
27 static int jbd2_verify_csum_type(journal_t *j, journal_superblock_t *sb)
29 - if (!jbd2_journal_has_csum_v2or3(j))
30 + if (!jbd2_journal_has_csum_v2or3_feature(j))
33 return sb->s_checksum_type == JBD2_CRC32C_CHKSUM;
34 @@ -1531,7 +1531,7 @@ static int journal_get_superblock(journal_t *journal)
38 - if (jbd2_journal_has_csum_v2or3(journal) &&
39 + if (jbd2_journal_has_csum_v2or3_feature(journal) &&
40 JBD2_HAS_COMPAT_FEATURE(journal, JBD2_FEATURE_COMPAT_CHECKSUM)) {
41 /* Can't have checksum v1 and v2 on at the same time! */
42 printk(KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
43 @@ -1545,7 +1545,7 @@ static int journal_get_superblock(journal_t *journal)
46 /* Load the checksum driver */
47 - if (jbd2_journal_has_csum_v2or3(journal)) {
48 + if (jbd2_journal_has_csum_v2or3_feature(journal)) {
49 journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
50 if (IS_ERR(journal->j_chksum_driver)) {
51 printk(KERN_ERR "JBD2: Cannot load crc32c driver.\n");
52 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
53 index df07e78..6da6f89 100644
54 --- a/include/linux/jbd2.h
55 +++ b/include/linux/jbd2.h
56 @@ -1338,13 +1338,18 @@ static inline int tid_geq(tid_t x, tid_t y)
57 extern int jbd2_journal_blocks_per_page(struct inode *inode);
58 extern size_t journal_tag_bytes(journal_t *journal);
60 +static inline bool jbd2_journal_has_csum_v2or3_feature(journal_t *j)
62 + return JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2) ||
63 + JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V3);
66 static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
68 - if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2) ||
69 - JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V3))
71 + WARN_ON_ONCE(jbd2_journal_has_csum_v2or3_feature(journal) &&
72 + journal->j_chksum_driver == NULL);
75 + return journal->j_chksum_driver != NULL;