Commit 9b8c456e authored by Herbert Xu's avatar Herbert Xu

crypto: cryptd - Use crypto_grab_aead

As AEAD has switched over to using frontend types, the function
crypto_init_spawn must not be used since it does not specify a
frontend type.  Otherwise it leads to a crash when the spawn is
used.

This patch fixes it by switching over to crypto_grab_aead instead.

Fixes: 5d1d65f8 ("crypto: aead - Convert top level interface to new style")
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 05767229
...@@ -295,6 +295,23 @@ static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm) ...@@ -295,6 +295,23 @@ static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm)
crypto_free_blkcipher(ctx->child); crypto_free_blkcipher(ctx->child);
} }
static int cryptd_init_instance(struct crypto_instance *inst,
struct crypto_alg *alg)
{
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"cryptd(%s)",
alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
return -ENAMETOOLONG;
memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
inst->alg.cra_priority = alg->cra_priority + 50;
inst->alg.cra_blocksize = alg->cra_blocksize;
inst->alg.cra_alignmask = alg->cra_alignmask;
return 0;
}
static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head, static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head,
unsigned int tail) unsigned int tail)
{ {
...@@ -308,17 +325,10 @@ static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head, ...@@ -308,17 +325,10 @@ static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head,
inst = (void *)(p + head); inst = (void *)(p + head);
err = -ENAMETOOLONG; err = cryptd_init_instance(inst, alg);
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, if (err)
"cryptd(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
goto out_free_inst; goto out_free_inst;
memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
inst->alg.cra_priority = alg->cra_priority + 50;
inst->alg.cra_blocksize = alg->cra_blocksize;
inst->alg.cra_alignmask = alg->cra_alignmask;
out: out:
return p; return p;
...@@ -747,29 +757,34 @@ static int cryptd_create_aead(struct crypto_template *tmpl, ...@@ -747,29 +757,34 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
struct aead_instance_ctx *ctx; struct aead_instance_ctx *ctx;
struct crypto_instance *inst; struct crypto_instance *inst;
struct crypto_alg *alg; struct crypto_alg *alg;
u32 type = CRYPTO_ALG_TYPE_AEAD; const char *name;
u32 mask = CRYPTO_ALG_TYPE_MASK; u32 type = 0;
u32 mask = 0;
int err; int err;
cryptd_check_internal(tb, &type, &mask); cryptd_check_internal(tb, &type, &mask);
alg = crypto_get_attr_alg(tb, type, mask); name = crypto_attr_alg_name(tb[1]);
if (IS_ERR(alg)) if (IS_ERR(name))
return PTR_ERR(alg); return PTR_ERR(name);
inst = cryptd_alloc_instance(alg, 0, sizeof(*ctx)); inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
err = PTR_ERR(inst); if (!inst)
if (IS_ERR(inst)) return -ENOMEM;
goto out_put_alg;
ctx = crypto_instance_ctx(inst); ctx = crypto_instance_ctx(inst);
ctx->queue = queue; ctx->queue = queue;
err = crypto_init_spawn(&ctx->aead_spawn.base, alg, inst, crypto_set_aead_spawn(&ctx->aead_spawn, inst);
CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); err = crypto_grab_aead(&ctx->aead_spawn, name, type, mask);
if (err) if (err)
goto out_free_inst; goto out_free_inst;
alg = crypto_aead_spawn_alg(&ctx->aead_spawn);
err = cryptd_init_instance(inst, alg);
if (err)
goto out_drop_aead;
type = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; type = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC;
if (alg->cra_flags & CRYPTO_ALG_INTERNAL) if (alg->cra_flags & CRYPTO_ALG_INTERNAL)
type |= CRYPTO_ALG_INTERNAL; type |= CRYPTO_ALG_INTERNAL;
...@@ -790,12 +805,11 @@ static int cryptd_create_aead(struct crypto_template *tmpl, ...@@ -790,12 +805,11 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
err = crypto_register_instance(tmpl, inst); err = crypto_register_instance(tmpl, inst);
if (err) { if (err) {
crypto_drop_spawn(&ctx->aead_spawn.base); out_drop_aead:
crypto_drop_aead(&ctx->aead_spawn);
out_free_inst: out_free_inst:
kfree(inst); kfree(inst);
} }
out_put_alg:
crypto_mod_put(alg);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment