Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 887207ed authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu
Browse files

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: e870456d ("crypto: algif_skcipher - overhaul memory management")
Fixes: d887c52d ("crypto: algif_aead - overhaul memory management")
Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
Cc: <stable@vger.kernel.org> # v4.14+
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarStephan Mueller <smueller@chronox.de>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent b32a7dc8
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -672,15 +672,16 @@ void af_alg_free_areq_sgls(struct af_alg_async_req *areq)
	}

	tsgl = areq->tsgl;
	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);

/**