aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/crypto_key.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2015-05-18 13:16:47 -0400
committerTheodore Ts'o <tytso@mit.edu>2015-05-18 13:16:47 -0400
commite2881b1b51d871a72911faf2fc7e090655940506 (patch)
tree07bc66d72cc03479c98b7b63edb53f1fa4069383 /fs/ext4/crypto_key.c
parentd229959072eba40e1c2a4f53f8af17f1e770eb66 (diff)
ext4 crypto: separate kernel and userspace structure for the key
Use struct ext4_encryption_key only for the master key passed via the kernel keyring. For internal kernel space users, we now use struct ext4_crypt_info. This will allow us to put information from the policy structure so we can cache it and avoid needing to constantly looking up the extended attribute. We will do this in a spearate patch. This patch is mostly mechnical to make it easier for patch review. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/crypto_key.c')
-rw-r--r--fs/ext4/crypto_key.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
index 52170d0b7c40..ec6635dc50f9 100644
--- a/fs/ext4/crypto_key.c
+++ b/fs/ext4/crypto_key.c
@@ -91,7 +91,7 @@ out:
91int ext4_generate_encryption_key(struct inode *inode) 91int ext4_generate_encryption_key(struct inode *inode)
92{ 92{
93 struct ext4_inode_info *ei = EXT4_I(inode); 93 struct ext4_inode_info *ei = EXT4_I(inode);
94 struct ext4_encryption_key *crypt_key = &ei->i_encryption_key; 94 struct ext4_crypt_info *crypt_info = &ei->i_crypt_info;
95 char full_key_descriptor[EXT4_KEY_DESC_PREFIX_SIZE + 95 char full_key_descriptor[EXT4_KEY_DESC_PREFIX_SIZE +
96 (EXT4_KEY_DESCRIPTOR_SIZE * 2) + 1]; 96 (EXT4_KEY_DESCRIPTOR_SIZE * 2) + 1];
97 struct key *keyring_key = NULL; 97 struct key *keyring_key = NULL;
@@ -112,17 +112,17 @@ int ext4_generate_encryption_key(struct inode *inode)
112 112
113 ei->i_crypt_policy_flags = ctx.flags; 113 ei->i_crypt_policy_flags = ctx.flags;
114 if (S_ISREG(inode->i_mode)) 114 if (S_ISREG(inode->i_mode))
115 crypt_key->mode = ctx.contents_encryption_mode; 115 crypt_info->ci_mode = ctx.contents_encryption_mode;
116 else if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) 116 else if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
117 crypt_key->mode = ctx.filenames_encryption_mode; 117 crypt_info->ci_mode = ctx.filenames_encryption_mode;
118 else { 118 else {
119 printk(KERN_ERR "ext4 crypto: Unsupported inode type.\n"); 119 printk(KERN_ERR "ext4 crypto: Unsupported inode type.\n");
120 BUG(); 120 BUG();
121 } 121 }
122 crypt_key->size = ext4_encryption_key_size(crypt_key->mode); 122 crypt_info->ci_size = ext4_encryption_key_size(crypt_info->ci_mode);
123 BUG_ON(!crypt_key->size); 123 BUG_ON(!crypt_info->ci_size);
124 if (DUMMY_ENCRYPTION_ENABLED(sbi)) { 124 if (DUMMY_ENCRYPTION_ENABLED(sbi)) {
125 memset(crypt_key->raw, 0x42, EXT4_AES_256_XTS_KEY_SIZE); 125 memset(crypt_info->ci_raw, 0x42, EXT4_AES_256_XTS_KEY_SIZE);
126 goto out; 126 goto out;
127 } 127 }
128 memcpy(full_key_descriptor, EXT4_KEY_DESC_PREFIX, 128 memcpy(full_key_descriptor, EXT4_KEY_DESC_PREFIX,
@@ -148,19 +148,20 @@ int ext4_generate_encryption_key(struct inode *inode)
148 BUILD_BUG_ON(EXT4_AES_128_ECB_KEY_SIZE != 148 BUILD_BUG_ON(EXT4_AES_128_ECB_KEY_SIZE !=
149 EXT4_KEY_DERIVATION_NONCE_SIZE); 149 EXT4_KEY_DERIVATION_NONCE_SIZE);
150 BUG_ON(master_key->size != EXT4_AES_256_XTS_KEY_SIZE); 150 BUG_ON(master_key->size != EXT4_AES_256_XTS_KEY_SIZE);
151 res = ext4_derive_key_aes(ctx.nonce, master_key->raw, crypt_key->raw); 151 res = ext4_derive_key_aes(ctx.nonce, master_key->raw,
152 crypt_info->ci_raw);
152out: 153out:
153 if (keyring_key) 154 if (keyring_key)
154 key_put(keyring_key); 155 key_put(keyring_key);
155 if (res < 0) 156 if (res < 0)
156 crypt_key->mode = EXT4_ENCRYPTION_MODE_INVALID; 157 crypt_info->ci_mode = EXT4_ENCRYPTION_MODE_INVALID;
157 return res; 158 return res;
158} 159}
159 160
160int ext4_has_encryption_key(struct inode *inode) 161int ext4_has_encryption_key(struct inode *inode)
161{ 162{
162 struct ext4_inode_info *ei = EXT4_I(inode); 163 struct ext4_inode_info *ei = EXT4_I(inode);
163 struct ext4_encryption_key *crypt_key = &ei->i_encryption_key; 164 struct ext4_crypt_info *crypt_info = &ei->i_crypt_info;
164 165
165 return (crypt_key->mode != EXT4_ENCRYPTION_MODE_INVALID); 166 return (crypt_info->ci_mode != EXT4_ENCRYPTION_MODE_INVALID);
166} 167}