Skip to content

Commit 67b164a

Browse files
committed
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: 83094e5 ("crypto: af_alg - add async support to algif_aead") Fixes: a596999 ("crypto: algif - change algif_skcipher to be asynchronous") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 431a2eb commit 67b164a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crypto/af_alg.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,13 @@ EXPORT_SYMBOL_GPL(af_alg_sendmsg);
11161116
void af_alg_free_resources(struct af_alg_async_req *areq)
11171117
{
11181118
struct sock *sk = areq->sk;
1119+
struct af_alg_ctx *ctx;
11191120

11201121
af_alg_free_areq_sgls(areq);
11211122
sock_kfree_s(sk, areq, areq->areqlen);
1123+
1124+
ctx = alg_sk(sk)->private;
1125+
ctx->inflight = false;
11221126
}
11231127
EXPORT_SYMBOL_GPL(af_alg_free_resources);
11241128

@@ -1188,11 +1192,19 @@ EXPORT_SYMBOL_GPL(af_alg_poll);
11881192
struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk,
11891193
unsigned int areqlen)
11901194
{
1191-
struct af_alg_async_req *areq = sock_kmalloc(sk, areqlen, GFP_KERNEL);
1195+
struct af_alg_ctx *ctx = alg_sk(sk)->private;
1196+
struct af_alg_async_req *areq;
1197+
1198+
/* Only one AIO request can be in flight. */
1199+
if (ctx->inflight)
1200+
return ERR_PTR(-EBUSY);
11921201

1202+
areq = sock_kmalloc(sk, areqlen, GFP_KERNEL);
11931203
if (unlikely(!areq))
11941204
return ERR_PTR(-ENOMEM);
11951205

1206+
ctx->inflight = true;
1207+
11961208
areq->areqlen = areqlen;
11971209
areq->sk = sk;
11981210
areq->first_rsgl.sgl.sgt.sgl = areq->first_rsgl.sgl.sgl;

include/crypto/if_alg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct af_alg_async_req {
136136
* recvmsg is invoked.
137137
* @init: True if metadata has been sent.
138138
* @len: Length of memory allocated for this data structure.
139+
* @inflight: Non-zero when AIO requests are in flight.
139140
*/
140141
struct af_alg_ctx {
141142
struct list_head tsgl_list;
@@ -154,6 +155,8 @@ struct af_alg_ctx {
154155
bool init;
155156

156157
unsigned int len;
158+
159+
unsigned int inflight;
157160
};
158161

159162
int af_alg_register_type(const struct af_alg_type *type);

0 commit comments

Comments
 (0)