Skip to content

Commit 71ffd1d

Browse files
author
Eric Biggers
committed
fscrypt: Don't use asynchronous CryptoAPI algorithms
Now that fscrypt's incomplete support for non-inline crypto engines has been removed, and none of the CPU-based algorithms have the CRYPTO_ALG_ASYNC flag set anymore, there is no need to accommodate asynchronous algorithms. Therefore, explicitly allocate only synchronous algorithms. Then, remove the code that handled waiting for asynchronous en/decryption operations to complete. This commit should *not* be backported to kernels that lack commit 0ba6ec5 ("crypto: x86/aes - stop using the SIMD helper"), as then it would disable the use of the optimized AES code on x86. Link: https://lore.kernel.org/r/20250710060754.637098-2-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent b41c1d8 commit 71ffd1d

4 files changed

Lines changed: 18 additions & 21 deletions

File tree

fs/crypto/crypto.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ int fscrypt_crypt_data_unit(const struct fscrypt_inode_info *ci,
115115
{
116116
union fscrypt_iv iv;
117117
struct skcipher_request *req = NULL;
118-
DECLARE_CRYPTO_WAIT(wait);
119118
struct scatterlist dst, src;
120119
struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;
121120
int res = 0;
@@ -133,17 +132,17 @@ int fscrypt_crypt_data_unit(const struct fscrypt_inode_info *ci,
133132

134133
skcipher_request_set_callback(
135134
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
136-
crypto_req_done, &wait);
135+
NULL, NULL);
137136

138137
sg_init_table(&dst, 1);
139138
sg_set_page(&dst, dest_page, len, offs);
140139
sg_init_table(&src, 1);
141140
sg_set_page(&src, src_page, len, offs);
142141
skcipher_request_set_crypt(req, &src, &dst, len, &iv);
143142
if (rw == FS_DECRYPT)
144-
res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait);
143+
res = crypto_skcipher_decrypt(req);
145144
else
146-
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
145+
res = crypto_skcipher_encrypt(req);
147146
skcipher_request_free(req);
148147
if (res) {
149148
fscrypt_err(ci->ci_inode,

fs/crypto/fname.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,
9595
u8 *out, unsigned int olen)
9696
{
9797
struct skcipher_request *req = NULL;
98-
DECLARE_CRYPTO_WAIT(wait);
9998
const struct fscrypt_inode_info *ci = inode->i_crypt_info;
10099
struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;
101100
union fscrypt_iv iv;
@@ -118,14 +117,14 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,
118117
req = skcipher_request_alloc(tfm, GFP_NOFS);
119118
if (!req)
120119
return -ENOMEM;
121-
skcipher_request_set_callback(req,
122-
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
123-
crypto_req_done, &wait);
120+
skcipher_request_set_callback(
121+
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
122+
NULL, NULL);
124123
sg_init_one(&sg, out, olen);
125124
skcipher_request_set_crypt(req, &sg, &sg, olen, &iv);
126125

127126
/* Do the encryption */
128-
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
127+
res = crypto_skcipher_encrypt(req);
129128
skcipher_request_free(req);
130129
if (res < 0) {
131130
fscrypt_err(inode, "Filename encryption failed: %d", res);
@@ -151,7 +150,6 @@ static int fname_decrypt(const struct inode *inode,
151150
struct fscrypt_str *oname)
152151
{
153152
struct skcipher_request *req = NULL;
154-
DECLARE_CRYPTO_WAIT(wait);
155153
struct scatterlist src_sg, dst_sg;
156154
const struct fscrypt_inode_info *ci = inode->i_crypt_info;
157155
struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;
@@ -162,9 +160,9 @@ static int fname_decrypt(const struct inode *inode,
162160
req = skcipher_request_alloc(tfm, GFP_NOFS);
163161
if (!req)
164162
return -ENOMEM;
165-
skcipher_request_set_callback(req,
166-
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
167-
crypto_req_done, &wait);
163+
skcipher_request_set_callback(
164+
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
165+
NULL, NULL);
168166

169167
/* Initialize IV */
170168
fscrypt_generate_iv(&iv, 0, ci);
@@ -173,7 +171,7 @@ static int fname_decrypt(const struct inode *inode,
173171
sg_init_one(&src_sg, iname->name, iname->len);
174172
sg_init_one(&dst_sg, oname->name, oname->len);
175173
skcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, &iv);
176-
res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait);
174+
res = crypto_skcipher_decrypt(req);
177175
skcipher_request_free(req);
178176
if (res < 0) {
179177
fscrypt_err(inode, "Filename decryption failed: %d", res);

fs/crypto/fscrypt_private.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
* Note that fscrypt also supports inline crypto engines. Those don't use the
6060
* Crypto API and work much better than the old-style (non-inline) engines.
6161
*/
62-
#define FSCRYPT_CRYPTOAPI_MASK \
63-
(CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY)
62+
#define FSCRYPT_CRYPTOAPI_MASK \
63+
(CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | \
64+
CRYPTO_ALG_KERN_DRIVER_ONLY)
6465

6566
#define FSCRYPT_CONTEXT_V1 1
6667
#define FSCRYPT_CONTEXT_V2 2

fs/crypto/keysetup_v1.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ static int derive_key_aes(const u8 *master_key,
5050
{
5151
int res = 0;
5252
struct skcipher_request *req = NULL;
53-
DECLARE_CRYPTO_WAIT(wait);
5453
struct scatterlist src_sg, dst_sg;
5554
struct crypto_skcipher *tfm =
5655
crypto_alloc_skcipher("ecb(aes)", 0, FSCRYPT_CRYPTOAPI_MASK);
@@ -66,9 +65,9 @@ static int derive_key_aes(const u8 *master_key,
6665
res = -ENOMEM;
6766
goto out;
6867
}
69-
skcipher_request_set_callback(req,
70-
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
71-
crypto_req_done, &wait);
68+
skcipher_request_set_callback(
69+
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
70+
NULL, NULL);
7271
res = crypto_skcipher_setkey(tfm, nonce, FSCRYPT_FILE_NONCE_SIZE);
7372
if (res < 0)
7473
goto out;
@@ -77,7 +76,7 @@ static int derive_key_aes(const u8 *master_key,
7776
sg_init_one(&dst_sg, derived_key, derived_keysize);
7877
skcipher_request_set_crypt(req, &src_sg, &dst_sg, derived_keysize,
7978
NULL);
80-
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
79+
res = crypto_skcipher_encrypt(req);
8180
out:
8281
skcipher_request_free(req);
8382
crypto_free_skcipher(tfm);

0 commit comments

Comments
 (0)