提交 b5c0d4fa 编写于 作者: E Eric Biggers 提交者: Zheng Zengkai

ext4: only allow test_dummy_encryption when supported

stable inclusion
from stable-v5.10.121
commit a67100f42665cf7a5ed7821376140f62def0d31e
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6CQ

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a67100f42665cf7a5ed7821376140f62def0d31e

--------------------------------

commit 5f41fdae upstream.

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: NEric Biggers <ebiggers@google.com>
Reviewed-by: NGabriel Krisman Bertazi <krisman@collabora.com>
Link: https://lore.kernel.org/r/20220519204437.61645-1-ebiggers@kernel.orgSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>

 Conflicts:
	fs/ext4/super.c
Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 396f4e2b
...@@ -1429,12 +1429,6 @@ struct ext4_super_block { ...@@ -1429,12 +1429,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
......
...@@ -2104,6 +2104,12 @@ static int ext4_set_test_dummy_encryption(struct super_block *sb, ...@@ -2104,6 +2104,12 @@ static int ext4_set_test_dummy_encryption(struct super_block *sb,
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
int err; int err;
if (!ext4_has_feature_encrypt(sb)) {
ext4_msg(sb, KERN_WARNING,
"test_dummy_encryption requires encrypt feature");
return -1;
}
/* /*
* This mount option is just for testing, and it's not worthwhile to * This mount option is just for testing, and it's not worthwhile to
* implement the extra complexity (e.g. RCU protection) that would be * implement the extra complexity (e.g. RCU protection) that would be
...@@ -2131,11 +2137,13 @@ static int ext4_set_test_dummy_encryption(struct super_block *sb, ...@@ -2131,11 +2137,13 @@ static int ext4_set_test_dummy_encryption(struct super_block *sb,
return -1; return -1;
} }
ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled"); ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled");
return 1;
#else #else
ext4_msg(sb, KERN_WARNING, ext4_msg(sb, KERN_WARNING,
"Test dummy encryption mount option ignored"); "test_dummy_encryption option not supported");
return -1;
#endif #endif
return 1;
} }
static int handle_mount_opt(struct super_block *sb, char *opt, int token, static int handle_mount_opt(struct super_block *sb, char *opt, int token,
...@@ -4967,12 +4975,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ...@@ -4967,12 +4975,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册