Commit 67b164a8 authored by Herbert Xu's avatar Herbert Xu

crypto: af_alg - Disallow multiple in-flight AIO requests

Having multiple in-flight AIO requests results in unpredictable
output because they all share the same IV.  Fix this by only allowing
one request at a time.

Fixes: 83094e5e ("crypto: af_alg - add async support to algif_aead")
Fixes: a596999b ("crypto: algif - change algif_skcipher to be asynchronous")
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 431a2eb8
...@@ -1116,9 +1116,13 @@ EXPORT_SYMBOL_GPL(af_alg_sendmsg); ...@@ -1116,9 +1116,13 @@ EXPORT_SYMBOL_GPL(af_alg_sendmsg);
void af_alg_free_resources(struct af_alg_async_req *areq) void af_alg_free_resources(struct af_alg_async_req *areq)
{ {
struct sock *sk = areq->sk; struct sock *sk = areq->sk;
struct af_alg_ctx *ctx;
af_alg_free_areq_sgls(areq); af_alg_free_areq_sgls(areq);
sock_kfree_s(sk, areq, areq->areqlen); sock_kfree_s(sk, areq, areq->areqlen);
ctx = alg_sk(sk)->private;
ctx->inflight = false;
} }
EXPORT_SYMBOL_GPL(af_alg_free_resources); EXPORT_SYMBOL_GPL(af_alg_free_resources);
...@@ -1188,11 +1192,19 @@ EXPORT_SYMBOL_GPL(af_alg_poll); ...@@ -1188,11 +1192,19 @@ EXPORT_SYMBOL_GPL(af_alg_poll);
struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk, struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk,
unsigned int areqlen) unsigned int areqlen)
{ {
struct af_alg_async_req *areq = sock_kmalloc(sk, areqlen, GFP_KERNEL); struct af_alg_ctx *ctx = alg_sk(sk)->private;
struct af_alg_async_req *areq;
/* Only one AIO request can be in flight. */
if (ctx->inflight)
return ERR_PTR(-EBUSY);
areq = sock_kmalloc(sk, areqlen, GFP_KERNEL);
if (unlikely(!areq)) if (unlikely(!areq))
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ctx->inflight = true;
areq->areqlen = areqlen; areq->areqlen = areqlen;
areq->sk = sk; areq->sk = sk;
areq->first_rsgl.sgl.sgt.sgl = areq->first_rsgl.sgl.sgl; areq->first_rsgl.sgl.sgt.sgl = areq->first_rsgl.sgl.sgl;
......
...@@ -136,6 +136,7 @@ struct af_alg_async_req { ...@@ -136,6 +136,7 @@ struct af_alg_async_req {
* recvmsg is invoked. * recvmsg is invoked.
* @init: True if metadata has been sent. * @init: True if metadata has been sent.
* @len: Length of memory allocated for this data structure. * @len: Length of memory allocated for this data structure.
* @inflight: Non-zero when AIO requests are in flight.
*/ */
struct af_alg_ctx { struct af_alg_ctx {
struct list_head tsgl_list; struct list_head tsgl_list;
...@@ -154,6 +155,8 @@ struct af_alg_ctx { ...@@ -154,6 +155,8 @@ struct af_alg_ctx {
bool init; bool init;
unsigned int len; unsigned int len;
unsigned int inflight;
}; };
int af_alg_register_type(const struct af_alg_type *type); int af_alg_register_type(const struct af_alg_type *type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment