Skip to content

Commit 6e28694

Browse files
committed
Merge tag 'v7.1-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: - Fix IPsec ESN regression in authencesn - Fix hmac setkey failure in eip93 - Guard against IV changing in algif_aead - Fix async completion handling in krb5enc - Fix fallback async completion in acomp - Fix handling of MAY_BACKLOG requests in pcrypt - Fix issues with firmware-returned values in ccp * tag 'v7.1-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: krb5enc - fix async decrypt skipping hash verification crypto: algif_aead - snapshot IV for async AEAD requests crypto: acomp - fix wrong pointer stored by acomp_save_req() crypto: ccp - copy IV using skcipher ivsize crypto: ccp: Don't attempt to copy ID to userspace if PSP command failed crypto: ccp: Don't attempt to copy PDH cert to userspace if PSP command failed crypto: ccp: Don't attempt to copy CSR to userspace if PSP command failed crypto: pcrypt - Fix handling of MAY_BACKLOG requests crypto: sa2ul - Fix AEAD fallback algorithm names crypto: authencesn - Fix src offset when decrypting in-place crypto: eip93 - fix hmac setkey algo selection
2 parents 292a2bc + 3bfbf5f commit 6e28694

9 files changed

Lines changed: 76 additions & 39 deletions

File tree

crypto/acompress.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,13 @@ static void acomp_save_req(struct acomp_req *req, crypto_completion_t cplt)
169169
state->compl = req->base.complete;
170170
state->data = req->base.data;
171171
req->base.complete = cplt;
172-
req->base.data = state;
172+
req->base.data = req;
173173
}
174174

175175
static void acomp_restore_req(struct acomp_req *req)
176176
{
177-
struct acomp_req_chain *state = req->base.data;
178-
179-
req->base.complete = state->compl;
180-
req->base.data = state->data;
177+
req->base.complete = req->chain.compl;
178+
req->base.data = req->chain.data;
181179
}
182180

183181
static void acomp_reqchain_virt(struct acomp_req *req)

crypto/algif_aead.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
7272
struct af_alg_ctx *ctx = ask->private;
7373
struct crypto_aead *tfm = pask->private;
7474
unsigned int as = crypto_aead_authsize(tfm);
75+
unsigned int ivsize = crypto_aead_ivsize(tfm);
7576
struct af_alg_async_req *areq;
7677
struct scatterlist *rsgl_src, *tsgl_src = NULL;
78+
void *iv;
7779
int err = 0;
7880
size_t used = 0; /* [in] TX bufs to be en/decrypted */
7981
size_t outlen = 0; /* [out] RX bufs produced by kernel */
@@ -125,10 +127,14 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
125127

126128
/* Allocate cipher request for current operation. */
127129
areq = af_alg_alloc_areq(sk, sizeof(struct af_alg_async_req) +
128-
crypto_aead_reqsize(tfm));
130+
crypto_aead_reqsize(tfm) + ivsize);
129131
if (IS_ERR(areq))
130132
return PTR_ERR(areq);
131133

134+
iv = (u8 *)aead_request_ctx(&areq->cra_u.aead_req) +
135+
crypto_aead_reqsize(tfm);
136+
memcpy(iv, ctx->iv, ivsize);
137+
132138
/* convert iovecs of output buffers into RX SGL */
133139
err = af_alg_get_rsgl(sk, msg, flags, areq, outlen, &usedpages);
134140
if (err)
@@ -187,7 +193,7 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
187193

188194
/* Initialize the crypto operation */
189195
aead_request_set_crypt(&areq->cra_u.aead_req, tsgl_src,
190-
areq->first_rsgl.sgl.sgt.sgl, used, ctx->iv);
196+
areq->first_rsgl.sgl.sgt.sgl, used, iv);
191197
aead_request_set_ad(&areq->cra_u.aead_req, ctx->aead_assoclen);
192198
aead_request_set_tfm(&areq->cra_u.aead_req, tfm);
193199

crypto/authencesn.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ static int crypto_authenc_esn_decrypt_tail(struct aead_request *req,
228228

229229
decrypt:
230230

231-
if (src != dst)
232-
src = scatterwalk_ffwd(areq_ctx->src, src, assoclen);
233231
dst = scatterwalk_ffwd(areq_ctx->dst, dst, assoclen);
232+
if (req->src == req->dst)
233+
src = dst;
234+
else
235+
src = scatterwalk_ffwd(areq_ctx->src, src, assoclen);
234236

235237
skcipher_request_set_tfm(skreq, ctx->enc);
236238
skcipher_request_set_callback(skreq, flags,

crypto/krb5enc.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ struct krb5enc_request_ctx {
3939
char tail[];
4040
};
4141

42-
static void krb5enc_request_complete(struct aead_request *req, int err)
43-
{
44-
if (err != -EINPROGRESS)
45-
aead_request_complete(req, err);
46-
}
47-
4842
/**
4943
* crypto_krb5enc_extractkeys - Extract Ke and Ki keys from the key blob.
5044
* @keys: Where to put the key sizes and pointers
@@ -127,7 +121,7 @@ static void krb5enc_encrypt_done(void *data, int err)
127121
{
128122
struct aead_request *req = data;
129123

130-
krb5enc_request_complete(req, err);
124+
aead_request_complete(req, err);
131125
}
132126

133127
/*
@@ -188,14 +182,16 @@ static void krb5enc_encrypt_ahash_done(void *data, int err)
188182
struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff);
189183

190184
if (err)
191-
return krb5enc_request_complete(req, err);
185+
goto out;
192186

193187
krb5enc_insert_checksum(req, ahreq->result);
194188

195-
err = krb5enc_dispatch_encrypt(req,
196-
aead_request_flags(req) & ~CRYPTO_TFM_REQ_MAY_SLEEP);
197-
if (err != -EINPROGRESS)
198-
aead_request_complete(req, err);
189+
err = krb5enc_dispatch_encrypt(req, 0);
190+
if (err == -EINPROGRESS)
191+
return;
192+
193+
out:
194+
aead_request_complete(req, err);
199195
}
200196

201197
/*
@@ -265,17 +261,16 @@ static void krb5enc_decrypt_hash_done(void *data, int err)
265261
{
266262
struct aead_request *req = data;
267263

268-
if (err)
269-
return krb5enc_request_complete(req, err);
270-
271-
err = krb5enc_verify_hash(req);
272-
krb5enc_request_complete(req, err);
264+
if (!err)
265+
err = krb5enc_verify_hash(req);
266+
aead_request_complete(req, err);
273267
}
274268

275269
/*
276270
* Dispatch the hashing of the plaintext after we've done the decryption.
277271
*/
278-
static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)
272+
static int krb5enc_dispatch_decrypt_hash(struct aead_request *req,
273+
unsigned int flags)
279274
{
280275
struct crypto_aead *krb5enc = crypto_aead_reqtfm(req);
281276
struct aead_instance *inst = aead_alg_instance(krb5enc);
@@ -291,7 +286,7 @@ static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)
291286
ahash_request_set_tfm(ahreq, auth);
292287
ahash_request_set_crypt(ahreq, req->dst, hash,
293288
req->assoclen + req->cryptlen - authsize);
294-
ahash_request_set_callback(ahreq, aead_request_flags(req),
289+
ahash_request_set_callback(ahreq, flags,
295290
krb5enc_decrypt_hash_done, req);
296291

297292
err = crypto_ahash_digest(ahreq);
@@ -301,6 +296,21 @@ static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)
301296
return krb5enc_verify_hash(req);
302297
}
303298

299+
static void krb5enc_decrypt_done(void *data, int err)
300+
{
301+
struct aead_request *req = data;
302+
303+
if (err)
304+
goto out;
305+
306+
err = krb5enc_dispatch_decrypt_hash(req, 0);
307+
if (err == -EINPROGRESS)
308+
return;
309+
310+
out:
311+
aead_request_complete(req, err);
312+
}
313+
304314
/*
305315
* Dispatch the decryption of the ciphertext.
306316
*/
@@ -324,7 +334,7 @@ static int krb5enc_dispatch_decrypt(struct aead_request *req)
324334

325335
skcipher_request_set_tfm(skreq, ctx->enc);
326336
skcipher_request_set_callback(skreq, aead_request_flags(req),
327-
req->base.complete, req->base.data);
337+
krb5enc_decrypt_done, req);
328338
skcipher_request_set_crypt(skreq, src, dst,
329339
req->cryptlen - authsize, req->iv);
330340

@@ -339,7 +349,7 @@ static int krb5enc_decrypt(struct aead_request *req)
339349
if (err < 0)
340350
return err;
341351

342-
return krb5enc_dispatch_decrypt_hash(req);
352+
return krb5enc_dispatch_decrypt_hash(req, aead_request_flags(req));
343353
}
344354

345355
static int krb5enc_init_tfm(struct crypto_aead *tfm)

crypto/pcrypt.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ static void pcrypt_aead_done(void *data, int err)
6969
struct pcrypt_request *preq = aead_request_ctx(req);
7070
struct padata_priv *padata = pcrypt_request_padata(preq);
7171

72+
if (err == -EINPROGRESS)
73+
return;
74+
7275
padata->info = err;
7376

7477
padata_do_serial(padata);
@@ -82,7 +85,7 @@ static void pcrypt_aead_enc(struct padata_priv *padata)
8285

8386
ret = crypto_aead_encrypt(req);
8487

85-
if (ret == -EINPROGRESS)
88+
if (ret == -EINPROGRESS || ret == -EBUSY)
8689
return;
8790

8891
padata->info = ret;
@@ -133,7 +136,7 @@ static void pcrypt_aead_dec(struct padata_priv *padata)
133136

134137
ret = crypto_aead_decrypt(req);
135138

136-
if (ret == -EINPROGRESS)
139+
if (ret == -EINPROGRESS || ret == -EBUSY)
137140
return;
138141

139142
padata->info = ret;

drivers/crypto/ccp/ccp-crypto-aes.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ static int ccp_aes_complete(struct crypto_async_request *async_req, int ret)
3030
if (ret)
3131
return ret;
3232

33-
if (ctx->u.aes.mode != CCP_AES_MODE_ECB)
34-
memcpy(req->iv, rctx->iv, AES_BLOCK_SIZE);
33+
if (ctx->u.aes.mode != CCP_AES_MODE_ECB) {
34+
size_t ivsize = crypto_skcipher_ivsize(crypto_skcipher_reqtfm(req));
35+
36+
memcpy(req->iv, rctx->iv, ivsize);
37+
}
3538

3639
return 0;
3740
}

drivers/crypto/ccp/sev-dev.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,14 +1860,20 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
18601860

18611861
ret = __sev_do_cmd_locked(SEV_CMD_PEK_CSR, &data, &argp->error);
18621862

1863-
/* If we query the CSR length, FW responded with expected data. */
1863+
/*
1864+
* Firmware will returns the length of the CSR blob (either the minimum
1865+
* required length or the actual length written), return it to the user.
1866+
*/
18641867
input.length = data.len;
18651868

18661869
if (copy_to_user((void __user *)argp->data, &input, sizeof(input))) {
18671870
ret = -EFAULT;
18681871
goto e_free_blob;
18691872
}
18701873

1874+
if (ret || WARN_ON_ONCE(argp->error))
1875+
goto e_free_blob;
1876+
18711877
if (blob) {
18721878
if (copy_to_user(input_address, blob, input.length))
18731879
ret = -EFAULT;
@@ -2217,6 +2223,9 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
22172223
goto e_free;
22182224
}
22192225

2226+
if (ret || WARN_ON_ONCE(argp->error))
2227+
goto e_free;
2228+
22202229
if (id_blob) {
22212230
if (copy_to_user(input_address, id_blob, data.len)) {
22222231
ret = -EFAULT;
@@ -2333,7 +2342,10 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
23332342

23342343
ret = __sev_do_cmd_locked(SEV_CMD_PDH_CERT_EXPORT, &data, &argp->error);
23352344

2336-
/* If we query the length, FW responded with expected data. */
2345+
/*
2346+
* Firmware will return the length of the blobs (either the minimum
2347+
* required length or the actual length written), return 'em to the user.
2348+
*/
23372349
input.cert_chain_len = data.cert_chain_len;
23382350
input.pdh_cert_len = data.pdh_cert_len;
23392351

@@ -2342,6 +2354,9 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
23422354
goto e_free_cert;
23432355
}
23442356

2357+
if (ret || WARN_ON_ONCE(argp->error))
2358+
goto e_free_cert;
2359+
23452360
if (pdh_blob) {
23462361
if (copy_to_user(input_pdh_cert_address,
23472362
pdh_blob, input.pdh_cert_len)) {

drivers/crypto/inside-secure/eip93/eip93-common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ int eip93_hmac_setkey(u32 ctx_flags, const u8 *key, unsigned int keylen,
731731
return -EINVAL;
732732
}
733733

734-
ahash_tfm = crypto_alloc_ahash(alg_name, 0, CRYPTO_ALG_ASYNC);
734+
ahash_tfm = crypto_alloc_ahash(alg_name, 0, 0);
735735
if (IS_ERR(ahash_tfm))
736736
return PTR_ERR(ahash_tfm);
737737

drivers/crypto/sa2ul.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,13 +1744,13 @@ static int sa_cra_init_aead(struct crypto_aead *tfm, const char *hash,
17441744
static int sa_cra_init_aead_sha1(struct crypto_aead *tfm)
17451745
{
17461746
return sa_cra_init_aead(tfm, "sha1",
1747-
"authenc(hmac(sha1-ce),cbc(aes-ce))");
1747+
"authenc(hmac(sha1),cbc(aes))");
17481748
}
17491749

17501750
static int sa_cra_init_aead_sha256(struct crypto_aead *tfm)
17511751
{
17521752
return sa_cra_init_aead(tfm, "sha256",
1753-
"authenc(hmac(sha256-ce),cbc(aes-ce))");
1753+
"authenc(hmac(sha256),cbc(aes))");
17541754
}
17551755

17561756
static void sa_exit_tfm_aead(struct crypto_aead *tfm)

0 commit comments

Comments
 (0)