Commit f18f9845 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux

Pull fscrypt updates from Eric Biggers:
 "Simplify the implementation of the test_dummy_encryption mount option
  by adding the 'test dummy key' on-demand"

* tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux:
  fscrypt: clean up fscrypt_add_test_dummy_key()
  fs/super.c: stop calling fscrypt_destroy_keyring() from __put_super()
  f2fs: stop calling fscrypt_add_test_dummy_key()
  ext4: stop calling fscrypt_add_test_dummy_key()
  fscrypt: add the test dummy encryption key on-demand
parents dc483c85 097d7c1f
...@@ -573,6 +573,9 @@ fscrypt_find_master_key(struct super_block *sb, ...@@ -573,6 +573,9 @@ fscrypt_find_master_key(struct super_block *sb,
int fscrypt_get_test_dummy_key_identifier( int fscrypt_get_test_dummy_key_identifier(
u8 key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]); u8 key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
int fscrypt_add_test_dummy_key(struct super_block *sb,
struct fscrypt_key_specifier *key_spec);
int fscrypt_verify_key_added(struct super_block *sb, int fscrypt_verify_key_added(struct super_block *sb,
const u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]); const u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]);
...@@ -651,6 +654,7 @@ bool fscrypt_policies_equal(const union fscrypt_policy *policy1, ...@@ -651,6 +654,7 @@ bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
const union fscrypt_policy *policy2); const union fscrypt_policy *policy2);
int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy, int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
struct fscrypt_key_specifier *key_spec); struct fscrypt_key_specifier *key_spec);
const union fscrypt_policy *fscrypt_get_dummy_policy(struct super_block *sb);
bool fscrypt_supported_policy(const union fscrypt_policy *policy_u, bool fscrypt_supported_policy(const union fscrypt_policy *policy_u,
const struct inode *inode); const struct inode *inode);
int fscrypt_policy_from_context(union fscrypt_policy *policy_u, int fscrypt_policy_from_context(union fscrypt_policy *policy_u,
......
...@@ -211,10 +211,6 @@ static int allocate_filesystem_keyring(struct super_block *sb) ...@@ -211,10 +211,6 @@ static int allocate_filesystem_keyring(struct super_block *sb)
* are still available at this time; this is important because after user file * are still available at this time; this is important because after user file
* accesses have been allowed, this function may need to evict keys from the * accesses have been allowed, this function may need to evict keys from the
* keyslots of an inline crypto engine, which requires the block device(s). * keyslots of an inline crypto engine, which requires the block device(s).
*
* This is also called when the super_block is being freed. This is needed to
* avoid a memory leak if mounting fails after the "test_dummy_encryption"
* option was processed, as in that case the unmount-time call isn't made.
*/ */
void fscrypt_destroy_keyring(struct super_block *sb) void fscrypt_destroy_keyring(struct super_block *sb)
{ {
...@@ -778,34 +774,26 @@ int fscrypt_get_test_dummy_key_identifier( ...@@ -778,34 +774,26 @@ int fscrypt_get_test_dummy_key_identifier(
/** /**
* fscrypt_add_test_dummy_key() - add the test dummy encryption key * fscrypt_add_test_dummy_key() - add the test dummy encryption key
* @sb: the filesystem instance to add the key to * @sb: the filesystem instance to add the key to
* @dummy_policy: the encryption policy for test_dummy_encryption * @key_spec: the key specifier of the test dummy encryption key
* *
* If needed, add the key for the test_dummy_encryption mount option to the * Add the key for the test_dummy_encryption mount option to the filesystem. To
* filesystem. To prevent misuse of this mount option, a per-boot random key is * prevent misuse of this mount option, a per-boot random key is used instead of
* used instead of a hardcoded one. This makes it so that any encrypted files * a hardcoded one. This makes it so that any encrypted files created using
* created using this option won't be accessible after a reboot. * this option won't be accessible after a reboot.
* *
* Return: 0 on success, -errno on failure * Return: 0 on success, -errno on failure
*/ */
int fscrypt_add_test_dummy_key(struct super_block *sb, int fscrypt_add_test_dummy_key(struct super_block *sb,
const struct fscrypt_dummy_policy *dummy_policy) struct fscrypt_key_specifier *key_spec)
{ {
const union fscrypt_policy *policy = dummy_policy->policy;
struct fscrypt_key_specifier key_spec;
struct fscrypt_master_key_secret secret; struct fscrypt_master_key_secret secret;
int err; int err;
if (!policy)
return 0;
err = fscrypt_policy_to_key_spec(policy, &key_spec);
if (err)
return err;
fscrypt_get_test_dummy_secret(&secret); fscrypt_get_test_dummy_secret(&secret);
err = add_master_key(sb, &secret, &key_spec); err = add_master_key(sb, &secret, key_spec);
wipe_master_key_secret(&secret); wipe_master_key_secret(&secret);
return err; return err;
} }
EXPORT_SYMBOL_GPL(fscrypt_add_test_dummy_key);
/* /*
* Verify that the current user has added a master key with the given identifier * Verify that the current user has added a master key with the given identifier
......
...@@ -438,6 +438,7 @@ static int setup_file_encryption_key(struct fscrypt_info *ci, ...@@ -438,6 +438,7 @@ static int setup_file_encryption_key(struct fscrypt_info *ci,
bool need_dirhash_key, bool need_dirhash_key,
struct fscrypt_master_key **mk_ret) struct fscrypt_master_key **mk_ret)
{ {
struct super_block *sb = ci->ci_inode->i_sb;
struct fscrypt_key_specifier mk_spec; struct fscrypt_key_specifier mk_spec;
struct fscrypt_master_key *mk; struct fscrypt_master_key *mk;
int err; int err;
...@@ -450,8 +451,26 @@ static int setup_file_encryption_key(struct fscrypt_info *ci, ...@@ -450,8 +451,26 @@ static int setup_file_encryption_key(struct fscrypt_info *ci,
if (err) if (err)
return err; return err;
mk = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec); mk = fscrypt_find_master_key(sb, &mk_spec);
if (!mk) { if (unlikely(!mk)) {
const union fscrypt_policy *dummy_policy =
fscrypt_get_dummy_policy(sb);
/*
* Add the test_dummy_encryption key on-demand. In principle,
* it should be added at mount time. Do it here instead so that
* the individual filesystems don't need to worry about adding
* this key at mount time and cleaning up on mount failure.
*/
if (dummy_policy &&
fscrypt_policies_equal(dummy_policy, &ci->ci_policy)) {
err = fscrypt_add_test_dummy_key(sb, &mk_spec);
if (err)
return err;
mk = fscrypt_find_master_key(sb, &mk_spec);
}
}
if (unlikely(!mk)) {
if (ci->ci_policy.version != FSCRYPT_POLICY_V1) if (ci->ci_policy.version != FSCRYPT_POLICY_V1)
return -ENOKEY; return -ENOKEY;
......
...@@ -53,8 +53,7 @@ int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy, ...@@ -53,8 +53,7 @@ int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
} }
} }
static const union fscrypt_policy * const union fscrypt_policy *fscrypt_get_dummy_policy(struct super_block *sb)
fscrypt_get_dummy_policy(struct super_block *sb)
{ {
if (!sb->s_cop->get_dummy_policy) if (!sb->s_cop->get_dummy_policy)
return NULL; return NULL;
......
...@@ -2635,7 +2635,6 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc, ...@@ -2635,7 +2635,6 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc,
{ {
const struct ext4_fs_context *ctx = fc->fs_private; const struct ext4_fs_context *ctx = fc->fs_private;
const struct ext4_sb_info *sbi = EXT4_SB(sb); const struct ext4_sb_info *sbi = EXT4_SB(sb);
int err;
if (!fscrypt_is_dummy_policy_set(&ctx->dummy_enc_policy)) if (!fscrypt_is_dummy_policy_set(&ctx->dummy_enc_policy))
return 0; return 0;
...@@ -2668,17 +2667,7 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc, ...@@ -2668,17 +2667,7 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc,
"Conflicting test_dummy_encryption options"); "Conflicting test_dummy_encryption options");
return -EINVAL; return -EINVAL;
} }
/* return 0;
* fscrypt_add_test_dummy_key() technically changes the super_block, so
* technically it should be delayed until ext4_apply_options() like the
* other changes. But since we never get here for remounts (see above),
* and this is the last chance to report errors, we do it here.
*/
err = fscrypt_add_test_dummy_key(sb, &ctx->dummy_enc_policy);
if (err)
ext4_msg(NULL, KERN_WARNING,
"Error adding test dummy encryption key [%d]", err);
return err;
} }
static void ext4_apply_test_dummy_encryption(struct ext4_fs_context *ctx, static void ext4_apply_test_dummy_encryption(struct ext4_fs_context *ctx,
......
...@@ -540,12 +540,6 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb, ...@@ -540,12 +540,6 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb,
opt, err); opt, err);
return -EINVAL; return -EINVAL;
} }
err = fscrypt_add_test_dummy_key(sb, policy);
if (err) {
f2fs_warn(sbi, "Error adding test dummy encryption key [%d]",
err);
return err;
}
f2fs_warn(sbi, "Test dummy encryption mode enabled"); f2fs_warn(sbi, "Test dummy encryption mode enabled");
return 0; return 0;
} }
......
...@@ -291,7 +291,6 @@ static void __put_super(struct super_block *s) ...@@ -291,7 +291,6 @@ static void __put_super(struct super_block *s)
WARN_ON(s->s_inode_lru.node); WARN_ON(s->s_inode_lru.node);
WARN_ON(!list_empty(&s->s_mounts)); WARN_ON(!list_empty(&s->s_mounts));
security_sb_free(s); security_sb_free(s);
fscrypt_destroy_keyring(s);
put_user_ns(s->s_user_ns); put_user_ns(s->s_user_ns);
kfree(s->s_subtype); kfree(s->s_subtype);
call_rcu(&s->rcu, destroy_super_rcu); call_rcu(&s->rcu, destroy_super_rcu);
......
...@@ -309,8 +309,6 @@ fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy) ...@@ -309,8 +309,6 @@ fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
/* keyring.c */ /* keyring.c */
void fscrypt_destroy_keyring(struct super_block *sb); void fscrypt_destroy_keyring(struct super_block *sb);
int fscrypt_ioctl_add_key(struct file *filp, void __user *arg); int fscrypt_ioctl_add_key(struct file *filp, void __user *arg);
int fscrypt_add_test_dummy_key(struct super_block *sb,
const struct fscrypt_dummy_policy *dummy_policy);
int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg); int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg);
int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg); int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg);
int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg); int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg);
...@@ -530,13 +528,6 @@ static inline int fscrypt_ioctl_add_key(struct file *filp, void __user *arg) ...@@ -530,13 +528,6 @@ static inline int fscrypt_ioctl_add_key(struct file *filp, void __user *arg)
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int
fscrypt_add_test_dummy_key(struct super_block *sb,
const struct fscrypt_dummy_policy *dummy_policy)
{
return 0;
}
static inline int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg) static inline int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
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