diff options
author | Eric Biggers <ebiggers@google.com> | 2017-11-28 00:46:24 -0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-11-29 13:39:14 +1100 |
commit | 45fd92e7cce7ebeaf2f3f9ae60b078dca7b90704 (patch) | |
tree | e2a7d47768fe74bbb30133e1ce09dc4b385ce3ed /crypto | |
parent | 72c557fd09ae25d9396271484a6b2f6417ad851e (diff) | |
download | linux-crypto-45fd92e7cce7ebeaf2f3f9ae60b078dca7b90704.tar.gz linux-crypto-45fd92e7cce7ebeaf2f3f9ae60b078dca7b90704.zip |
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: 8a15a4bf1947 ("crypto: algif_skcipher - overhaul memory management")
Fixes: 0c2a2d0aa6e4 ("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>
Diffstat (limited to '')
-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 85cea9de..1e5353f6 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) } tsgl = areq->tsgl; - for_each_sg(tsgl, sg, areq->tsgl_entries, i) { - if (!sg_page(sg)) - continue; - put_page(sg_page(sg)); - } + if (tsgl) { + for_each_sg(tsgl, sg, areq->tsgl_entries, i) { + if (!sg_page(sg)) + continue; + put_page(sg_page(sg)); + } - if (areq->tsgl && areq->tsgl_entries) sock_kfree_s(sk, tsgl, areq->tsgl_entries * sizeof(*tsgl)); + } } EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls); |