]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: af_alg - zero initialize memory allocated via sock_kmalloc
authorShivani Agarwal <shivani.agarwal@broadcom.com>
Wed, 24 Sep 2025 06:01:48 +0000 (23:01 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 17 Oct 2025 08:03:57 +0000 (16:03 +0800)
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.

Fixes: fe869cdb89c9 ("crypto: algif_hash - User-space interface for hash operations")
Fixes: 5afdfd22e6ba ("crypto: algif_rng - add random number generator support")
Fixes: 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code")
Fixes: 67b164a871af ("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>
crypto/af_alg.c
crypto/algif_hash.c
crypto/algif_rng.c

index ca6fdcc6c54aca6825b8db7546e809e99dc3285e..6c271e55f44d94e5bfc716933e45d71cdb86a549 100644 (file)
@@ -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;
 }
index e3f1a4852737b02294be94d9a9300faee1b7c3b4..4d3dfc60a16a6d8b677d903d209df18d67202c98 100644 (file)
@@ -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;
index 10c41adac3b1f3574494ad71ce65f6e4db383997..1a86e40c8372e569a9008a5025bfc8406d18d24d 100644 (file)
@@ -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