Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

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>

authored by

Shivani Agarwal and committed by
Herbert Xu
6f6e3093 e74b96d7

+4 -7
+2 -3
crypto/af_alg.c
··· 1212 1212 if (unlikely(!areq)) 1213 1213 return ERR_PTR(-ENOMEM); 1214 1214 1215 + memset(areq, 0, areqlen); 1216 + 1215 1217 ctx->inflight = true; 1216 1218 1217 1219 areq->areqlen = areqlen; 1218 1220 areq->sk = sk; 1219 1221 areq->first_rsgl.sgl.sgt.sgl = areq->first_rsgl.sgl.sgl; 1220 - areq->last_rsgl = NULL; 1221 1222 INIT_LIST_HEAD(&areq->rsgl_list); 1222 - areq->tsgl = NULL; 1223 - areq->tsgl_entries = 0; 1224 1223 1225 1224 return areq; 1226 1225 }
+1 -2
crypto/algif_hash.c
··· 416 416 if (!ctx) 417 417 return -ENOMEM; 418 418 419 - ctx->result = NULL; 419 + memset(ctx, 0, len); 420 420 ctx->len = len; 421 - ctx->more = false; 422 421 crypto_init_wait(&ctx->wait); 423 422 424 423 ask->private = ctx;
+1 -2
crypto/algif_rng.c
··· 248 248 if (!ctx) 249 249 return -ENOMEM; 250 250 251 + memset(ctx, 0, len); 251 252 ctx->len = len; 252 - ctx->addtl = NULL; 253 - ctx->addtl_len = 0; 254 253 255 254 /* 256 255 * No seeding done at that point -- if multiple accepts are