Skip to content

Commit

Permalink
crypto: lrw - Fix use-after-free on EINPROGRESS
Browse files Browse the repository at this point in the history
When we get an EINPROGRESS completion in lrw, we will end up marking
the request as done and freeing it.  This then blows up when the
request is really completed as we've already freed the memory.

Fixes: 700cb3f ("crypto: lrw - Convert to skcipher")
Cc: <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Apr 10, 2017
1 parent aa4a829 commit 4702bbe
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crypto/lrw.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,21 @@ static void encrypt_done(struct crypto_async_request *areq, int err)
struct rctx *rctx;

rctx = skcipher_request_ctx(req);

if (err == -EINPROGRESS) {
if (rctx->left != req->cryptlen)
return;
goto out;
}

subreq = &rctx->subreq;
subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;

err = do_encrypt(req, err ?: post_crypt(req));
if (rctx->left)
return;

out:
skcipher_request_complete(req, err);
}

Expand Down Expand Up @@ -389,13 +397,21 @@ static void decrypt_done(struct crypto_async_request *areq, int err)
struct rctx *rctx;

rctx = skcipher_request_ctx(req);

if (err == -EINPROGRESS) {
if (rctx->left != req->cryptlen)
return;
goto out;
}

subreq = &rctx->subreq;
subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;

err = do_decrypt(req, err ?: post_crypt(req));
if (rctx->left)
return;

out:
skcipher_request_complete(req, err);
}

Expand Down

0 comments on commit 4702bbe

Please sign in to comment.