diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2015-05-21 03:10:57 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-05-21 23:25:49 -0400 |
commit | 9b8c456e081e7eca856ad9b2a92980a68887f533 (patch) | |
tree | 347444e7ef5c16cbe586527f84f95f0f69557ac1 /crypto/cryptd.c | |
parent | 0576722919f13da8430d00e47aa58ba151505d90 (diff) |
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: 5d1d65f8bea6 ("crypto: aead - Convert top level interface to new style")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cryptd.c')
-rw-r--r-- | crypto/cryptd.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/crypto/cryptd.c b/crypto/cryptd.c index e1584fb5ba34..4264c8d9c97d 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c | |||
@@ -295,6 +295,23 @@ static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm) | |||
295 | crypto_free_blkcipher(ctx->child); | 295 | crypto_free_blkcipher(ctx->child); |
296 | } | 296 | } |
297 | 297 | ||
298 | static int cryptd_init_instance(struct crypto_instance *inst, | ||
299 | struct crypto_alg *alg) | ||
300 | { | ||
301 | if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | ||
302 | "cryptd(%s)", | ||
303 | alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) | ||
304 | return -ENAMETOOLONG; | ||
305 | |||
306 | memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); | ||
307 | |||
308 | inst->alg.cra_priority = alg->cra_priority + 50; | ||
309 | inst->alg.cra_blocksize = alg->cra_blocksize; | ||
310 | inst->alg.cra_alignmask = alg->cra_alignmask; | ||
311 | |||
312 | return 0; | ||
313 | } | ||
314 | |||
298 | static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head, | 315 | static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head, |
299 | unsigned int tail) | 316 | unsigned int tail) |
300 | { | 317 | { |
@@ -308,17 +325,10 @@ static void *cryptd_alloc_instance(struct crypto_alg *alg, unsigned int head, | |||
308 | 325 | ||
309 | inst = (void *)(p + head); | 326 | inst = (void *)(p + head); |
310 | 327 | ||
311 | err = -ENAMETOOLONG; | 328 | err = cryptd_init_instance(inst, alg); |
312 | if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | 329 | if (err) |
313 | "cryptd(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) | ||
314 | goto out_free_inst; | 330 | goto out_free_inst; |
315 | 331 | ||
316 | memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); | ||
317 | |||
318 | inst->alg.cra_priority = alg->cra_priority + 50; | ||
319 | inst->alg.cra_blocksize = alg->cra_blocksize; | ||
320 | inst->alg.cra_alignmask = alg->cra_alignmask; | ||
321 | |||
322 | out: | 332 | out: |
323 | return p; | 333 | return p; |
324 | 334 | ||
@@ -747,29 +757,34 @@ static int cryptd_create_aead(struct crypto_template *tmpl, | |||
747 | struct aead_instance_ctx *ctx; | 757 | struct aead_instance_ctx *ctx; |
748 | struct crypto_instance *inst; | 758 | struct crypto_instance *inst; |
749 | struct crypto_alg *alg; | 759 | struct crypto_alg *alg; |
750 | u32 type = CRYPTO_ALG_TYPE_AEAD; | 760 | const char *name; |
751 | u32 mask = CRYPTO_ALG_TYPE_MASK; | 761 | u32 type = 0; |
762 | u32 mask = 0; | ||
752 | int err; | 763 | int err; |
753 | 764 | ||
754 | cryptd_check_internal(tb, &type, &mask); | 765 | cryptd_check_internal(tb, &type, &mask); |
755 | 766 | ||
756 | alg = crypto_get_attr_alg(tb, type, mask); | 767 | name = crypto_attr_alg_name(tb[1]); |
757 | if (IS_ERR(alg)) | 768 | if (IS_ERR(name)) |
758 | return PTR_ERR(alg); | 769 | return PTR_ERR(name); |
759 | 770 | ||
760 | inst = cryptd_alloc_instance(alg, 0, sizeof(*ctx)); | 771 | inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); |
761 | err = PTR_ERR(inst); | 772 | if (!inst) |
762 | if (IS_ERR(inst)) | 773 | return -ENOMEM; |
763 | goto out_put_alg; | ||
764 | 774 | ||
765 | ctx = crypto_instance_ctx(inst); | 775 | ctx = crypto_instance_ctx(inst); |
766 | ctx->queue = queue; | 776 | ctx->queue = queue; |
767 | 777 | ||
768 | err = crypto_init_spawn(&ctx->aead_spawn.base, alg, inst, | 778 | crypto_set_aead_spawn(&ctx->aead_spawn, inst); |
769 | CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 779 | err = crypto_grab_aead(&ctx->aead_spawn, name, type, mask); |
770 | if (err) | 780 | if (err) |
771 | goto out_free_inst; | 781 | goto out_free_inst; |
772 | 782 | ||
783 | alg = crypto_aead_spawn_alg(&ctx->aead_spawn); | ||
784 | err = cryptd_init_instance(inst, alg); | ||
785 | if (err) | ||
786 | goto out_drop_aead; | ||
787 | |||
773 | type = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; | 788 | type = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; |
774 | if (alg->cra_flags & CRYPTO_ALG_INTERNAL) | 789 | if (alg->cra_flags & CRYPTO_ALG_INTERNAL) |
775 | type |= CRYPTO_ALG_INTERNAL; | 790 | type |= CRYPTO_ALG_INTERNAL; |
@@ -790,12 +805,11 @@ static int cryptd_create_aead(struct crypto_template *tmpl, | |||
790 | 805 | ||
791 | err = crypto_register_instance(tmpl, inst); | 806 | err = crypto_register_instance(tmpl, inst); |
792 | if (err) { | 807 | if (err) { |
793 | crypto_drop_spawn(&ctx->aead_spawn.base); | 808 | out_drop_aead: |
809 | crypto_drop_aead(&ctx->aead_spawn); | ||
794 | out_free_inst: | 810 | out_free_inst: |
795 | kfree(inst); | 811 | kfree(inst); |
796 | } | 812 | } |
797 | out_put_alg: | ||
798 | crypto_mod_put(alg); | ||
799 | return err; | 813 | return err; |
800 | } | 814 | } |
801 | 815 | ||