blob: eede186b04ce3b274b8cb7b9d9afdf8e1e45c7cc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07002/*
Eric Biggers3ec4f2a62019-08-04 19:35:45 -07003 * Key setup facility for FS encryption support.
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07004 *
5 * Copyright (C) 2015, Google, Inc.
6 *
Eric Biggers3ec4f2a62019-08-04 19:35:45 -07007 * Originally written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar.
8 * Heavily modified since then.
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07009 */
10
Eric Biggersa5757842018-01-05 10:45:00 -080011#include <crypto/skcipher.h>
Eric Biggers0109ce762019-08-04 19:35:45 -070012#include <linux/key.h>
Eric Biggersa992b202020-09-16 21:11:24 -070013#include <linux/random.h>
Eric Biggers0109ce762019-08-04 19:35:45 -070014
Theodore Ts'o3325bea2016-11-26 20:32:46 -050015#include "fscrypt_private.h"
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070016
Eric Biggers85af90e2019-12-09 13:18:27 -080017struct fscrypt_mode fscrypt_modes[] = {
Eric Biggers3b6df592019-08-04 19:35:44 -070018 [FSCRYPT_MODE_AES_256_XTS] = {
Eric Biggerse1cc40e2018-05-18 10:58:14 -070019 .friendly_name = "AES-256-XTS",
20 .cipher_str = "xts(aes)",
21 .keysize = 64,
Eric Biggers7f595d62021-09-20 20:03:03 -070022 .security_strength = 32,
Eric Biggers8094c3c2019-01-06 08:36:21 -050023 .ivsize = 16,
Satya Tangirala5fee3602020-07-02 01:56:05 +000024 .blk_crypto_mode = BLK_ENCRYPTION_MODE_AES_256_XTS,
Eric Biggerse1cc40e2018-05-18 10:58:14 -070025 },
Eric Biggers3b6df592019-08-04 19:35:44 -070026 [FSCRYPT_MODE_AES_256_CTS] = {
Eric Biggerse1cc40e2018-05-18 10:58:14 -070027 .friendly_name = "AES-256-CTS-CBC",
28 .cipher_str = "cts(cbc(aes))",
29 .keysize = 32,
Eric Biggers7f595d62021-09-20 20:03:03 -070030 .security_strength = 32,
Eric Biggers8094c3c2019-01-06 08:36:21 -050031 .ivsize = 16,
Eric Biggerse1cc40e2018-05-18 10:58:14 -070032 },
Eric Biggers3b6df592019-08-04 19:35:44 -070033 [FSCRYPT_MODE_AES_128_CBC] = {
Eric Biggers4006d792019-10-09 16:34:16 -070034 .friendly_name = "AES-128-CBC-ESSIV",
35 .cipher_str = "essiv(cbc(aes),sha256)",
Eric Biggerse1cc40e2018-05-18 10:58:14 -070036 .keysize = 16,
Eric Biggers7f595d62021-09-20 20:03:03 -070037 .security_strength = 16,
Eric Biggers8094c3c2019-01-06 08:36:21 -050038 .ivsize = 16,
Satya Tangirala5fee3602020-07-02 01:56:05 +000039 .blk_crypto_mode = BLK_ENCRYPTION_MODE_AES_128_CBC_ESSIV,
Eric Biggerse1cc40e2018-05-18 10:58:14 -070040 },
Eric Biggers3b6df592019-08-04 19:35:44 -070041 [FSCRYPT_MODE_AES_128_CTS] = {
Eric Biggerse1cc40e2018-05-18 10:58:14 -070042 .friendly_name = "AES-128-CTS-CBC",
43 .cipher_str = "cts(cbc(aes))",
44 .keysize = 16,
Eric Biggers7f595d62021-09-20 20:03:03 -070045 .security_strength = 16,
Eric Biggers8094c3c2019-01-06 08:36:21 -050046 .ivsize = 16,
47 },
Eric Biggers3b6df592019-08-04 19:35:44 -070048 [FSCRYPT_MODE_ADIANTUM] = {
Eric Biggers8094c3c2019-01-06 08:36:21 -050049 .friendly_name = "Adiantum",
50 .cipher_str = "adiantum(xchacha12,aes)",
51 .keysize = 32,
Eric Biggers7f595d62021-09-20 20:03:03 -070052 .security_strength = 32,
Eric Biggers8094c3c2019-01-06 08:36:21 -050053 .ivsize = 32,
Satya Tangirala5fee3602020-07-02 01:56:05 +000054 .blk_crypto_mode = BLK_ENCRYPTION_MODE_ADIANTUM,
Eric Biggerse1cc40e2018-05-18 10:58:14 -070055 },
Daniel Walterb7e7cf72017-06-19 09:27:58 +020056};
57
Eric Biggerse3b10782020-05-15 13:41:41 -070058static DEFINE_MUTEX(fscrypt_mode_key_setup_mutex);
59
Eric Biggerse1cc40e2018-05-18 10:58:14 -070060static struct fscrypt_mode *
Eric Biggers5dae4602019-08-04 19:35:47 -070061select_encryption_mode(const union fscrypt_policy *policy,
62 const struct inode *inode)
Eric Biggers8f398502016-09-15 13:32:11 -040063{
Eric Biggers3ceb6542020-10-23 17:51:31 -070064 BUILD_BUG_ON(ARRAY_SIZE(fscrypt_modes) != FSCRYPT_MODE_MAX + 1);
65
Eric Biggerse1cc40e2018-05-18 10:58:14 -070066 if (S_ISREG(inode->i_mode))
Eric Biggers85af90e2019-12-09 13:18:27 -080067 return &fscrypt_modes[fscrypt_policy_contents_mode(policy)];
Eric Biggers8f398502016-09-15 13:32:11 -040068
Eric Biggerse1cc40e2018-05-18 10:58:14 -070069 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
Eric Biggers85af90e2019-12-09 13:18:27 -080070 return &fscrypt_modes[fscrypt_policy_fnames_mode(policy)];
Eric Biggerse1cc40e2018-05-18 10:58:14 -070071
72 WARN_ONCE(1, "fscrypt: filesystem tried to load encryption info for inode %lu, which is not encryptable (file type %d)\n",
73 inode->i_ino, (inode->i_mode & S_IFMT));
74 return ERR_PTR(-EINVAL);
Eric Biggers8f398502016-09-15 13:32:11 -040075}
76
Eric Biggers3ec4f2a62019-08-04 19:35:45 -070077/* Create a symmetric cipher object for the given encryption mode and key */
Satya Tangirala5fee3602020-07-02 01:56:05 +000078static struct crypto_skcipher *
79fscrypt_allocate_skcipher(struct fscrypt_mode *mode, const u8 *raw_key,
80 const struct inode *inode)
Eric Biggers8094c3c2019-01-06 08:36:21 -050081{
82 struct crypto_skcipher *tfm;
83 int err;
84
85 tfm = crypto_alloc_skcipher(mode->cipher_str, 0, 0);
86 if (IS_ERR(tfm)) {
Eric Biggers29a98c12019-07-24 11:08:00 -070087 if (PTR_ERR(tfm) == -ENOENT) {
Eric Biggersa4d14e92019-07-24 11:07:59 -070088 fscrypt_warn(inode,
89 "Missing crypto API support for %s (API name: \"%s\")",
90 mode->friendly_name, mode->cipher_str);
Eric Biggers29a98c12019-07-24 11:08:00 -070091 return ERR_PTR(-ENOPKG);
92 }
93 fscrypt_err(inode, "Error allocating '%s' transform: %ld",
94 mode->cipher_str, PTR_ERR(tfm));
Eric Biggers8094c3c2019-01-06 08:36:21 -050095 return tfm;
96 }
Eric Biggersff73c2c2019-10-21 13:49:03 -070097 if (!xchg(&mode->logged_impl_name, 1)) {
Eric Biggers8094c3c2019-01-06 08:36:21 -050098 /*
99 * fscrypt performance can vary greatly depending on which
100 * crypto algorithm implementation is used. Help people debug
101 * performance problems by logging the ->cra_driver_name the
Eric Biggersff73c2c2019-10-21 13:49:03 -0700102 * first time a mode is used.
Eric Biggers8094c3c2019-01-06 08:36:21 -0500103 */
Eric Biggers8094c3c2019-01-06 08:36:21 -0500104 pr_info("fscrypt: %s using implementation \"%s\"\n",
Eric Biggers6e1adb82019-12-09 12:38:10 -0800105 mode->friendly_name, crypto_skcipher_driver_name(tfm));
Eric Biggers8094c3c2019-01-06 08:36:21 -0500106 }
Eric Biggersc64cfb92019-12-09 12:39:18 -0800107 if (WARN_ON(crypto_skcipher_ivsize(tfm) != mode->ivsize)) {
108 err = -EINVAL;
109 goto err_free_tfm;
110 }
Eric Biggers231baec2019-01-18 22:48:00 -0800111 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Eric Biggers8094c3c2019-01-06 08:36:21 -0500112 err = crypto_skcipher_setkey(tfm, raw_key, mode->keysize);
113 if (err)
114 goto err_free_tfm;
115
116 return tfm;
117
118err_free_tfm:
119 crypto_free_skcipher(tfm);
120 return ERR_PTR(err);
121}
122
Satya Tangirala5fee3602020-07-02 01:56:05 +0000123/*
124 * Prepare the crypto transform object or blk-crypto key in @prep_key, given the
Eric Biggersb7e072f2021-10-25 19:10:42 -0700125 * raw key, encryption mode (@ci->ci_mode), flag indicating which encryption
126 * implementation (fs-layer or blk-crypto) will be used (@ci->ci_inlinecrypt),
127 * and IV generation method (@ci->ci_policy.flags).
Satya Tangirala5fee3602020-07-02 01:56:05 +0000128 */
129int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key,
130 const u8 *raw_key, const struct fscrypt_info *ci)
Eric Biggers8094c3c2019-01-06 08:36:21 -0500131{
Eric Biggers4006d792019-10-09 16:34:16 -0700132 struct crypto_skcipher *tfm;
Eric Biggers8094c3c2019-01-06 08:36:21 -0500133
Satya Tangirala5fee3602020-07-02 01:56:05 +0000134 if (fscrypt_using_inline_encryption(ci))
135 return fscrypt_prepare_inline_crypt_key(prep_key, raw_key, ci);
136
Eric Biggersf592efe2020-01-20 14:31:58 -0800137 tfm = fscrypt_allocate_skcipher(ci->ci_mode, raw_key, ci->ci_inode);
Eric Biggers4006d792019-10-09 16:34:16 -0700138 if (IS_ERR(tfm))
139 return PTR_ERR(tfm);
Satya Tangirala5fee3602020-07-02 01:56:05 +0000140 /*
Eric Biggers97c63272020-07-21 15:59:17 -0700141 * Pairs with the smp_load_acquire() in fscrypt_is_key_prepared().
142 * I.e., here we publish ->tfm with a RELEASE barrier so that
143 * concurrent tasks can ACQUIRE it. Note that this concurrency is only
144 * possible for per-mode keys, not for per-file keys.
Satya Tangirala5fee3602020-07-02 01:56:05 +0000145 */
146 smp_store_release(&prep_key->tfm, tfm);
Eric Biggers8094c3c2019-01-06 08:36:21 -0500147 return 0;
148}
149
Satya Tangirala5fee3602020-07-02 01:56:05 +0000150/* Destroy a crypto transform object and/or blk-crypto key. */
151void fscrypt_destroy_prepared_key(struct fscrypt_prepared_key *prep_key)
152{
153 crypto_free_skcipher(prep_key->tfm);
154 fscrypt_destroy_inline_crypt_key(prep_key);
155}
156
157/* Given a per-file encryption key, set up the file's crypto transform object */
158int fscrypt_set_per_file_enc_key(struct fscrypt_info *ci, const u8 *raw_key)
159{
160 ci->ci_owns_key = true;
161 return fscrypt_prepare_key(&ci->ci_enc_key, raw_key, ci);
162}
163
Eric Biggersf592efe2020-01-20 14:31:58 -0800164static int setup_per_mode_enc_key(struct fscrypt_info *ci,
165 struct fscrypt_master_key *mk,
Satya Tangirala5fee3602020-07-02 01:56:05 +0000166 struct fscrypt_prepared_key *keys,
Eric Biggersf592efe2020-01-20 14:31:58 -0800167 u8 hkdf_context, bool include_fs_uuid)
Eric Biggers5dae4602019-08-04 19:35:47 -0700168{
Eric Biggersb103fb72019-10-24 14:54:36 -0700169 const struct inode *inode = ci->ci_inode;
170 const struct super_block *sb = inode->i_sb;
Eric Biggers5dae4602019-08-04 19:35:47 -0700171 struct fscrypt_mode *mode = ci->ci_mode;
Eric Biggers85af90e2019-12-09 13:18:27 -0800172 const u8 mode_num = mode - fscrypt_modes;
Satya Tangirala5fee3602020-07-02 01:56:05 +0000173 struct fscrypt_prepared_key *prep_key;
Eric Biggers5dae4602019-08-04 19:35:47 -0700174 u8 mode_key[FSCRYPT_MAX_KEY_SIZE];
Eric Biggersb103fb72019-10-24 14:54:36 -0700175 u8 hkdf_info[sizeof(mode_num) + sizeof(sb->s_uuid)];
176 unsigned int hkdf_infolen = 0;
Eric Biggers5dae4602019-08-04 19:35:47 -0700177 int err;
178
Eric Biggers3ceb6542020-10-23 17:51:31 -0700179 if (WARN_ON(mode_num > FSCRYPT_MODE_MAX))
Eric Biggers5dae4602019-08-04 19:35:47 -0700180 return -EINVAL;
181
Satya Tangirala5fee3602020-07-02 01:56:05 +0000182 prep_key = &keys[mode_num];
183 if (fscrypt_is_key_prepared(prep_key, ci)) {
184 ci->ci_enc_key = *prep_key;
Eric Biggerse3b10782020-05-15 13:41:41 -0700185 return 0;
186 }
187
188 mutex_lock(&fscrypt_mode_key_setup_mutex);
189
Satya Tangirala5fee3602020-07-02 01:56:05 +0000190 if (fscrypt_is_key_prepared(prep_key, ci))
Eric Biggerse3b10782020-05-15 13:41:41 -0700191 goto done_unlock;
Eric Biggers5dae4602019-08-04 19:35:47 -0700192
193 BUILD_BUG_ON(sizeof(mode_num) != 1);
Eric Biggersb103fb72019-10-24 14:54:36 -0700194 BUILD_BUG_ON(sizeof(sb->s_uuid) != 16);
195 BUILD_BUG_ON(sizeof(hkdf_info) != 17);
196 hkdf_info[hkdf_infolen++] = mode_num;
197 if (include_fs_uuid) {
198 memcpy(&hkdf_info[hkdf_infolen], &sb->s_uuid,
199 sizeof(sb->s_uuid));
200 hkdf_infolen += sizeof(sb->s_uuid);
201 }
Eric Biggers5dae4602019-08-04 19:35:47 -0700202 err = fscrypt_hkdf_expand(&mk->mk_secret.hkdf,
Eric Biggersb103fb72019-10-24 14:54:36 -0700203 hkdf_context, hkdf_info, hkdf_infolen,
Eric Biggers5dae4602019-08-04 19:35:47 -0700204 mode_key, mode->keysize);
205 if (err)
Eric Biggerse3b10782020-05-15 13:41:41 -0700206 goto out_unlock;
Satya Tangirala5fee3602020-07-02 01:56:05 +0000207 err = fscrypt_prepare_key(prep_key, mode_key, ci);
Eric Biggers5dae4602019-08-04 19:35:47 -0700208 memzero_explicit(mode_key, mode->keysize);
Satya Tangirala5fee3602020-07-02 01:56:05 +0000209 if (err)
Eric Biggerse3b10782020-05-15 13:41:41 -0700210 goto out_unlock;
Eric Biggerse3b10782020-05-15 13:41:41 -0700211done_unlock:
Satya Tangirala5fee3602020-07-02 01:56:05 +0000212 ci->ci_enc_key = *prep_key;
Eric Biggerse3b10782020-05-15 13:41:41 -0700213 err = 0;
214out_unlock:
215 mutex_unlock(&fscrypt_mode_key_setup_mutex);
216 return err;
Eric Biggers5dae4602019-08-04 19:35:47 -0700217}
218
Eric Biggers2fc2b432021-06-05 00:50:33 -0700219/*
220 * Derive a SipHash key from the given fscrypt master key and the given
221 * application-specific information string.
222 *
223 * Note that the KDF produces a byte array, but the SipHash APIs expect the key
224 * as a pair of 64-bit words. Therefore, on big endian CPUs we have to do an
225 * endianness swap in order to get the same results as on little endian CPUs.
226 */
227static int fscrypt_derive_siphash_key(const struct fscrypt_master_key *mk,
228 u8 context, const u8 *info,
229 unsigned int infolen, siphash_key_t *key)
230{
231 int err;
232
233 err = fscrypt_hkdf_expand(&mk->mk_secret.hkdf, context, info, infolen,
234 (u8 *)key, sizeof(*key));
235 if (err)
236 return err;
237
238 BUILD_BUG_ON(sizeof(*key) != 16);
239 BUILD_BUG_ON(ARRAY_SIZE(key->key) != 2);
240 le64_to_cpus(&key->key[0]);
241 le64_to_cpus(&key->key[1]);
242 return 0;
243}
244
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800245int fscrypt_derive_dirhash_key(struct fscrypt_info *ci,
246 const struct fscrypt_master_key *mk)
247{
248 int err;
249
Eric Biggers2fc2b432021-06-05 00:50:33 -0700250 err = fscrypt_derive_siphash_key(mk, HKDF_CONTEXT_DIRHASH_KEY,
251 ci->ci_nonce, FSCRYPT_FILE_NONCE_SIZE,
252 &ci->ci_dirhash_key);
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800253 if (err)
254 return err;
255 ci->ci_dirhash_key_initialized = true;
256 return 0;
257}
258
Eric Biggersa992b202020-09-16 21:11:24 -0700259void fscrypt_hash_inode_number(struct fscrypt_info *ci,
260 const struct fscrypt_master_key *mk)
261{
262 WARN_ON(ci->ci_inode->i_ino == 0);
263 WARN_ON(!mk->mk_ino_hash_key_initialized);
264
265 ci->ci_hashed_ino = (u32)siphash_1u64(ci->ci_inode->i_ino,
266 &mk->mk_ino_hash_key);
267}
268
Eric Biggerse3b10782020-05-15 13:41:41 -0700269static int fscrypt_setup_iv_ino_lblk_32_key(struct fscrypt_info *ci,
270 struct fscrypt_master_key *mk)
271{
272 int err;
273
274 err = setup_per_mode_enc_key(ci, mk, mk->mk_iv_ino_lblk_32_keys,
275 HKDF_CONTEXT_IV_INO_LBLK_32_KEY, true);
276 if (err)
277 return err;
278
279 /* pairs with smp_store_release() below */
280 if (!smp_load_acquire(&mk->mk_ino_hash_key_initialized)) {
281
282 mutex_lock(&fscrypt_mode_key_setup_mutex);
283
284 if (mk->mk_ino_hash_key_initialized)
285 goto unlock;
286
Eric Biggers2fc2b432021-06-05 00:50:33 -0700287 err = fscrypt_derive_siphash_key(mk,
288 HKDF_CONTEXT_INODE_HASH_KEY,
289 NULL, 0, &mk->mk_ino_hash_key);
Eric Biggerse3b10782020-05-15 13:41:41 -0700290 if (err)
291 goto unlock;
292 /* pairs with smp_load_acquire() above */
293 smp_store_release(&mk->mk_ino_hash_key_initialized, true);
294unlock:
295 mutex_unlock(&fscrypt_mode_key_setup_mutex);
296 if (err)
297 return err;
298 }
299
Eric Biggersa992b202020-09-16 21:11:24 -0700300 /*
301 * New inodes may not have an inode number assigned yet.
302 * Hashing their inode number is delayed until later.
303 */
Eric Biggers92cfcd02020-10-30 17:45:56 -0700304 if (ci->ci_inode->i_ino)
Eric Biggersa992b202020-09-16 21:11:24 -0700305 fscrypt_hash_inode_number(ci, mk);
Eric Biggerse3b10782020-05-15 13:41:41 -0700306 return 0;
307}
308
Eric Biggers5dae4602019-08-04 19:35:47 -0700309static int fscrypt_setup_v2_file_key(struct fscrypt_info *ci,
Eric Biggersa992b202020-09-16 21:11:24 -0700310 struct fscrypt_master_key *mk,
311 bool need_dirhash_key)
Eric Biggers5dae4602019-08-04 19:35:47 -0700312{
Eric Biggers5dae4602019-08-04 19:35:47 -0700313 int err;
314
315 if (ci->ci_policy.v2.flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) {
316 /*
Eric Biggersf592efe2020-01-20 14:31:58 -0800317 * DIRECT_KEY: instead of deriving per-file encryption keys, the
318 * per-file nonce will be included in all the IVs. But unlike
319 * v1 policies, for v2 policies in this case we don't encrypt
320 * with the master key directly but rather derive a per-mode
321 * encryption key. This ensures that the master key is
322 * consistently used only for HKDF, avoiding key reuse issues.
Eric Biggers5dae4602019-08-04 19:35:47 -0700323 */
Eric Biggerse3b10782020-05-15 13:41:41 -0700324 err = setup_per_mode_enc_key(ci, mk, mk->mk_direct_keys,
Eric Biggersf592efe2020-01-20 14:31:58 -0800325 HKDF_CONTEXT_DIRECT_KEY, false);
Eric Biggersb103fb72019-10-24 14:54:36 -0700326 } else if (ci->ci_policy.v2.flags &
327 FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) {
328 /*
329 * IV_INO_LBLK_64: encryption keys are derived from (master_key,
330 * mode_num, filesystem_uuid), and inode number is included in
331 * the IVs. This format is optimized for use with inline
Eric Biggerse3b10782020-05-15 13:41:41 -0700332 * encryption hardware compliant with the UFS standard.
Eric Biggersb103fb72019-10-24 14:54:36 -0700333 */
Eric Biggerse3b10782020-05-15 13:41:41 -0700334 err = setup_per_mode_enc_key(ci, mk, mk->mk_iv_ino_lblk_64_keys,
Eric Biggersf592efe2020-01-20 14:31:58 -0800335 HKDF_CONTEXT_IV_INO_LBLK_64_KEY,
336 true);
Eric Biggerse3b10782020-05-15 13:41:41 -0700337 } else if (ci->ci_policy.v2.flags &
338 FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) {
339 err = fscrypt_setup_iv_ino_lblk_32_key(ci, mk);
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800340 } else {
341 u8 derived_key[FSCRYPT_MAX_KEY_SIZE];
Eric Biggers5dae4602019-08-04 19:35:47 -0700342
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800343 err = fscrypt_hkdf_expand(&mk->mk_secret.hkdf,
Eric Biggersf592efe2020-01-20 14:31:58 -0800344 HKDF_CONTEXT_PER_FILE_ENC_KEY,
Eric Biggers1d6217a42020-07-08 14:57:22 -0700345 ci->ci_nonce, FSCRYPT_FILE_NONCE_SIZE,
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800346 derived_key, ci->ci_mode->keysize);
347 if (err)
348 return err;
349
Eric Biggersf592efe2020-01-20 14:31:58 -0800350 err = fscrypt_set_per_file_enc_key(ci, derived_key);
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800351 memzero_explicit(derived_key, ci->ci_mode->keysize);
352 }
Eric Biggers5dae4602019-08-04 19:35:47 -0700353 if (err)
354 return err;
355
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800356 /* Derive a secret dirhash key for directories that need it. */
Eric Biggersa992b202020-09-16 21:11:24 -0700357 if (need_dirhash_key) {
Daniel Rosenbergaa408f82020-01-20 14:31:57 -0800358 err = fscrypt_derive_dirhash_key(ci, mk);
359 if (err)
360 return err;
361 }
362
363 return 0;
Eric Biggers5dae4602019-08-04 19:35:47 -0700364}
365
Eric Biggers3ec4f2a62019-08-04 19:35:45 -0700366/*
Eric Biggers7f595d62021-09-20 20:03:03 -0700367 * Check whether the size of the given master key (@mk) is appropriate for the
368 * encryption settings which a particular file will use (@ci).
369 *
370 * If the file uses a v1 encryption policy, then the master key must be at least
371 * as long as the derived key, as this is a requirement of the v1 KDF.
372 *
373 * Otherwise, the KDF can accept any size key, so we enforce a slightly looser
374 * requirement: we require that the size of the master key be at least the
375 * maximum security strength of any algorithm whose key will be derived from it
376 * (but in practice we only need to consider @ci->ci_mode, since any other
377 * possible subkeys such as DIRHASH and INODE_HASH will never increase the
378 * required key size over @ci->ci_mode). This allows AES-256-XTS keys to be
379 * derived from a 256-bit master key, which is cryptographically sufficient,
380 * rather than requiring a 512-bit master key which is unnecessarily long. (We
381 * still allow 512-bit master keys if the user chooses to use them, though.)
382 */
383static bool fscrypt_valid_master_key_size(const struct fscrypt_master_key *mk,
384 const struct fscrypt_info *ci)
385{
386 unsigned int min_keysize;
387
388 if (ci->ci_policy.version == FSCRYPT_POLICY_V1)
389 min_keysize = ci->ci_mode->keysize;
390 else
391 min_keysize = ci->ci_mode->security_strength;
392
393 if (mk->mk_secret.size < min_keysize) {
394 fscrypt_warn(NULL,
395 "key with %s %*phN is too short (got %u bytes, need %u+ bytes)",
396 master_key_spec_type(&mk->mk_spec),
397 master_key_spec_len(&mk->mk_spec),
398 (u8 *)&mk->mk_spec.u,
399 mk->mk_secret.size, min_keysize);
400 return false;
401 }
402 return true;
403}
404
405/*
Eric Biggers3ec4f2a62019-08-04 19:35:45 -0700406 * Find the master key, then set up the inode's actual encryption key.
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700407 *
408 * If the master key is found in the filesystem-level keyring, then the
Eric Biggers4a4b8722020-11-16 19:26:26 -0800409 * corresponding 'struct key' is returned in *master_key_ret with its semaphore
410 * read-locked. This is needed to ensure that only one task links the
411 * fscrypt_info into ->mk_decrypted_inodes (as multiple tasks may race to create
412 * an fscrypt_info for the same inode), and to synchronize the master key being
413 * removed with a new inode starting to use it.
Eric Biggers3ec4f2a62019-08-04 19:35:45 -0700414 */
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700415static int setup_file_encryption_key(struct fscrypt_info *ci,
Eric Biggersa992b202020-09-16 21:11:24 -0700416 bool need_dirhash_key,
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700417 struct key **master_key_ret)
Eric Biggers3ec4f2a62019-08-04 19:35:45 -0700418{
Eric Biggers22d94f42019-08-04 19:35:46 -0700419 struct key *key;
420 struct fscrypt_master_key *mk = NULL;
421 struct fscrypt_key_specifier mk_spec;
422 int err;
423
Satya Tangirala5fee3602020-07-02 01:56:05 +0000424 err = fscrypt_select_encryption_impl(ci);
425 if (err)
426 return err;
427
Eric Biggers5dae4602019-08-04 19:35:47 -0700428 switch (ci->ci_policy.version) {
429 case FSCRYPT_POLICY_V1:
430 mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
431 memcpy(mk_spec.u.descriptor,
432 ci->ci_policy.v1.master_key_descriptor,
433 FSCRYPT_KEY_DESCRIPTOR_SIZE);
434 break;
435 case FSCRYPT_POLICY_V2:
436 mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
437 memcpy(mk_spec.u.identifier,
438 ci->ci_policy.v2.master_key_identifier,
439 FSCRYPT_KEY_IDENTIFIER_SIZE);
440 break;
441 default:
442 WARN_ON(1);
443 return -EINVAL;
444 }
Eric Biggers22d94f42019-08-04 19:35:46 -0700445
446 key = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec);
447 if (IS_ERR(key)) {
Eric Biggers5dae4602019-08-04 19:35:47 -0700448 if (key != ERR_PTR(-ENOKEY) ||
449 ci->ci_policy.version != FSCRYPT_POLICY_V1)
Eric Biggers22d94f42019-08-04 19:35:46 -0700450 return PTR_ERR(key);
451
Eric Biggers5dae4602019-08-04 19:35:47 -0700452 /*
453 * As a legacy fallback for v1 policies, search for the key in
454 * the current task's subscribed keyrings too. Don't move this
455 * to before the search of ->s_master_keys, since users
456 * shouldn't be able to override filesystem-level keys.
457 */
Eric Biggers22d94f42019-08-04 19:35:46 -0700458 return fscrypt_setup_v1_file_key_via_subscribed_keyrings(ci);
459 }
460
461 mk = key->payload.data[0];
Eric Biggers4a4b8722020-11-16 19:26:26 -0800462 down_read(&key->sem);
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700463
464 /* Has the secret been removed (via FS_IOC_REMOVE_ENCRYPTION_KEY)? */
465 if (!is_master_key_secret_present(&mk->mk_secret)) {
466 err = -ENOKEY;
467 goto out_release_key;
468 }
Eric Biggers22d94f42019-08-04 19:35:46 -0700469
Eric Biggers7f595d62021-09-20 20:03:03 -0700470 if (!fscrypt_valid_master_key_size(mk, ci)) {
Eric Biggers22d94f42019-08-04 19:35:46 -0700471 err = -ENOKEY;
472 goto out_release_key;
473 }
474
Eric Biggers5dae4602019-08-04 19:35:47 -0700475 switch (ci->ci_policy.version) {
476 case FSCRYPT_POLICY_V1:
477 err = fscrypt_setup_v1_file_key(ci, mk->mk_secret.raw);
478 break;
479 case FSCRYPT_POLICY_V2:
Eric Biggersa992b202020-09-16 21:11:24 -0700480 err = fscrypt_setup_v2_file_key(ci, mk, need_dirhash_key);
Eric Biggers5dae4602019-08-04 19:35:47 -0700481 break;
482 default:
483 WARN_ON(1);
484 err = -EINVAL;
485 break;
486 }
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700487 if (err)
488 goto out_release_key;
489
490 *master_key_ret = key;
491 return 0;
Eric Biggers22d94f42019-08-04 19:35:46 -0700492
493out_release_key:
Eric Biggers4a4b8722020-11-16 19:26:26 -0800494 up_read(&key->sem);
Eric Biggers22d94f42019-08-04 19:35:46 -0700495 key_put(key);
496 return err;
Eric Biggers3ec4f2a62019-08-04 19:35:45 -0700497}
498
Eric Biggers8094c3c2019-01-06 08:36:21 -0500499static void put_crypt_info(struct fscrypt_info *ci)
500{
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700501 struct key *key;
502
Eric Biggers8094c3c2019-01-06 08:36:21 -0500503 if (!ci)
504 return;
505
Eric Biggers4006d792019-10-09 16:34:16 -0700506 if (ci->ci_direct_key)
Eric Biggers0109ce762019-08-04 19:35:45 -0700507 fscrypt_put_direct_key(ci->ci_direct_key);
Eric Biggersb103fb72019-10-24 14:54:36 -0700508 else if (ci->ci_owns_key)
Satya Tangirala5fee3602020-07-02 01:56:05 +0000509 fscrypt_destroy_prepared_key(&ci->ci_enc_key);
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700510
511 key = ci->ci_master_key;
512 if (key) {
513 struct fscrypt_master_key *mk = key->payload.data[0];
514
515 /*
516 * Remove this inode from the list of inodes that were unlocked
517 * with the master key.
518 *
519 * In addition, if we're removing the last inode from a key that
520 * already had its secret removed, invalidate the key so that it
521 * gets removed from ->s_master_keys.
522 */
523 spin_lock(&mk->mk_decrypted_inodes_lock);
524 list_del(&ci->ci_master_key_link);
525 spin_unlock(&mk->mk_decrypted_inodes_lock);
526 if (refcount_dec_and_test(&mk->mk_refcount))
527 key_invalidate(key);
528 key_put(key);
529 }
Eric Biggers6f997562019-10-09 16:34:17 -0700530 memzero_explicit(ci, sizeof(*ci));
Eric Biggers8094c3c2019-01-06 08:36:21 -0500531 kmem_cache_free(fscrypt_info_cachep, ci);
532}
533
Eric Biggersa992b202020-09-16 21:11:24 -0700534static int
535fscrypt_setup_encryption_info(struct inode *inode,
536 const union fscrypt_policy *policy,
537 const u8 nonce[FSCRYPT_FILE_NONCE_SIZE],
538 bool need_dirhash_key)
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700539{
540 struct fscrypt_info *crypt_info;
Eric Biggerse1cc40e2018-05-18 10:58:14 -0700541 struct fscrypt_mode *mode;
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700542 struct key *master_key = NULL;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700543 int res;
544
David Gstirf32d7ac2016-12-06 23:53:57 +0100545 res = fscrypt_initialize(inode->i_sb->s_cop->flags);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700546 if (res)
547 return res;
548
Eric Biggers9dad5fe2020-09-16 21:11:32 -0700549 crypt_info = kmem_cache_zalloc(fscrypt_info_cachep, GFP_KERNEL);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700550 if (!crypt_info)
551 return -ENOMEM;
552
Eric Biggers59dc6a82019-08-04 19:35:44 -0700553 crypt_info->ci_inode = inode;
Eric Biggersa992b202020-09-16 21:11:24 -0700554 crypt_info->ci_policy = *policy;
555 memcpy(crypt_info->ci_nonce, nonce, FSCRYPT_FILE_NONCE_SIZE);
Eric Biggers5dae4602019-08-04 19:35:47 -0700556
557 mode = select_encryption_mode(&crypt_info->ci_policy, inode);
Eric Biggerse1cc40e2018-05-18 10:58:14 -0700558 if (IS_ERR(mode)) {
559 res = PTR_ERR(mode);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700560 goto out;
Eric Biggerse1cc40e2018-05-18 10:58:14 -0700561 }
Eric Biggers8094c3c2019-01-06 08:36:21 -0500562 WARN_ON(mode->ivsize > FSCRYPT_MAX_IV_SIZE);
563 crypt_info->ci_mode = mode;
Eric Biggers8f398502016-09-15 13:32:11 -0400564
Eric Biggersa992b202020-09-16 21:11:24 -0700565 res = setup_file_encryption_key(crypt_info, need_dirhash_key,
566 &master_key);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700567 if (res)
568 goto out;
569
Eric Biggersab673b92020-07-21 15:59:19 -0700570 /*
Eric Biggersa992b202020-09-16 21:11:24 -0700571 * For existing inodes, multiple tasks may race to set ->i_crypt_info.
572 * So use cmpxchg_release(). This pairs with the smp_load_acquire() in
Eric Biggersab673b92020-07-21 15:59:19 -0700573 * fscrypt_get_info(). I.e., here we publish ->i_crypt_info with a
574 * RELEASE barrier so that other tasks can ACQUIRE it.
575 */
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700576 if (cmpxchg_release(&inode->i_crypt_info, NULL, crypt_info) == NULL) {
Eric Biggersab673b92020-07-21 15:59:19 -0700577 /*
578 * We won the race and set ->i_crypt_info to our crypt_info.
579 * Now link it into the master key's inode list.
580 */
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700581 if (master_key) {
582 struct fscrypt_master_key *mk =
583 master_key->payload.data[0];
584
585 refcount_inc(&mk->mk_refcount);
586 crypt_info->ci_master_key = key_get(master_key);
587 spin_lock(&mk->mk_decrypted_inodes_lock);
588 list_add(&crypt_info->ci_master_key_link,
589 &mk->mk_decrypted_inodes);
590 spin_unlock(&mk->mk_decrypted_inodes_lock);
591 }
Eric Biggers1b53cf92017-02-21 15:07:11 -0800592 crypt_info = NULL;
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700593 }
594 res = 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700595out:
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700596 if (master_key) {
Eric Biggers4a4b8722020-11-16 19:26:26 -0800597 up_read(&master_key->sem);
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700598 key_put(master_key);
599 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700600 put_crypt_info(crypt_info);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700601 return res;
602}
Eric Biggersa992b202020-09-16 21:11:24 -0700603
604/**
605 * fscrypt_get_encryption_info() - set up an inode's encryption key
Eric Biggersac4acb12020-09-16 21:11:35 -0700606 * @inode: the inode to set up the key for. Must be encrypted.
Eric Biggersa14d0b62020-12-02 18:20:41 -0800607 * @allow_unsupported: if %true, treat an unsupported encryption policy (or
608 * unrecognized encryption context) the same way as the key
609 * being unavailable, instead of returning an error. Use
610 * %false unless the operation being performed is needed in
611 * order for files (or directories) to be deleted.
Eric Biggersa992b202020-09-16 21:11:24 -0700612 *
613 * Set up ->i_crypt_info, if it hasn't already been done.
614 *
615 * Note: unless ->i_crypt_info is already set, this isn't %GFP_NOFS-safe. So
616 * generally this shouldn't be called from within a filesystem transaction.
617 *
618 * Return: 0 if ->i_crypt_info was set or was already set, *or* if the
619 * encryption key is unavailable. (Use fscrypt_has_encryption_key() to
620 * distinguish these cases.) Also can return another -errno code.
621 */
Eric Biggersa14d0b62020-12-02 18:20:41 -0800622int fscrypt_get_encryption_info(struct inode *inode, bool allow_unsupported)
Eric Biggersa992b202020-09-16 21:11:24 -0700623{
624 int res;
625 union fscrypt_context ctx;
626 union fscrypt_policy policy;
627
628 if (fscrypt_has_encryption_key(inode))
629 return 0;
630
631 res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
632 if (res < 0) {
Eric Biggersa14d0b62020-12-02 18:20:41 -0800633 if (res == -ERANGE && allow_unsupported)
634 return 0;
Eric Biggersac4acb12020-09-16 21:11:35 -0700635 fscrypt_warn(inode, "Error %d getting encryption context", res);
636 return res;
Eric Biggersa992b202020-09-16 21:11:24 -0700637 }
638
639 res = fscrypt_policy_from_context(&policy, &ctx, res);
640 if (res) {
Eric Biggersa14d0b62020-12-02 18:20:41 -0800641 if (allow_unsupported)
642 return 0;
Eric Biggersa992b202020-09-16 21:11:24 -0700643 fscrypt_warn(inode,
644 "Unrecognized or corrupt encryption context");
645 return res;
646 }
647
Eric Biggersa14d0b62020-12-02 18:20:41 -0800648 if (!fscrypt_supported_policy(&policy, inode)) {
649 if (allow_unsupported)
650 return 0;
Eric Biggersa992b202020-09-16 21:11:24 -0700651 return -EINVAL;
Eric Biggersa14d0b62020-12-02 18:20:41 -0800652 }
Eric Biggersa992b202020-09-16 21:11:24 -0700653
654 res = fscrypt_setup_encryption_info(inode, &policy,
655 fscrypt_context_nonce(&ctx),
656 IS_CASEFOLDED(inode) &&
657 S_ISDIR(inode->i_mode));
Eric Biggersa14d0b62020-12-02 18:20:41 -0800658
659 if (res == -ENOPKG && allow_unsupported) /* Algorithm unavailable? */
660 res = 0;
Eric Biggersa992b202020-09-16 21:11:24 -0700661 if (res == -ENOKEY)
662 res = 0;
663 return res;
664}
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700665
Eric Biggers2c58d542019-04-10 13:21:15 -0700666/**
Eric Biggersa992b202020-09-16 21:11:24 -0700667 * fscrypt_prepare_new_inode() - prepare to create a new inode in a directory
668 * @dir: a possibly-encrypted directory
669 * @inode: the new inode. ->i_mode must be set already.
670 * ->i_ino doesn't need to be set yet.
671 * @encrypt_ret: (output) set to %true if the new inode will be encrypted
672 *
673 * If the directory is encrypted, set up its ->i_crypt_info in preparation for
674 * encrypting the name of the new file. Also, if the new inode will be
675 * encrypted, set up its ->i_crypt_info and set *encrypt_ret=true.
676 *
677 * This isn't %GFP_NOFS-safe, and therefore it should be called before starting
678 * any filesystem transaction to create the inode. For this reason, ->i_ino
679 * isn't required to be set yet, as the filesystem may not have set it yet.
680 *
681 * This doesn't persist the new inode's encryption context. That still needs to
682 * be done later by calling fscrypt_set_context().
683 *
684 * Return: 0 on success, -ENOKEY if the encryption key is missing, or another
685 * -errno code
686 */
687int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode,
688 bool *encrypt_ret)
689{
Eric Biggersac4acb12020-09-16 21:11:35 -0700690 const union fscrypt_policy *policy;
Eric Biggersa992b202020-09-16 21:11:24 -0700691 u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
692
Eric Biggersac4acb12020-09-16 21:11:35 -0700693 policy = fscrypt_policy_to_inherit(dir);
694 if (policy == NULL)
Eric Biggersa992b202020-09-16 21:11:24 -0700695 return 0;
Eric Biggersac4acb12020-09-16 21:11:35 -0700696 if (IS_ERR(policy))
697 return PTR_ERR(policy);
Eric Biggersa992b202020-09-16 21:11:24 -0700698
699 if (WARN_ON_ONCE(inode->i_mode == 0))
700 return -EINVAL;
701
702 /*
703 * Only regular files, directories, and symlinks are encrypted.
704 * Special files like device nodes and named pipes aren't.
705 */
706 if (!S_ISREG(inode->i_mode) &&
707 !S_ISDIR(inode->i_mode) &&
708 !S_ISLNK(inode->i_mode))
709 return 0;
710
711 *encrypt_ret = true;
712
713 get_random_bytes(nonce, FSCRYPT_FILE_NONCE_SIZE);
Eric Biggersac4acb12020-09-16 21:11:35 -0700714 return fscrypt_setup_encryption_info(inode, policy, nonce,
Eric Biggersa992b202020-09-16 21:11:24 -0700715 IS_CASEFOLDED(dir) &&
716 S_ISDIR(inode->i_mode));
717}
718EXPORT_SYMBOL_GPL(fscrypt_prepare_new_inode);
719
720/**
Eric Biggersd2fe9752020-05-11 12:13:56 -0700721 * fscrypt_put_encryption_info() - free most of an inode's fscrypt data
722 * @inode: an inode being evicted
Eric Biggers2c58d542019-04-10 13:21:15 -0700723 *
724 * Free the inode's fscrypt_info. Filesystems must call this when the inode is
725 * being evicted. An RCU grace period need not have elapsed yet.
726 */
Eric Biggers3d204e22018-01-11 23:30:13 -0500727void fscrypt_put_encryption_info(struct inode *inode)
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700728{
Eric Biggers3d204e22018-01-11 23:30:13 -0500729 put_crypt_info(inode->i_crypt_info);
730 inode->i_crypt_info = NULL;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700731}
732EXPORT_SYMBOL(fscrypt_put_encryption_info);
Eric Biggers2c58d542019-04-10 13:21:15 -0700733
734/**
Eric Biggersd2fe9752020-05-11 12:13:56 -0700735 * fscrypt_free_inode() - free an inode's fscrypt data requiring RCU delay
736 * @inode: an inode being freed
Eric Biggers2c58d542019-04-10 13:21:15 -0700737 *
738 * Free the inode's cached decrypted symlink target, if any. Filesystems must
739 * call this after an RCU grace period, just before they free the inode.
740 */
741void fscrypt_free_inode(struct inode *inode)
742{
743 if (IS_ENCRYPTED(inode) && S_ISLNK(inode->i_mode)) {
744 kfree(inode->i_link);
745 inode->i_link = NULL;
746 }
747}
748EXPORT_SYMBOL(fscrypt_free_inode);
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700749
750/**
Eric Biggersd2fe9752020-05-11 12:13:56 -0700751 * fscrypt_drop_inode() - check whether the inode's master key has been removed
752 * @inode: an inode being considered for eviction
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700753 *
754 * Filesystems supporting fscrypt must call this from their ->drop_inode()
755 * method so that encrypted inodes are evicted as soon as they're no longer in
756 * use and their master key has been removed.
757 *
758 * Return: 1 if fscrypt wants the inode to be evicted now, otherwise 0
759 */
760int fscrypt_drop_inode(struct inode *inode)
761{
Eric Biggersab673b92020-07-21 15:59:19 -0700762 const struct fscrypt_info *ci = fscrypt_get_info(inode);
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700763 const struct fscrypt_master_key *mk;
764
765 /*
766 * If ci is NULL, then the inode doesn't have an encryption key set up
767 * so it's irrelevant. If ci_master_key is NULL, then the master key
768 * was provided via the legacy mechanism of the process-subscribed
769 * keyrings, so we don't know whether it's been removed or not.
770 */
771 if (!ci || !ci->ci_master_key)
772 return 0;
773 mk = ci->ci_master_key->payload.data[0];
774
775 /*
Eric Biggers2b4eae92020-03-05 00:41:38 -0800776 * With proper, non-racy use of FS_IOC_REMOVE_ENCRYPTION_KEY, all inodes
777 * protected by the key were cleaned by sync_filesystem(). But if
778 * userspace is still using the files, inodes can be dirtied between
779 * then and now. We mustn't lose any writes, so skip dirty inodes here.
780 */
781 if (inode->i_state & I_DIRTY_ALL)
782 return 0;
783
784 /*
Eric Biggers4a4b8722020-11-16 19:26:26 -0800785 * Note: since we aren't holding the key semaphore, the result here can
Eric Biggersb1c0ec32019-08-04 19:35:46 -0700786 * immediately become outdated. But there's no correctness problem with
787 * unnecessarily evicting. Nor is there a correctness problem with not
788 * evicting while iput() is racing with the key being removed, since
789 * then the thread removing the key will either evict the inode itself
790 * or will correctly detect that it wasn't evicted due to the race.
791 */
792 return !is_master_key_secret_present(&mk->mk_secret);
793}
794EXPORT_SYMBOL_GPL(fscrypt_drop_inode);