Skip to content

Commit a218743

Browse files
krismantytso
authored andcommitted
ext4: fix error message when rejecting the default hash
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]>
1 parent 5f48d4d commit a218743

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,7 @@ static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
24622462
#define DX_HASH_HALF_MD4_UNSIGNED 4
24632463
#define DX_HASH_TEA_UNSIGNED 5
24642464
#define DX_HASH_SIPHASH 6
2465+
#define DX_HASH_LAST DX_HASH_SIPHASH
24652466

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

fs/ext4/super.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,13 +3583,6 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly)
35833583
"mounted without CONFIG_UNICODE");
35843584
return 0;
35853585
}
3586-
if (EXT4_SB(sb)->s_es->s_def_hash_version == DX_HASH_SIPHASH &&
3587-
!ext4_has_feature_casefold(sb)) {
3588-
ext4_msg(sb, KERN_ERR,
3589-
"Filesystem without casefold feature cannot be "
3590-
"mounted with siphash");
3591-
return 0;
3592-
}
35933586

35943587
if (readonly)
35953588
return 1;
@@ -5095,16 +5088,27 @@ static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb,
50955088
return ret;
50965089
}
50975090

5098-
static void ext4_hash_info_init(struct super_block *sb)
5091+
static int ext4_hash_info_init(struct super_block *sb)
50995092
{
51005093
struct ext4_sb_info *sbi = EXT4_SB(sb);
51015094
struct ext4_super_block *es = sbi->s_es;
51025095
unsigned int i;
51035096

5097+
sbi->s_def_hash_version = es->s_def_hash_version;
5098+
5099+
if (sbi->s_def_hash_version > DX_HASH_LAST) {
5100+
ext4_msg(sb, KERN_ERR,
5101+
"Invalid default hash set in the superblock");
5102+
return -EINVAL;
5103+
} else if (sbi->s_def_hash_version == DX_HASH_SIPHASH) {
5104+
ext4_msg(sb, KERN_ERR,
5105+
"SIPHASH is not a valid default hash value");
5106+
return -EINVAL;
5107+
}
5108+
51045109
for (i = 0; i < 4; i++)
51055110
sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
51065111

5107-
sbi->s_def_hash_version = es->s_def_hash_version;
51085112
if (ext4_has_feature_dir_index(sb)) {
51095113
i = le32_to_cpu(es->s_flags);
51105114
if (i & EXT2_FLAGS_UNSIGNED_HASH)
@@ -5122,6 +5126,7 @@ static void ext4_hash_info_init(struct super_block *sb)
51225126
#endif
51235127
}
51245128
}
5129+
return 0;
51255130
}
51265131

51275132
static int ext4_block_group_meta_init(struct super_block *sb, int silent)
@@ -5257,7 +5262,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52575262
if (err)
52585263
goto failed_mount;
52595264

5260-
ext4_hash_info_init(sb);
5265+
err = ext4_hash_info_init(sb);
5266+
if (err)
5267+
goto failed_mount;
52615268

52625269
err = ext4_handle_clustersize(sb);
52635270
if (err)

0 commit comments

Comments
 (0)