]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: fix error message when rejecting the default hash
authorGabriel Krisman Bertazi <krisman@suse.de>
Thu, 8 Jan 2026 15:04:29 +0000 (12:04 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:10:13 +0000 (13:10 +0100)
commit a2187431c395cdfbf144e3536f25468c64fc7cfa upstream.

Commit 985b67cd8639 ("ext4: filesystems without casefold feature cannot
be mounted with siphash") properly rejects volumes where
s_def_hash_version is set to DX_HASH_SIPHASH, but the check and the
error message should not look into casefold setup - a filesystem should
never have DX_HASH_SIPHASH as the default hash.  Fix it and, since we
are there, move the check to ext4_hash_info_init.

Fixes:985b67cd8639 ("ext4: filesystems without casefold feature cannot
be mounted with siphash")

Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
Link: https://patch.msgid.link/87jzg1en6j.fsf_-_@mailhost.krisman.be
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
[cascardo: conflicts due to other parts of ext4_fill_super having been factored out]
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/ext4.h
fs/ext4/super.c

index 14dc0a3160fd0b1b358210647c3055594c707b8f..389251ee9ac9bde6cb51bb3601d04c8ab1c685e9 100644 (file)
@@ -2443,6 +2443,7 @@ static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
 #define DX_HASH_HALF_MD4_UNSIGNED      4
 #define DX_HASH_TEA_UNSIGNED           5
 #define DX_HASH_SIPHASH                        6
+#define DX_HASH_LAST                   DX_HASH_SIPHASH
 
 static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
                              const void *address, unsigned int length)
index b2f892e3b1afb7ceb25a97b583106d117229465b..05f1f9b7ad0c4a41bdc448c937c4203d56c114d4 100644 (file)
@@ -3191,14 +3191,6 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly)
        }
 #endif
 
-       if (EXT4_SB(sb)->s_es->s_def_hash_version == DX_HASH_SIPHASH &&
-           !ext4_has_feature_casefold(sb)) {
-               ext4_msg(sb, KERN_ERR,
-                        "Filesystem without casefold feature cannot be "
-                        "mounted with siphash");
-               return 0;
-       }
-
        if (readonly)
                return 1;
 
@@ -3897,16 +3889,27 @@ static void ext4_setup_csum_trigger(struct super_block *sb,
        sbi->s_journal_triggers[type].tr_triggers.t_frozen = trigger;
 }
 
-static void ext4_hash_info_init(struct super_block *sb)
+static int ext4_hash_info_init(struct super_block *sb)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
        struct ext4_super_block *es = sbi->s_es;
        unsigned int i;
 
+       sbi->s_def_hash_version = es->s_def_hash_version;
+
+       if (sbi->s_def_hash_version > DX_HASH_LAST) {
+               ext4_msg(sb, KERN_ERR,
+                        "Invalid default hash set in the superblock");
+               return -EINVAL;
+       } else if (sbi->s_def_hash_version == DX_HASH_SIPHASH) {
+               ext4_msg(sb, KERN_ERR,
+                        "SIPHASH is not a valid default hash value");
+               return -EINVAL;
+       }
+
        for (i = 0; i < 4; i++)
                sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
 
-       sbi->s_def_hash_version = es->s_def_hash_version;
        if (ext4_has_feature_dir_index(sb)) {
                i = le32_to_cpu(es->s_flags);
                if (i & EXT2_FLAGS_UNSIGNED_HASH)
@@ -3924,6 +3927,7 @@ static void ext4_hash_info_init(struct super_block *sb)
 #endif
                }
        }
+       return 0;
 }
 
 static int ext4_fill_super(struct super_block *sb, void *data, int silent)
@@ -4444,7 +4448,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
        sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
        sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
 
-       ext4_hash_info_init(sb);
+       err = ext4_hash_info_init(sb);
+       if (err)
+               goto failed_mount;
 
        /* Handle clustersize */
        clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);