hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/fs/crypto/keysetup_v1.c
....@@ -45,7 +45,7 @@
4545 * key is longer, then only the first 'derived_keysize' bytes are used.
4646 */
4747 static int derive_key_aes(const u8 *master_key,
48
- const u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE],
48
+ const u8 nonce[FSCRYPT_FILE_NONCE_SIZE],
4949 u8 *derived_key, unsigned int derived_keysize)
5050 {
5151 int res = 0;
....@@ -59,8 +59,8 @@
5959 tfm = NULL;
6060 goto out;
6161 }
62
- crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
63
- req = skcipher_request_alloc(tfm, GFP_NOFS);
62
+ crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
63
+ req = skcipher_request_alloc(tfm, GFP_KERNEL);
6464 if (!req) {
6565 res = -ENOMEM;
6666 goto out;
....@@ -68,7 +68,7 @@
6868 skcipher_request_set_callback(req,
6969 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
7070 crypto_req_done, &wait);
71
- res = crypto_skcipher_setkey(tfm, nonce, FS_KEY_DERIVATION_NONCE_SIZE);
71
+ res = crypto_skcipher_setkey(tfm, nonce, FSCRYPT_FILE_NONCE_SIZE);
7272 if (res < 0)
7373 goto out;
7474
....@@ -99,7 +99,7 @@
9999 const struct user_key_payload *ukp;
100100 const struct fscrypt_key *payload;
101101
102
- description = kasprintf(GFP_NOFS, "%s%*phN", prefix,
102
+ description = kasprintf(GFP_KERNEL, "%s%*phN", prefix,
103103 FSCRYPT_KEY_DESCRIPTOR_SIZE, descriptor);
104104 if (!description)
105105 return ERR_PTR(-ENOMEM);
....@@ -155,7 +155,7 @@
155155 {
156156 if (dk) {
157157 fscrypt_destroy_prepared_key(&dk->dk_key);
158
- kzfree(dk);
158
+ kfree_sensitive(dk);
159159 }
160160 }
161161
....@@ -228,7 +228,7 @@
228228 return dk;
229229
230230 /* Nope, allocate one. */
231
- dk = kzalloc(sizeof(*dk), GFP_NOFS);
231
+ dk = kzalloc(sizeof(*dk), GFP_KERNEL);
232232 if (!dk)
233233 return ERR_PTR(-ENOMEM);
234234 refcount_set(&dk->dk_refcount, 1);
....@@ -258,7 +258,7 @@
258258 if (IS_ERR(dk))
259259 return PTR_ERR(dk);
260260 ci->ci_direct_key = dk;
261
- ci->ci_key = dk->dk_key;
261
+ ci->ci_enc_key = dk->dk_key;
262262 return 0;
263263 }
264264
....@@ -273,7 +273,7 @@
273273 * This cannot be a stack buffer because it will be passed to the
274274 * scatterlist crypto API during derive_key_aes().
275275 */
276
- derived_key = kmalloc(ci->ci_mode->keysize, GFP_NOFS);
276
+ derived_key = kmalloc(ci->ci_mode->keysize, GFP_KERNEL);
277277 if (!derived_key)
278278 return -ENOMEM;
279279
....@@ -284,7 +284,7 @@
284284
285285 err = fscrypt_set_per_file_enc_key(ci, derived_key);
286286 out:
287
- kzfree(derived_key);
287
+ kfree_sensitive(derived_key);
288288 return err;
289289 }
290290