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