Skip to content

Commit 193cbbd

Browse files
krismanopsiff
authored andcommitted
ext4: fix error message when rejecting the default hash
commit a218743 upstream. Commit 985b67c ("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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 0eb7d3da258b05538f573200fab751420ca93b2f) Signed-off-by: Wentao Guan <[email protected]>
1 parent 573960c commit 193cbbd

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,7 @@ static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
24592459
#define DX_HASH_HALF_MD4_UNSIGNED 4
24602460
#define DX_HASH_TEA_UNSIGNED 5
24612461
#define DX_HASH_SIPHASH 6
2462+
#define DX_HASH_LAST DX_HASH_SIPHASH
24622463

24632464
static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
24642465
const void *address, unsigned int length)

fs/ext4/super.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,14 +3639,6 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly)
36393639
}
36403640
#endif
36413641

3642-
if (EXT4_SB(sb)->s_es->s_def_hash_version == DX_HASH_SIPHASH &&
3643-
!ext4_has_feature_casefold(sb)) {
3644-
ext4_msg(sb, KERN_ERR,
3645-
"Filesystem without casefold feature cannot be "
3646-
"mounted with siphash");
3647-
return 0;
3648-
}
3649-
36503642
if (readonly)
36513643
return 1;
36523644

@@ -5155,16 +5147,27 @@ static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb,
51555147
return ret;
51565148
}
51575149

5158-
static void ext4_hash_info_init(struct super_block *sb)
5150+
static int ext4_hash_info_init(struct super_block *sb)
51595151
{
51605152
struct ext4_sb_info *sbi = EXT4_SB(sb);
51615153
struct ext4_super_block *es = sbi->s_es;
51625154
unsigned int i;
51635155

5156+
sbi->s_def_hash_version = es->s_def_hash_version;
5157+
5158+
if (sbi->s_def_hash_version > DX_HASH_LAST) {
5159+
ext4_msg(sb, KERN_ERR,
5160+
"Invalid default hash set in the superblock");
5161+
return -EINVAL;
5162+
} else if (sbi->s_def_hash_version == DX_HASH_SIPHASH) {
5163+
ext4_msg(sb, KERN_ERR,
5164+
"SIPHASH is not a valid default hash value");
5165+
return -EINVAL;
5166+
}
5167+
51645168
for (i = 0; i < 4; i++)
51655169
sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
51665170

5167-
sbi->s_def_hash_version = es->s_def_hash_version;
51685171
if (ext4_has_feature_dir_index(sb)) {
51695172
i = le32_to_cpu(es->s_flags);
51705173
if (i & EXT2_FLAGS_UNSIGNED_HASH)
@@ -5182,6 +5185,7 @@ static void ext4_hash_info_init(struct super_block *sb)
51825185
#endif
51835186
}
51845187
}
5188+
return 0;
51855189
}
51865190

51875191
static int ext4_block_group_meta_init(struct super_block *sb, int silent)
@@ -5326,7 +5330,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53265330
if (err)
53275331
goto failed_mount;
53285332

5329-
ext4_hash_info_init(sb);
5333+
err = ext4_hash_info_init(sb);
5334+
if (err)
5335+
goto failed_mount;
53305336

53315337
err = ext4_handle_clustersize(sb);
53325338
if (err)

0 commit comments

Comments
 (0)