aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/crypto_policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/crypto_policy.c')
-rw-r--r--fs/ext4/crypto_policy.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/fs/ext4/crypto_policy.c b/fs/ext4/crypto_policy.c
index 30eaf9e9864a..a6d6291aea16 100644
--- a/fs/ext4/crypto_policy.c
+++ b/fs/ext4/crypto_policy.c
@@ -37,6 +37,8 @@ static int ext4_is_encryption_context_consistent_with_policy(
37 return 0; 37 return 0;
38 return (memcmp(ctx.master_key_descriptor, policy->master_key_descriptor, 38 return (memcmp(ctx.master_key_descriptor, policy->master_key_descriptor,
39 EXT4_KEY_DESCRIPTOR_SIZE) == 0 && 39 EXT4_KEY_DESCRIPTOR_SIZE) == 0 &&
40 (ctx.flags ==
41 policy->flags) &&
40 (ctx.contents_encryption_mode == 42 (ctx.contents_encryption_mode ==
41 policy->contents_encryption_mode) && 43 policy->contents_encryption_mode) &&
42 (ctx.filenames_encryption_mode == 44 (ctx.filenames_encryption_mode ==
@@ -56,25 +58,25 @@ static int ext4_create_encryption_context_from_policy(
56 printk(KERN_WARNING 58 printk(KERN_WARNING
57 "%s: Invalid contents encryption mode %d\n", __func__, 59 "%s: Invalid contents encryption mode %d\n", __func__,
58 policy->contents_encryption_mode); 60 policy->contents_encryption_mode);
59 res = -EINVAL; 61 return -EINVAL;
60 goto out;
61 } 62 }
62 if (!ext4_valid_filenames_enc_mode(policy->filenames_encryption_mode)) { 63 if (!ext4_valid_filenames_enc_mode(policy->filenames_encryption_mode)) {
63 printk(KERN_WARNING 64 printk(KERN_WARNING
64 "%s: Invalid filenames encryption mode %d\n", __func__, 65 "%s: Invalid filenames encryption mode %d\n", __func__,
65 policy->filenames_encryption_mode); 66 policy->filenames_encryption_mode);
66 res = -EINVAL; 67 return -EINVAL;
67 goto out;
68 } 68 }
69 if (policy->flags & ~EXT4_POLICY_FLAGS_VALID)
70 return -EINVAL;
69 ctx.contents_encryption_mode = policy->contents_encryption_mode; 71 ctx.contents_encryption_mode = policy->contents_encryption_mode;
70 ctx.filenames_encryption_mode = policy->filenames_encryption_mode; 72 ctx.filenames_encryption_mode = policy->filenames_encryption_mode;
73 ctx.flags = policy->flags;
71 BUILD_BUG_ON(sizeof(ctx.nonce) != EXT4_KEY_DERIVATION_NONCE_SIZE); 74 BUILD_BUG_ON(sizeof(ctx.nonce) != EXT4_KEY_DERIVATION_NONCE_SIZE);
72 get_random_bytes(ctx.nonce, EXT4_KEY_DERIVATION_NONCE_SIZE); 75 get_random_bytes(ctx.nonce, EXT4_KEY_DERIVATION_NONCE_SIZE);
73 76
74 res = ext4_xattr_set(inode, EXT4_XATTR_INDEX_ENCRYPTION, 77 res = ext4_xattr_set(inode, EXT4_XATTR_INDEX_ENCRYPTION,
75 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, &ctx, 78 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, &ctx,
76 sizeof(ctx), 0); 79 sizeof(ctx), 0);
77out:
78 if (!res) 80 if (!res)
79 ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT); 81 ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
80 return res; 82 return res;
@@ -115,6 +117,7 @@ int ext4_get_policy(struct inode *inode, struct ext4_encryption_policy *policy)
115 policy->version = 0; 117 policy->version = 0;
116 policy->contents_encryption_mode = ctx.contents_encryption_mode; 118 policy->contents_encryption_mode = ctx.contents_encryption_mode;
117 policy->filenames_encryption_mode = ctx.filenames_encryption_mode; 119 policy->filenames_encryption_mode = ctx.filenames_encryption_mode;
120 policy->flags = ctx.flags;
118 memcpy(&policy->master_key_descriptor, ctx.master_key_descriptor, 121 memcpy(&policy->master_key_descriptor, ctx.master_key_descriptor,
119 EXT4_KEY_DESCRIPTOR_SIZE); 122 EXT4_KEY_DESCRIPTOR_SIZE);
120 return 0; 123 return 0;
@@ -176,6 +179,7 @@ int ext4_inherit_context(struct inode *parent, struct inode *child)
176 EXT4_ENCRYPTION_MODE_AES_256_XTS; 179 EXT4_ENCRYPTION_MODE_AES_256_XTS;
177 ctx.filenames_encryption_mode = 180 ctx.filenames_encryption_mode =
178 EXT4_ENCRYPTION_MODE_AES_256_CTS; 181 EXT4_ENCRYPTION_MODE_AES_256_CTS;
182 ctx.flags = 0;
179 memset(ctx.master_key_descriptor, 0x42, 183 memset(ctx.master_key_descriptor, 0x42,
180 EXT4_KEY_DESCRIPTOR_SIZE); 184 EXT4_KEY_DESCRIPTOR_SIZE);
181 res = 0; 185 res = 0;