Skip to content

Commit 6db4341

Browse files
ebiggersherbertx
authored andcommitted
crypto: adiantum - initialize crypto_spawn::inst
crypto_grab_*() doesn't set crypto_spawn::inst, so templates must set it beforehand. Otherwise it will be left NULL, which causes a crash in certain cases where algorithms are dynamically loaded/unloaded. E.g. with CONFIG_CRYPTO_CHACHA20_X86_64=m, the following caused a crash: insmod chacha-x86_64.ko python -c 'import socket; socket.socket(socket.AF_ALG, 5, 0).bind(("skcipher", "adiantum(xchacha12,aes)"))' rmmod chacha-x86_64.ko python -c 'import socket; socket.socket(socket.AF_ALG, 5, 0).bind(("skcipher", "adiantum(xchacha12,aes)"))' Fixes: 059c2a4 ("crypto: adiantum - add Adiantum support") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 06bbf75 commit 6db4341

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

crypto/adiantum.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ static int adiantum_create(struct crypto_template *tmpl, struct rtattr **tb)
539539
ictx = skcipher_instance_ctx(inst);
540540

541541
/* Stream cipher, e.g. "xchacha12" */
542+
crypto_set_skcipher_spawn(&ictx->streamcipher_spawn,
543+
skcipher_crypto_instance(inst));
542544
err = crypto_grab_skcipher(&ictx->streamcipher_spawn, streamcipher_name,
543545
0, crypto_requires_sync(algt->type,
544546
algt->mask));
@@ -547,6 +549,8 @@ static int adiantum_create(struct crypto_template *tmpl, struct rtattr **tb)
547549
streamcipher_alg = crypto_spawn_skcipher_alg(&ictx->streamcipher_spawn);
548550

549551
/* Block cipher, e.g. "aes" */
552+
crypto_set_spawn(&ictx->blockcipher_spawn,
553+
skcipher_crypto_instance(inst));
550554
err = crypto_grab_spawn(&ictx->blockcipher_spawn, blockcipher_name,
551555
CRYPTO_ALG_TYPE_CIPHER, CRYPTO_ALG_TYPE_MASK);
552556
if (err)

0 commit comments

Comments
 (0)