FAILED: patch "[PATCH] crypto: af_alg - zero initialize memory allocated via" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 6f6e309328d53a10c0fe1f77dec2db73373179b6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025122930-sinner-squad-c6cd@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 6f6e309328d53a10c0fe1f77dec2db73373179b6 Mon Sep 17 00:00:00 2001
From: Shivani Agarwal <[email protected]>
Date: Tue, 23 Sep 2025 23:01:48 -0700
Subject: [PATCH] crypto: af_alg - zero initialize memory allocated via
sock_kmalloc
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:
67b164a871af ("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.
crypto/af_alg.c +2 -3
@@ -1212,15 +1212,14 @@ struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk,if (unlikely (!areq))return ERR_PTR (-ENOMEM ); +memset (areq,0 , areqlen); + ctx->inflight = true; areq->areqlen = areqlen; areq->sk = sk; areq->first_rsgl.sgl.sgt.sgl = areq->first_rsgl.sgl.sgl; - areq->last_rsgl =NULL ;INIT_LIST_HEAD (&areq->rsgl_list); - areq->tsgl =NULL ; - areq->tsgl_entries =0 ;return areq; }
crypto/algif_hash.c +1 -2
@@ -416,9 +416,8 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk)if (!ctx)return -ENOMEM ; - ctx->result =NULL ; +memset (ctx,0 , len); ctx->len = len; - ctx->more = false;crypto_init_wait (&ctx->wait); ask->private = ctx;
crypto/algif_rng.c +1 -2
@@ -248,9 +248,8 @@ static int rng_accept_parent(void *private, struct sock *sk)if (!ctx)return -ENOMEM ; +memset (ctx,0 , len); ctx->len = len; - ctx->addtl =NULL ; - ctx->addtl_len =0 ;/* * No seeding done at that point -- if multiple accepts are
Sasha Levin
maintainerPATCH 1/1 crypto: af_alg - zero initialize memory allocated via sock_kmalloc
From: Shivani Agarwal <[email protected]>
[ Upstream commit 6f6e309328d53a10c0fe1f77dec2db73373179b6 ]
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:
67b164a871af ("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.
--- crypto/af_alg.c | 5 ++--- crypto/algif_hash.c | 3 +-- crypto/algif_rng.c | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-)
crypto/af_alg.c +2 -3
@@ -1127,14 +1127,13 @@ struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk,if (unlikely (!areq))return ERR_PTR (-ENOMEM ); +memset (areq,0 , areqlen); + ctx->inflight = true; areq->areqlen = areqlen; areq->sk = sk; - areq->last_rsgl =NULL ;INIT_LIST_HEAD (&areq->rsgl_list); - areq->tsgl =NULL ; - areq->tsgl_entries =0 ;return areq; }
crypto/algif_hash.c +1 -2
@@ -423,9 +423,8 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk)if (!ctx)return -ENOMEM ; - ctx->result =NULL ; +memset (ctx,0 , len); ctx->len = len; - ctx->more = false;crypto_init_wait (&ctx->wait); ask->private = ctx;
crypto/algif_rng.c +1 -2
@@ -250,9 +250,8 @@ static int rng_accept_parent(void *private, struct sock *sk)if (!ctx)return -ENOMEM ; +memset (ctx,0 , len); ctx->len = len; - ctx->addtl =NULL ; - ctx->addtl_len =0 ;/* * No seeding done at that point -- if multiple accepts are
Signature · 1 line
2.51.0