Skip to content

Commit 51a5ab3

Browse files
shivania2gregkh
authored andcommitted
crypto: af_alg - zero initialize memory allocated via sock_kmalloc
commit 6f6e309 upstream. Several crypto user API contexts and requests allocated with sock_kmalloc() were left uninitialized, relying on callers to set fields explicitly. This resulted in the use of uninitialized data in certain error paths or when new fields are added in the future. The ACVP patches also contain two user-space interface files: algif_kpp.c and algif_akcipher.c. These too rely on proper initialization of their context structures. A particular issue has been observed with the newly added 'inflight' variable introduced in af_alg_ctx by commit: 67b164a ("crypto: af_alg - Disallow multiple in-flight AIO requests") Because the context is not memset to zero after allocation, the inflight variable has contained garbage values. As a result, af_alg_alloc_areq() has incorrectly returned -EBUSY randomly when the garbage value was interpreted as true: https://github.com/gregkh/linux/blame/master/crypto/af_alg.c#L1209 The check directly tests ctx->inflight without explicitly comparing against true/false. Since inflight is only ever set to true or false later, an uninitialized value has triggered -EBUSY failures. Zero-initializing memory allocated with sock_kmalloc() ensures inflight and other fields start in a known state, removing random issues caused by uninitialized data. Fixes: fe869cd ("crypto: algif_hash - User-space interface for hash operations") Fixes: 5afdfd2 ("crypto: algif_rng - add random number generator support") Fixes: 2d97591 ("crypto: af_alg - consolidation of duplicate code") Fixes: 67b164a ("crypto: af_alg - Disallow multiple in-flight AIO requests") Cc: stable@vger.kernel.org Signed-off-by: Shivani Agarwal <shivani.agarwal@broadcom.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c549b9e commit 51a5ab3

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

crypto/af_alg.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,14 @@ struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk,
12121212
if (unlikely(!areq))
12131213
return ERR_PTR(-ENOMEM);
12141214

1215+
memset(areq, 0, areqlen);
1216+
12151217
ctx->inflight = true;
12161218

12171219
areq->areqlen = areqlen;
12181220
areq->sk = sk;
12191221
areq->first_rsgl.sgl.sgt.sgl = areq->first_rsgl.sgl.sgl;
1220-
areq->last_rsgl = NULL;
12211222
INIT_LIST_HEAD(&areq->rsgl_list);
1222-
areq->tsgl = NULL;
1223-
areq->tsgl_entries = 0;
12241223

12251224
return areq;
12261225
}

crypto/algif_hash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,8 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk)
416416
if (!ctx)
417417
return -ENOMEM;
418418

419-
ctx->result = NULL;
419+
memset(ctx, 0, len);
420420
ctx->len = len;
421-
ctx->more = false;
422421
crypto_init_wait(&ctx->wait);
423422

424423
ask->private = ctx;

crypto/algif_rng.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ static int rng_accept_parent(void *private, struct sock *sk)
248248
if (!ctx)
249249
return -ENOMEM;
250250

251+
memset(ctx, 0, len);
251252
ctx->len = len;
252-
ctx->addtl = NULL;
253-
ctx->addtl_len = 0;
254253

255254
/*
256255
* No seeding done at that point -- if multiple accepts are

0 commit comments

Comments
 (0)