diff options
author | Eric Biggers <ebiggers@google.com> | 2017-11-28 03:46:24 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-11-28 21:39:14 -0500 |
commit | 887207ed9e5812ed9239b6d07185a2d35dda91db (patch) | |
tree | cadb413b15f8fd9699ad3f48638795a7bb9fb31e | |
parent | b32a7dc8aef1882fbf983eb354837488cc9d54dc (diff) |
crypto: af_alg - fix NULL pointer dereference in
af_alg_free_areq_sgls()
If allocating the ->tsgl member of 'struct af_alg_async_req' failed,
during cleanup we dereferenced the NULL ->tsgl pointer in
af_alg_free_areq_sgls(), because ->tsgl_entries was nonzero.
Fix it by only freeing the ->tsgl list if it is non-NULL.
This affected both algif_skcipher and algif_aead.
Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: <stable@vger.kernel.org> # v4.14+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/af_alg.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 85cea9de324a..1e5353f62067 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c | |||
@@ -672,14 +672,15 @@ void af_alg_free_areq_sgls(struct af_alg_async_req *areq) | |||
672 | } | 672 | } |
673 | 673 | ||
674 | tsgl = areq->tsgl; | 674 | tsgl = areq->tsgl; |
675 | for_each_sg(tsgl, sg, areq->tsgl_entries, i) { | 675 | if (tsgl) { |
676 | if (!sg_page(sg)) | 676 | for_each_sg(tsgl, sg, areq->tsgl_entries, i) { |
677 | continue; | 677 | if (!sg_page(sg)) |
678 | put_page(sg_page(sg)); | 678 | continue; |
679 | } | 679 | put_page(sg_page(sg)); |
680 | } | ||
680 | 681 | ||
681 | if (areq->tsgl && areq->tsgl_entries) | ||
682 | sock_kfree_s(sk, tsgl, areq->tsgl_entries * sizeof(*tsgl)); | 682 | sock_kfree_s(sk, tsgl, areq->tsgl_entries * sizeof(*tsgl)); |
683 | } | ||
683 | } | 684 | } |
684 | EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls); | 685 | EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls); |
685 | 686 | ||