aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2017-04-10 05:59:07 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-04-21 03:31:22 -0400
commit64ba06dc8a1d5c8e70b7b79a709bd1c90ec23afc (patch)
tree62a792fe27cd2fc4327c3107dd35bb139b64c000
parent7da0f8e547c2d3cac939da24458a88cce550af11 (diff)
crypto: algif_aead - Fix bogus request dereference in completion function
commit e6534aebb26e32fbab14df9c713c65e8507d17e4 upstream. The algif_aead completion function tries to deduce the aead_request from the crypto_async_request argument. This is broken because the API does not guarantee that the same request will be pased to the completion function. Only the value of req->data can be used in the completion function. This patch fixes it by storing a pointer to sk in areq and using that instead of passing in sk through req->data. Fixes: 83094e5e9e49 ("crypto: af_alg - add async support to...") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--crypto/algif_aead.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
index e8817e2f0597..fde8d885f7b6 100644
--- a/crypto/algif_aead.c
+++ b/crypto/algif_aead.c
@@ -39,6 +39,7 @@ struct aead_async_req {
39 struct aead_async_rsgl first_rsgl; 39 struct aead_async_rsgl first_rsgl;
40 struct list_head list; 40 struct list_head list;
41 struct kiocb *iocb; 41 struct kiocb *iocb;
42 struct sock *sk;
42 unsigned int tsgls; 43 unsigned int tsgls;
43 char iv[]; 44 char iv[];
44}; 45};
@@ -379,12 +380,10 @@ unlock:
379 380
380static void aead_async_cb(struct crypto_async_request *_req, int err) 381static void aead_async_cb(struct crypto_async_request *_req, int err)
381{ 382{
382 struct sock *sk = _req->data; 383 struct aead_request *req = _req->data;
383 struct alg_sock *ask = alg_sk(sk); 384 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
384 struct aead_ctx *ctx = ask->private;
385 struct crypto_aead *tfm = crypto_aead_reqtfm(&ctx->aead_req);
386 struct aead_request *req = aead_request_cast(_req);
387 struct aead_async_req *areq = GET_ASYM_REQ(req, tfm); 385 struct aead_async_req *areq = GET_ASYM_REQ(req, tfm);
386 struct sock *sk = areq->sk;
388 struct scatterlist *sg = areq->tsgl; 387 struct scatterlist *sg = areq->tsgl;
389 struct aead_async_rsgl *rsgl; 388 struct aead_async_rsgl *rsgl;
390 struct kiocb *iocb = areq->iocb; 389 struct kiocb *iocb = areq->iocb;
@@ -447,11 +446,12 @@ static int aead_recvmsg_async(struct socket *sock, struct msghdr *msg,
447 memset(&areq->first_rsgl, '\0', sizeof(areq->first_rsgl)); 446 memset(&areq->first_rsgl, '\0', sizeof(areq->first_rsgl));
448 INIT_LIST_HEAD(&areq->list); 447 INIT_LIST_HEAD(&areq->list);
449 areq->iocb = msg->msg_iocb; 448 areq->iocb = msg->msg_iocb;
449 areq->sk = sk;
450 memcpy(areq->iv, ctx->iv, crypto_aead_ivsize(tfm)); 450 memcpy(areq->iv, ctx->iv, crypto_aead_ivsize(tfm));
451 aead_request_set_tfm(req, tfm); 451 aead_request_set_tfm(req, tfm);
452 aead_request_set_ad(req, ctx->aead_assoclen); 452 aead_request_set_ad(req, ctx->aead_assoclen);
453 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 453 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
454 aead_async_cb, sk); 454 aead_async_cb, req);
455 used -= ctx->aead_assoclen; 455 used -= ctx->aead_assoclen;
456 456
457 /* take over all tx sgls from ctx */ 457 /* take over all tx sgls from ctx */