Skip to content

Commit 5f41fda

Browse files
ebiggerstytso
authored andcommitted
ext4: only allow test_dummy_encryption when supported
Make the test_dummy_encryption mount option require that the encrypt feature flag be already enabled on the filesystem, rather than automatically enabling it. Practically, this means that "-O encrypt" will need to be included in MKFS_OPTIONS when running xfstests with the test_dummy_encryption mount option. (ext4/053 also needs an update.) Moreover, as long as the preconditions for test_dummy_encryption are being tightened anyway, take the opportunity to start rejecting it when !CONFIG_FS_ENCRYPTION rather than ignoring it. The motivation for requiring the encrypt feature flag is that: - Having the filesystem auto-enable feature flags is problematic, as it bypasses the usual sanity checks. The specific issue which came up recently is that in kernel versions where ext4 supports casefold but not encrypt+casefold (v5.1 through v5.10), the kernel will happily add the encrypt flag to a filesystem that has the casefold flag, making it unmountable -- but only for subsequent mounts, not the initial one. This confused the casefold support detection in xfstests, causing generic/556 to fail rather than be skipped. - The xfstests-bld test runners (kvm-xfstests et al.) already use the required mkfs flag, so they will not be affected by this change. Only users of test_dummy_encryption alone will be affected. But, this option has always been for testing only, so it should be fine to require that the few users of this option update their test scripts. - f2fs already requires it (for its equivalent feature flag). Signed-off-by: Eric Biggers <[email protected]> Reviewed-by: Gabriel Krisman Bertazi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent d36f6ed commit 5f41fda

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

fs/ext4/ext4.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,12 +1442,6 @@ struct ext4_super_block {
14421442

14431443
#ifdef __KERNEL__
14441444

1445-
#ifdef CONFIG_FS_ENCRYPTION
1446-
#define DUMMY_ENCRYPTION_ENABLED(sbi) ((sbi)->s_dummy_enc_policy.policy != NULL)
1447-
#else
1448-
#define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
1449-
#endif
1450-
14511445
/* Number of quota types we support */
14521446
#define EXT4_MAXQUOTAS 3
14531447

fs/ext4/super.c

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,11 +2308,12 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
23082308
ctx->spec |= EXT4_SPEC_DUMMY_ENCRYPTION;
23092309
ctx->test_dummy_enc_arg = kmemdup_nul(param->string, param->size,
23102310
GFP_KERNEL);
2311+
return 0;
23112312
#else
23122313
ext4_msg(NULL, KERN_WARNING,
2313-
"Test dummy encryption mount option ignored");
2314+
"test_dummy_encryption option not supported");
2315+
return -EINVAL;
23142316
#endif
2315-
return 0;
23162317
case Opt_dax:
23172318
case Opt_dax_type:
23182319
#ifdef CONFIG_FS_DAX
@@ -2669,12 +2670,44 @@ static int ext4_check_quota_consistency(struct fs_context *fc,
26692670
#endif
26702671
}
26712672

2673+
static int ext4_check_test_dummy_encryption(const struct fs_context *fc,
2674+
struct super_block *sb)
2675+
{
2676+
#ifdef CONFIG_FS_ENCRYPTION
2677+
const struct ext4_fs_context *ctx = fc->fs_private;
2678+
const struct ext4_sb_info *sbi = EXT4_SB(sb);
2679+
2680+
if (!(ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION))
2681+
return 0;
2682+
2683+
if (!ext4_has_feature_encrypt(sb)) {
2684+
ext4_msg(NULL, KERN_WARNING,
2685+
"test_dummy_encryption requires encrypt feature");
2686+
return -EINVAL;
2687+
}
2688+
/*
2689+
* This mount option is just for testing, and it's not worthwhile to
2690+
* implement the extra complexity (e.g. RCU protection) that would be
2691+
* needed to allow it to be set or changed during remount. We do allow
2692+
* it to be specified during remount, but only if there is no change.
2693+
*/
2694+
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
2695+
!sbi->s_dummy_enc_policy.policy) {
2696+
ext4_msg(NULL, KERN_WARNING,
2697+
"Can't set test_dummy_encryption on remount");
2698+
return -EINVAL;
2699+
}
2700+
#endif /* CONFIG_FS_ENCRYPTION */
2701+
return 0;
2702+
}
2703+
26722704
static int ext4_check_opt_consistency(struct fs_context *fc,
26732705
struct super_block *sb)
26742706
{
26752707
struct ext4_fs_context *ctx = fc->fs_private;
26762708
struct ext4_sb_info *sbi = fc->s_fs_info;
26772709
int is_remount = fc->purpose == FS_CONTEXT_FOR_RECONFIGURE;
2710+
int err;
26782711

26792712
if ((ctx->opt_flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) {
26802713
ext4_msg(NULL, KERN_ERR,
@@ -2704,20 +2737,9 @@ static int ext4_check_opt_consistency(struct fs_context *fc,
27042737
"for blocksize < PAGE_SIZE");
27052738
}
27062739

2707-
#ifdef CONFIG_FS_ENCRYPTION
2708-
/*
2709-
* This mount option is just for testing, and it's not worthwhile to
2710-
* implement the extra complexity (e.g. RCU protection) that would be
2711-
* needed to allow it to be set or changed during remount. We do allow
2712-
* it to be specified during remount, but only if there is no change.
2713-
*/
2714-
if ((ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION) &&
2715-
is_remount && !sbi->s_dummy_enc_policy.policy) {
2716-
ext4_msg(NULL, KERN_WARNING,
2717-
"Can't set test_dummy_encryption on remount");
2718-
return -1;
2719-
}
2720-
#endif
2740+
err = ext4_check_test_dummy_encryption(fc, sb);
2741+
if (err)
2742+
return err;
27212743

27222744
if ((ctx->spec & EXT4_SPEC_DATAJ) && is_remount) {
27232745
if (!sbi->s_journal) {
@@ -5163,12 +5185,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
51635185
goto failed_mount_wq;
51645186
}
51655187

5166-
if (DUMMY_ENCRYPTION_ENABLED(sbi) && !sb_rdonly(sb) &&
5167-
!ext4_has_feature_encrypt(sb)) {
5168-
ext4_set_feature_encrypt(sb);
5169-
ext4_commit_super(sb);
5170-
}
5171-
51725188
/*
51735189
* Get the # of file system overhead blocks from the
51745190
* superblock if present.

0 commit comments

Comments
 (0)