jbd2: gate checksum calculations on crc driver presence, not sb flags
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 15 Oct 2015 14:30:36 +0000 (10:30 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 15 Oct 2015 14:30:36 +0000 (10:30 -0400)
Change the journal's checksum functions to gate on whether or not the
crc32c driver is loaded, and gate the loading on the superblock bits.
This prevents a journal crash if someone loads a journal in no-csum
mode and then randomizes the superblock, thus flipping on the feature
bits.

Tested-By: Nikolay Borisov <kernel@kyup.com>
Reported-by: Nikolay Borisov <kernel@kyup.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/journal.c
include/linux/jbd2.h

index 8270fe9e3641eb52521ef288ee46047559835bfb..00f7dbdd64b0b6ad5d6eaacd762c4653bf57b3bc 100644 (file)
@@ -124,7 +124,7 @@ EXPORT_SYMBOL(__jbd2_debug);
 /* Checksumming functions */
 static int jbd2_verify_csum_type(journal_t *j, journal_superblock_t *sb)
 {
-       if (!jbd2_journal_has_csum_v2or3(j))
+       if (!jbd2_journal_has_csum_v2or3_feature(j))
                return 1;
 
        return sb->s_checksum_type == JBD2_CRC32C_CHKSUM;
@@ -1531,7 +1531,7 @@ static int journal_get_superblock(journal_t *journal)
                goto out;
        }
 
-       if (jbd2_journal_has_csum_v2or3(journal) &&
+       if (jbd2_journal_has_csum_v2or3_feature(journal) &&
            JBD2_HAS_COMPAT_FEATURE(journal, JBD2_FEATURE_COMPAT_CHECKSUM)) {
                /* Can't have checksum v1 and v2 on at the same time! */
                printk(KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
@@ -1545,7 +1545,7 @@ static int journal_get_superblock(journal_t *journal)
        }
 
        /* Load the checksum driver */
-       if (jbd2_journal_has_csum_v2or3(journal)) {
+       if (jbd2_journal_has_csum_v2or3_feature(journal)) {
                journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
                if (IS_ERR(journal->j_chksum_driver)) {
                        printk(KERN_ERR "JBD2: Cannot load crc32c driver.\n");
index df07e78487d560f1e2d96b5e5249a57a080c4ed2..6da6f89722e18db92b99b4388a8eb374a5ab6975 100644 (file)
@@ -1338,13 +1338,18 @@ static inline int tid_geq(tid_t x, tid_t y)
 extern int jbd2_journal_blocks_per_page(struct inode *inode);
 extern size_t journal_tag_bytes(journal_t *journal);
 
+static inline bool jbd2_journal_has_csum_v2or3_feature(journal_t *j)
+{
+       return JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2) ||
+              JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V3);
+}
+
 static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
 {
-       if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2) ||
-           JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V3))
-               return 1;
+       WARN_ON_ONCE(jbd2_journal_has_csum_v2or3_feature(journal) &&
+                    journal->j_chksum_driver == NULL);
 
-       return 0;
+       return journal->j_chksum_driver != NULL;
 }
 
 /*