[PATCH 4.10 57/69] crypto: xts - Fix use-after-free on EINPROGRESS

From: Greg Kroah-Hartman
Date: Wed Apr 19 2017 - 11:19:25 EST


4.10-stable review patch. If anyone has any objections, please let me know.

------------------

From: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

commit aa4a829bdaced81e70c215a84ef6595ce8bd4308 upstream.

When we get an EINPROGRESS completion in xts, 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: f1c131b45410 ("crypto: xts - Convert to skcipher")
Reported-by: Nathan Royce <nroycea+kernel@xxxxxxxxx>
Reported-by: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Tested-by: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
crypto/xts.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -286,6 +286,13 @@ static void encrypt_done(struct crypto_a
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;

@@ -293,6 +300,7 @@ static void encrypt_done(struct crypto_a
if (rctx->left)
return;

+out:
skcipher_request_complete(req, err);
}

@@ -330,6 +338,13 @@ static void decrypt_done(struct crypto_a
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;

@@ -337,6 +352,7 @@ static void decrypt_done(struct crypto_a
if (rctx->left)
return;

+out:
skcipher_request_complete(req, err);
}