crypto: algif_aead - fix uninitialized ctx->init
PATCH v2 1/1 crypto: algif_aead - fix uninitialized ctx->init
In skcipher_accept_parent_nokey() the whole af_alg_ctx structure is cleared by memset() after allocation, so add such memset() also to aead_accept_parent_nokey() so that the new "init" field is also initialized to zero. Without that the initial ctx->init checks might randomly return true and cause errors.
While there, also remove the redundant zero assignments in both functions.
Found via libkcapi testsuite.
---
v2:
- intead add missing memset() to algif_aead and remove the redundant zero assignments (suggested by Herbert)
crypto/algif_aead.c | 6 ------ crypto/algif_skcipher.c | 7 +------ 2 files changed, 1 insertion(+), 12 deletions(-)
crypto/algif_aead.c +0 -6
@@ -558,12 +558,6 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk)INIT_LIST_HEAD (&ctx->tsgl_list); ctx->len = len; - ctx->used =0 ; -atomic_set (&ctx->rcvused,0 ); - ctx->more =0 ; - ctx->merge =0 ; - ctx->enc =0 ; - ctx->aead_assoclen =0 ;crypto_init_wait (&ctx->wait); ask->private = ctx;
crypto/algif_skcipher.c +1 -6
@@ -333,6 +333,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) ctx =sock_kmalloc (sk, len,GFP_KERNEL );if (!ctx)return -ENOMEM ; +memset (ctx,0 , len); ctx->iv =sock_kmalloc (sk,crypto_skcipher_ivsize (tfm),GFP_KERNEL );
@@ -340,16 +341,10 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk)sock_kfree_s (sk, ctx, len);return -ENOMEM ; } -memset (ctx->iv,0 ,crypto_skcipher_ivsize (tfm));INIT_LIST_HEAD (&ctx->tsgl_list); ctx->len = len; - ctx->used =0 ; -atomic_set (&ctx->rcvused,0 ); - ctx->more =0 ; - ctx->merge =0 ; - ctx->enc =0 ;crypto_init_wait (&ctx->wait); ask->private = ctx;
Signature · 1 line
2.26.2
Herbert Xu
maintainerQuoted 17 lines · Ondrej Mosnacek
In
skcipher_accept_parent_nokey()the wholeaf_alg_ctxstructure is cleared bymemset()after allocation, so add suchmemset()also toaead_accept_parent_nokey()so that the new "init" field is also initialized to zero. Without that the initialctx->initchecks might randomly return true and cause errors.While there, also remove the redundant zero assignments in both functions.
Found via libkcapi testsuite.
Cc Stephan Mueller <[email protected]>Fixes f3c802a1f300 ("crypto: algif_aead - Only wake up when ctx->more is zero")Suggested-by Herbert Xu <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>---
Quoted 7 lines
v2:
- intead add missingmemset()toalgif_aeadand remove the redundant zero assignments (suggested by Herbert)crypto/algif_aead.c | 6 ------ crypto/algif_skcipher.c | 7 +------ 2 files changed, 1 insertion(+), 12 deletions(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt