Commit 5f41fdae authored by Eric Biggers's avatar Eric Biggers Committed by Theodore Ts'o

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: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
Link: https://lore.kernel.org/r/20220519204437.61645-1-ebiggers@kernel.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent d36f6ed7
...@@ -1442,12 +1442,6 @@ struct ext4_super_block { ...@@ -1442,12 +1442,6 @@ struct ext4_super_block {
#ifdef __KERNEL__ #ifdef __KERNEL__
#ifdef CONFIG_FS_ENCRYPTION
#define DUMMY_ENCRYPTION_ENABLED(sbi) ((sbi)->s_dummy_enc_policy.policy != NULL)
#else
#define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
#endif
/* Number of quota types we support */ /* Number of quota types we support */
#define EXT4_MAXQUOTAS 3 #define EXT4_MAXQUOTAS 3
......
...@@ -2308,11 +2308,12 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param) ...@@ -2308,11 +2308,12 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
ctx->spec |= EXT4_SPEC_DUMMY_ENCRYPTION; ctx->spec |= EXT4_SPEC_DUMMY_ENCRYPTION;
ctx->test_dummy_enc_arg = kmemdup_nul(param->string, param->size, ctx->test_dummy_enc_arg = kmemdup_nul(param->string, param->size,
GFP_KERNEL); GFP_KERNEL);
return 0;
#else #else
ext4_msg(NULL, KERN_WARNING, ext4_msg(NULL, KERN_WARNING,
"Test dummy encryption mount option ignored"); "test_dummy_encryption option not supported");
return -EINVAL;
#endif #endif
return 0;
case Opt_dax: case Opt_dax:
case Opt_dax_type: case Opt_dax_type:
#ifdef CONFIG_FS_DAX #ifdef CONFIG_FS_DAX
...@@ -2669,12 +2670,44 @@ static int ext4_check_quota_consistency(struct fs_context *fc, ...@@ -2669,12 +2670,44 @@ static int ext4_check_quota_consistency(struct fs_context *fc,
#endif #endif
} }
static int ext4_check_test_dummy_encryption(const struct fs_context *fc,
struct super_block *sb)
{
#ifdef CONFIG_FS_ENCRYPTION
const struct ext4_fs_context *ctx = fc->fs_private;
const struct ext4_sb_info *sbi = EXT4_SB(sb);
if (!(ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION))
return 0;
if (!ext4_has_feature_encrypt(sb)) {
ext4_msg(NULL, KERN_WARNING,
"test_dummy_encryption requires encrypt feature");
return -EINVAL;
}
/*
* This mount option is just for testing, and it's not worthwhile to
* implement the extra complexity (e.g. RCU protection) that would be
* needed to allow it to be set or changed during remount. We do allow
* it to be specified during remount, but only if there is no change.
*/
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
!sbi->s_dummy_enc_policy.policy) {
ext4_msg(NULL, KERN_WARNING,
"Can't set test_dummy_encryption on remount");
return -EINVAL;
}
#endif /* CONFIG_FS_ENCRYPTION */
return 0;
}
static int ext4_check_opt_consistency(struct fs_context *fc, static int ext4_check_opt_consistency(struct fs_context *fc,
struct super_block *sb) struct super_block *sb)
{ {
struct ext4_fs_context *ctx = fc->fs_private; struct ext4_fs_context *ctx = fc->fs_private;
struct ext4_sb_info *sbi = fc->s_fs_info; struct ext4_sb_info *sbi = fc->s_fs_info;
int is_remount = fc->purpose == FS_CONTEXT_FOR_RECONFIGURE; int is_remount = fc->purpose == FS_CONTEXT_FOR_RECONFIGURE;
int err;
if ((ctx->opt_flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) { if ((ctx->opt_flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) {
ext4_msg(NULL, KERN_ERR, ext4_msg(NULL, KERN_ERR,
...@@ -2704,20 +2737,9 @@ static int ext4_check_opt_consistency(struct fs_context *fc, ...@@ -2704,20 +2737,9 @@ static int ext4_check_opt_consistency(struct fs_context *fc,
"for blocksize < PAGE_SIZE"); "for blocksize < PAGE_SIZE");
} }
#ifdef CONFIG_FS_ENCRYPTION err = ext4_check_test_dummy_encryption(fc, sb);
/* if (err)
* This mount option is just for testing, and it's not worthwhile to return err;
* implement the extra complexity (e.g. RCU protection) that would be
* needed to allow it to be set or changed during remount. We do allow
* it to be specified during remount, but only if there is no change.
*/
if ((ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION) &&
is_remount && !sbi->s_dummy_enc_policy.policy) {
ext4_msg(NULL, KERN_WARNING,
"Can't set test_dummy_encryption on remount");
return -1;
}
#endif
if ((ctx->spec & EXT4_SPEC_DATAJ) && is_remount) { if ((ctx->spec & EXT4_SPEC_DATAJ) && is_remount) {
if (!sbi->s_journal) { if (!sbi->s_journal) {
...@@ -5163,12 +5185,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) ...@@ -5163,12 +5185,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
goto failed_mount_wq; goto failed_mount_wq;
} }
if (DUMMY_ENCRYPTION_ENABLED(sbi) && !sb_rdonly(sb) &&
!ext4_has_feature_encrypt(sb)) {
ext4_set_feature_encrypt(sb);
ext4_commit_super(sb);
}
/* /*
* Get the # of file system overhead blocks from the * Get the # of file system overhead blocks from the
* superblock if present. * superblock if present.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment