]> asedeno.scripts.mit.edu Git - linux.git/blob - fs/crypto/keyinfo.c
fscrypt: use FSCRYPT_* definitions, not FS_*
[linux.git] / fs / crypto / keyinfo.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * key management facility for FS encryption support.
4  *
5  * Copyright (C) 2015, Google, Inc.
6  *
7  * This contains encryption key functions.
8  *
9  * Written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar, 2015.
10  */
11
12 #include <keys/user-type.h>
13 #include <linux/hashtable.h>
14 #include <linux/scatterlist.h>
15 #include <crypto/aes.h>
16 #include <crypto/algapi.h>
17 #include <crypto/sha.h>
18 #include <crypto/skcipher.h>
19 #include "fscrypt_private.h"
20
21 static struct crypto_shash *essiv_hash_tfm;
22
23 /* Table of keys referenced by DIRECT_KEY policies */
24 static DEFINE_HASHTABLE(fscrypt_master_keys, 6); /* 6 bits = 64 buckets */
25 static DEFINE_SPINLOCK(fscrypt_master_keys_lock);
26
27 /*
28  * Key derivation function.  This generates the derived key by encrypting the
29  * master key with AES-128-ECB using the inode's nonce as the AES key.
30  *
31  * The master key must be at least as long as the derived key.  If the master
32  * key is longer, then only the first 'derived_keysize' bytes are used.
33  */
34 static int derive_key_aes(const u8 *master_key,
35                           const struct fscrypt_context *ctx,
36                           u8 *derived_key, unsigned int derived_keysize)
37 {
38         int res = 0;
39         struct skcipher_request *req = NULL;
40         DECLARE_CRYPTO_WAIT(wait);
41         struct scatterlist src_sg, dst_sg;
42         struct crypto_skcipher *tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0);
43
44         if (IS_ERR(tfm)) {
45                 res = PTR_ERR(tfm);
46                 tfm = NULL;
47                 goto out;
48         }
49         crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
50         req = skcipher_request_alloc(tfm, GFP_NOFS);
51         if (!req) {
52                 res = -ENOMEM;
53                 goto out;
54         }
55         skcipher_request_set_callback(req,
56                         CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
57                         crypto_req_done, &wait);
58         res = crypto_skcipher_setkey(tfm, ctx->nonce, sizeof(ctx->nonce));
59         if (res < 0)
60                 goto out;
61
62         sg_init_one(&src_sg, master_key, derived_keysize);
63         sg_init_one(&dst_sg, derived_key, derived_keysize);
64         skcipher_request_set_crypt(req, &src_sg, &dst_sg, derived_keysize,
65                                    NULL);
66         res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
67 out:
68         skcipher_request_free(req);
69         crypto_free_skcipher(tfm);
70         return res;
71 }
72
73 /*
74  * Search the current task's subscribed keyrings for a "logon" key with
75  * description prefix:descriptor, and if found acquire a read lock on it and
76  * return a pointer to its validated payload in *payload_ret.
77  */
78 static struct key *
79 find_and_lock_process_key(const char *prefix,
80                           const u8 descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE],
81                           unsigned int min_keysize,
82                           const struct fscrypt_key **payload_ret)
83 {
84         char *description;
85         struct key *key;
86         const struct user_key_payload *ukp;
87         const struct fscrypt_key *payload;
88
89         description = kasprintf(GFP_NOFS, "%s%*phN", prefix,
90                                 FSCRYPT_KEY_DESCRIPTOR_SIZE, descriptor);
91         if (!description)
92                 return ERR_PTR(-ENOMEM);
93
94         key = request_key(&key_type_logon, description, NULL);
95         kfree(description);
96         if (IS_ERR(key))
97                 return key;
98
99         down_read(&key->sem);
100         ukp = user_key_payload_locked(key);
101
102         if (!ukp) /* was the key revoked before we acquired its semaphore? */
103                 goto invalid;
104
105         payload = (const struct fscrypt_key *)ukp->data;
106
107         if (ukp->datalen != sizeof(struct fscrypt_key) ||
108             payload->size < 1 || payload->size > FSCRYPT_MAX_KEY_SIZE) {
109                 fscrypt_warn(NULL,
110                              "key with description '%s' has invalid payload",
111                              key->description);
112                 goto invalid;
113         }
114
115         if (payload->size < min_keysize) {
116                 fscrypt_warn(NULL,
117                              "key with description '%s' is too short (got %u bytes, need %u+ bytes)",
118                              key->description, payload->size, min_keysize);
119                 goto invalid;
120         }
121
122         *payload_ret = payload;
123         return key;
124
125 invalid:
126         up_read(&key->sem);
127         key_put(key);
128         return ERR_PTR(-ENOKEY);
129 }
130
131 static struct fscrypt_mode available_modes[] = {
132         [FSCRYPT_MODE_AES_256_XTS] = {
133                 .friendly_name = "AES-256-XTS",
134                 .cipher_str = "xts(aes)",
135                 .keysize = 64,
136                 .ivsize = 16,
137         },
138         [FSCRYPT_MODE_AES_256_CTS] = {
139                 .friendly_name = "AES-256-CTS-CBC",
140                 .cipher_str = "cts(cbc(aes))",
141                 .keysize = 32,
142                 .ivsize = 16,
143         },
144         [FSCRYPT_MODE_AES_128_CBC] = {
145                 .friendly_name = "AES-128-CBC",
146                 .cipher_str = "cbc(aes)",
147                 .keysize = 16,
148                 .ivsize = 16,
149                 .needs_essiv = true,
150         },
151         [FSCRYPT_MODE_AES_128_CTS] = {
152                 .friendly_name = "AES-128-CTS-CBC",
153                 .cipher_str = "cts(cbc(aes))",
154                 .keysize = 16,
155                 .ivsize = 16,
156         },
157         [FSCRYPT_MODE_ADIANTUM] = {
158                 .friendly_name = "Adiantum",
159                 .cipher_str = "adiantum(xchacha12,aes)",
160                 .keysize = 32,
161                 .ivsize = 32,
162         },
163 };
164
165 static struct fscrypt_mode *
166 select_encryption_mode(const struct fscrypt_info *ci, const struct inode *inode)
167 {
168         if (!fscrypt_valid_enc_modes(ci->ci_data_mode, ci->ci_filename_mode)) {
169                 fscrypt_warn(inode,
170                              "Unsupported encryption modes (contents mode %d, filenames mode %d)",
171                              ci->ci_data_mode, ci->ci_filename_mode);
172                 return ERR_PTR(-EINVAL);
173         }
174
175         if (S_ISREG(inode->i_mode))
176                 return &available_modes[ci->ci_data_mode];
177
178         if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
179                 return &available_modes[ci->ci_filename_mode];
180
181         WARN_ONCE(1, "fscrypt: filesystem tried to load encryption info for inode %lu, which is not encryptable (file type %d)\n",
182                   inode->i_ino, (inode->i_mode & S_IFMT));
183         return ERR_PTR(-EINVAL);
184 }
185
186 /* Find the master key, then derive the inode's actual encryption key */
187 static int find_and_derive_key(const struct inode *inode,
188                                const struct fscrypt_context *ctx,
189                                u8 *derived_key, const struct fscrypt_mode *mode)
190 {
191         struct key *key;
192         const struct fscrypt_key *payload;
193         int err;
194
195         key = find_and_lock_process_key(FSCRYPT_KEY_DESC_PREFIX,
196                                         ctx->master_key_descriptor,
197                                         mode->keysize, &payload);
198         if (key == ERR_PTR(-ENOKEY) && inode->i_sb->s_cop->key_prefix) {
199                 key = find_and_lock_process_key(inode->i_sb->s_cop->key_prefix,
200                                                 ctx->master_key_descriptor,
201                                                 mode->keysize, &payload);
202         }
203         if (IS_ERR(key))
204                 return PTR_ERR(key);
205
206         if (ctx->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) {
207                 if (mode->ivsize < offsetofend(union fscrypt_iv, nonce)) {
208                         fscrypt_warn(inode,
209                                      "Direct key mode not allowed with %s",
210                                      mode->friendly_name);
211                         err = -EINVAL;
212                 } else if (ctx->contents_encryption_mode !=
213                            ctx->filenames_encryption_mode) {
214                         fscrypt_warn(inode,
215                                      "Direct key mode not allowed with different contents and filenames modes");
216                         err = -EINVAL;
217                 } else {
218                         memcpy(derived_key, payload->raw, mode->keysize);
219                         err = 0;
220                 }
221         } else {
222                 err = derive_key_aes(payload->raw, ctx, derived_key,
223                                      mode->keysize);
224         }
225         up_read(&key->sem);
226         key_put(key);
227         return err;
228 }
229
230 /* Allocate and key a symmetric cipher object for the given encryption mode */
231 static struct crypto_skcipher *
232 allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key,
233                            const struct inode *inode)
234 {
235         struct crypto_skcipher *tfm;
236         int err;
237
238         tfm = crypto_alloc_skcipher(mode->cipher_str, 0, 0);
239         if (IS_ERR(tfm)) {
240                 if (PTR_ERR(tfm) == -ENOENT) {
241                         fscrypt_warn(inode,
242                                      "Missing crypto API support for %s (API name: \"%s\")",
243                                      mode->friendly_name, mode->cipher_str);
244                         return ERR_PTR(-ENOPKG);
245                 }
246                 fscrypt_err(inode, "Error allocating '%s' transform: %ld",
247                             mode->cipher_str, PTR_ERR(tfm));
248                 return tfm;
249         }
250         if (unlikely(!mode->logged_impl_name)) {
251                 /*
252                  * fscrypt performance can vary greatly depending on which
253                  * crypto algorithm implementation is used.  Help people debug
254                  * performance problems by logging the ->cra_driver_name the
255                  * first time a mode is used.  Note that multiple threads can
256                  * race here, but it doesn't really matter.
257                  */
258                 mode->logged_impl_name = true;
259                 pr_info("fscrypt: %s using implementation \"%s\"\n",
260                         mode->friendly_name,
261                         crypto_skcipher_alg(tfm)->base.cra_driver_name);
262         }
263         crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
264         err = crypto_skcipher_setkey(tfm, raw_key, mode->keysize);
265         if (err)
266                 goto err_free_tfm;
267
268         return tfm;
269
270 err_free_tfm:
271         crypto_free_skcipher(tfm);
272         return ERR_PTR(err);
273 }
274
275 /* Master key referenced by DIRECT_KEY policy */
276 struct fscrypt_master_key {
277         struct hlist_node mk_node;
278         refcount_t mk_refcount;
279         const struct fscrypt_mode *mk_mode;
280         struct crypto_skcipher *mk_ctfm;
281         u8 mk_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
282         u8 mk_raw[FSCRYPT_MAX_KEY_SIZE];
283 };
284
285 static void free_master_key(struct fscrypt_master_key *mk)
286 {
287         if (mk) {
288                 crypto_free_skcipher(mk->mk_ctfm);
289                 kzfree(mk);
290         }
291 }
292
293 static void put_master_key(struct fscrypt_master_key *mk)
294 {
295         if (!refcount_dec_and_lock(&mk->mk_refcount, &fscrypt_master_keys_lock))
296                 return;
297         hash_del(&mk->mk_node);
298         spin_unlock(&fscrypt_master_keys_lock);
299
300         free_master_key(mk);
301 }
302
303 /*
304  * Find/insert the given master key into the fscrypt_master_keys table.  If
305  * found, it is returned with elevated refcount, and 'to_insert' is freed if
306  * non-NULL.  If not found, 'to_insert' is inserted and returned if it's
307  * non-NULL; otherwise NULL is returned.
308  */
309 static struct fscrypt_master_key *
310 find_or_insert_master_key(struct fscrypt_master_key *to_insert,
311                           const u8 *raw_key, const struct fscrypt_mode *mode,
312                           const struct fscrypt_info *ci)
313 {
314         unsigned long hash_key;
315         struct fscrypt_master_key *mk;
316
317         /*
318          * Careful: to avoid potentially leaking secret key bytes via timing
319          * information, we must key the hash table by descriptor rather than by
320          * raw key, and use crypto_memneq() when comparing raw keys.
321          */
322
323         BUILD_BUG_ON(sizeof(hash_key) > FSCRYPT_KEY_DESCRIPTOR_SIZE);
324         memcpy(&hash_key, ci->ci_master_key_descriptor, sizeof(hash_key));
325
326         spin_lock(&fscrypt_master_keys_lock);
327         hash_for_each_possible(fscrypt_master_keys, mk, mk_node, hash_key) {
328                 if (memcmp(ci->ci_master_key_descriptor, mk->mk_descriptor,
329                            FSCRYPT_KEY_DESCRIPTOR_SIZE) != 0)
330                         continue;
331                 if (mode != mk->mk_mode)
332                         continue;
333                 if (crypto_memneq(raw_key, mk->mk_raw, mode->keysize))
334                         continue;
335                 /* using existing tfm with same (descriptor, mode, raw_key) */
336                 refcount_inc(&mk->mk_refcount);
337                 spin_unlock(&fscrypt_master_keys_lock);
338                 free_master_key(to_insert);
339                 return mk;
340         }
341         if (to_insert)
342                 hash_add(fscrypt_master_keys, &to_insert->mk_node, hash_key);
343         spin_unlock(&fscrypt_master_keys_lock);
344         return to_insert;
345 }
346
347 /* Prepare to encrypt directly using the master key in the given mode */
348 static struct fscrypt_master_key *
349 fscrypt_get_master_key(const struct fscrypt_info *ci, struct fscrypt_mode *mode,
350                        const u8 *raw_key, const struct inode *inode)
351 {
352         struct fscrypt_master_key *mk;
353         int err;
354
355         /* Is there already a tfm for this key? */
356         mk = find_or_insert_master_key(NULL, raw_key, mode, ci);
357         if (mk)
358                 return mk;
359
360         /* Nope, allocate one. */
361         mk = kzalloc(sizeof(*mk), GFP_NOFS);
362         if (!mk)
363                 return ERR_PTR(-ENOMEM);
364         refcount_set(&mk->mk_refcount, 1);
365         mk->mk_mode = mode;
366         mk->mk_ctfm = allocate_skcipher_for_mode(mode, raw_key, inode);
367         if (IS_ERR(mk->mk_ctfm)) {
368                 err = PTR_ERR(mk->mk_ctfm);
369                 mk->mk_ctfm = NULL;
370                 goto err_free_mk;
371         }
372         memcpy(mk->mk_descriptor, ci->ci_master_key_descriptor,
373                FSCRYPT_KEY_DESCRIPTOR_SIZE);
374         memcpy(mk->mk_raw, raw_key, mode->keysize);
375
376         return find_or_insert_master_key(mk, raw_key, mode, ci);
377
378 err_free_mk:
379         free_master_key(mk);
380         return ERR_PTR(err);
381 }
382
383 static int derive_essiv_salt(const u8 *key, int keysize, u8 *salt)
384 {
385         struct crypto_shash *tfm = READ_ONCE(essiv_hash_tfm);
386
387         /* init hash transform on demand */
388         if (unlikely(!tfm)) {
389                 struct crypto_shash *prev_tfm;
390
391                 tfm = crypto_alloc_shash("sha256", 0, 0);
392                 if (IS_ERR(tfm)) {
393                         if (PTR_ERR(tfm) == -ENOENT) {
394                                 fscrypt_warn(NULL,
395                                              "Missing crypto API support for SHA-256");
396                                 return -ENOPKG;
397                         }
398                         fscrypt_err(NULL,
399                                     "Error allocating SHA-256 transform: %ld",
400                                     PTR_ERR(tfm));
401                         return PTR_ERR(tfm);
402                 }
403                 prev_tfm = cmpxchg(&essiv_hash_tfm, NULL, tfm);
404                 if (prev_tfm) {
405                         crypto_free_shash(tfm);
406                         tfm = prev_tfm;
407                 }
408         }
409
410         {
411                 SHASH_DESC_ON_STACK(desc, tfm);
412                 desc->tfm = tfm;
413
414                 return crypto_shash_digest(desc, key, keysize, salt);
415         }
416 }
417
418 static int init_essiv_generator(struct fscrypt_info *ci, const u8 *raw_key,
419                                 int keysize)
420 {
421         int err;
422         struct crypto_cipher *essiv_tfm;
423         u8 salt[SHA256_DIGEST_SIZE];
424
425         essiv_tfm = crypto_alloc_cipher("aes", 0, 0);
426         if (IS_ERR(essiv_tfm))
427                 return PTR_ERR(essiv_tfm);
428
429         ci->ci_essiv_tfm = essiv_tfm;
430
431         err = derive_essiv_salt(raw_key, keysize, salt);
432         if (err)
433                 goto out;
434
435         /*
436          * Using SHA256 to derive the salt/key will result in AES-256 being
437          * used for IV generation. File contents encryption will still use the
438          * configured keysize (AES-128) nevertheless.
439          */
440         err = crypto_cipher_setkey(essiv_tfm, salt, sizeof(salt));
441         if (err)
442                 goto out;
443
444 out:
445         memzero_explicit(salt, sizeof(salt));
446         return err;
447 }
448
449 /*
450  * Given the encryption mode and key (normally the derived key, but for
451  * DIRECT_KEY mode it's the master key), set up the inode's symmetric cipher
452  * transform object(s).
453  */
454 static int setup_crypto_transform(struct fscrypt_info *ci,
455                                   struct fscrypt_mode *mode,
456                                   const u8 *raw_key, const struct inode *inode)
457 {
458         struct fscrypt_master_key *mk;
459         struct crypto_skcipher *ctfm;
460         int err;
461
462         if (ci->ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) {
463                 mk = fscrypt_get_master_key(ci, mode, raw_key, inode);
464                 if (IS_ERR(mk))
465                         return PTR_ERR(mk);
466                 ctfm = mk->mk_ctfm;
467         } else {
468                 mk = NULL;
469                 ctfm = allocate_skcipher_for_mode(mode, raw_key, inode);
470                 if (IS_ERR(ctfm))
471                         return PTR_ERR(ctfm);
472         }
473         ci->ci_master_key = mk;
474         ci->ci_ctfm = ctfm;
475
476         if (mode->needs_essiv) {
477                 /* ESSIV implies 16-byte IVs which implies !DIRECT_KEY */
478                 WARN_ON(mode->ivsize != AES_BLOCK_SIZE);
479                 WARN_ON(ci->ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY);
480
481                 err = init_essiv_generator(ci, raw_key, mode->keysize);
482                 if (err) {
483                         fscrypt_warn(inode,
484                                      "Error initializing ESSIV generator: %d",
485                                      err);
486                         return err;
487                 }
488         }
489         return 0;
490 }
491
492 static void put_crypt_info(struct fscrypt_info *ci)
493 {
494         if (!ci)
495                 return;
496
497         if (ci->ci_master_key) {
498                 put_master_key(ci->ci_master_key);
499         } else {
500                 crypto_free_skcipher(ci->ci_ctfm);
501                 crypto_free_cipher(ci->ci_essiv_tfm);
502         }
503         kmem_cache_free(fscrypt_info_cachep, ci);
504 }
505
506 int fscrypt_get_encryption_info(struct inode *inode)
507 {
508         struct fscrypt_info *crypt_info;
509         struct fscrypt_context ctx;
510         struct fscrypt_mode *mode;
511         u8 *raw_key = NULL;
512         int res;
513
514         if (fscrypt_has_encryption_key(inode))
515                 return 0;
516
517         res = fscrypt_initialize(inode->i_sb->s_cop->flags);
518         if (res)
519                 return res;
520
521         res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
522         if (res < 0) {
523                 if (!fscrypt_dummy_context_enabled(inode) ||
524                     IS_ENCRYPTED(inode)) {
525                         fscrypt_warn(inode,
526                                      "Error %d getting encryption context",
527                                      res);
528                         return res;
529                 }
530                 /* Fake up a context for an unencrypted directory */
531                 memset(&ctx, 0, sizeof(ctx));
532                 ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1;
533                 ctx.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS;
534                 ctx.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS;
535                 memset(ctx.master_key_descriptor, 0x42,
536                        FSCRYPT_KEY_DESCRIPTOR_SIZE);
537         } else if (res != sizeof(ctx)) {
538                 fscrypt_warn(inode,
539                              "Unknown encryption context size (%d bytes)", res);
540                 return -EINVAL;
541         }
542
543         if (ctx.format != FS_ENCRYPTION_CONTEXT_FORMAT_V1) {
544                 fscrypt_warn(inode, "Unknown encryption context version (%d)",
545                              ctx.format);
546                 return -EINVAL;
547         }
548
549         if (ctx.flags & ~FSCRYPT_POLICY_FLAGS_VALID) {
550                 fscrypt_warn(inode, "Unknown encryption context flags (0x%02x)",
551                              ctx.flags);
552                 return -EINVAL;
553         }
554
555         crypt_info = kmem_cache_zalloc(fscrypt_info_cachep, GFP_NOFS);
556         if (!crypt_info)
557                 return -ENOMEM;
558
559         crypt_info->ci_flags = ctx.flags;
560         crypt_info->ci_data_mode = ctx.contents_encryption_mode;
561         crypt_info->ci_filename_mode = ctx.filenames_encryption_mode;
562         memcpy(crypt_info->ci_master_key_descriptor, ctx.master_key_descriptor,
563                FSCRYPT_KEY_DESCRIPTOR_SIZE);
564         memcpy(crypt_info->ci_nonce, ctx.nonce, FS_KEY_DERIVATION_NONCE_SIZE);
565
566         mode = select_encryption_mode(crypt_info, inode);
567         if (IS_ERR(mode)) {
568                 res = PTR_ERR(mode);
569                 goto out;
570         }
571         WARN_ON(mode->ivsize > FSCRYPT_MAX_IV_SIZE);
572         crypt_info->ci_mode = mode;
573
574         /*
575          * This cannot be a stack buffer because it may be passed to the
576          * scatterlist crypto API as part of key derivation.
577          */
578         res = -ENOMEM;
579         raw_key = kmalloc(mode->keysize, GFP_NOFS);
580         if (!raw_key)
581                 goto out;
582
583         res = find_and_derive_key(inode, &ctx, raw_key, mode);
584         if (res)
585                 goto out;
586
587         res = setup_crypto_transform(crypt_info, mode, raw_key, inode);
588         if (res)
589                 goto out;
590
591         if (cmpxchg_release(&inode->i_crypt_info, NULL, crypt_info) == NULL)
592                 crypt_info = NULL;
593 out:
594         if (res == -ENOKEY)
595                 res = 0;
596         put_crypt_info(crypt_info);
597         kzfree(raw_key);
598         return res;
599 }
600 EXPORT_SYMBOL(fscrypt_get_encryption_info);
601
602 /**
603  * fscrypt_put_encryption_info - free most of an inode's fscrypt data
604  *
605  * Free the inode's fscrypt_info.  Filesystems must call this when the inode is
606  * being evicted.  An RCU grace period need not have elapsed yet.
607  */
608 void fscrypt_put_encryption_info(struct inode *inode)
609 {
610         put_crypt_info(inode->i_crypt_info);
611         inode->i_crypt_info = NULL;
612 }
613 EXPORT_SYMBOL(fscrypt_put_encryption_info);
614
615 /**
616  * fscrypt_free_inode - free an inode's fscrypt data requiring RCU delay
617  *
618  * Free the inode's cached decrypted symlink target, if any.  Filesystems must
619  * call this after an RCU grace period, just before they free the inode.
620  */
621 void fscrypt_free_inode(struct inode *inode)
622 {
623         if (IS_ENCRYPTED(inode) && S_ISLNK(inode->i_mode)) {
624                 kfree(inode->i_link);
625                 inode->i_link = NULL;
626         }
627 }
628 EXPORT_SYMBOL(fscrypt_free_inode);