Message ID | 20190920043556.GP2879@gauss3.secunet.de (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Herbert Xu |
Headers | show |
Series | crypto: pcrypt - forbid recursive instantiation | expand |
On Fri, Sep 20, 2019 at 06:35:56AM +0200, Steffen Klassert wrote: > > Fix this by making pcrypt forbid instantiation if pcrypt appears in the > underlying ->cra_driver_name or if an underlying algorithm needs a > fallback. This is somewhat of a hack, but it's a simple fix that should > be sufficient to prevent the deadlock. This still doesn't resolve the case where pcrypt is used in a non-transparent fashion, e.g., through a fallback. Note that even adding a NEED_FALLBACK flag won't fix this as you can construct an instance on top of a NEED_FALLBACK algorithm that itself does not need a fallback. Anyway I decided to change pcrypt to use a set of queues per instance rather than globally and it should resolve the problem. Cheers,
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c index 543792e0ebf0..932a77b61b47 100644 --- a/crypto/pcrypt.c +++ b/crypto/pcrypt.c @@ -198,6 +198,12 @@ static void pcrypt_free(struct aead_instance *inst) static int pcrypt_init_instance(struct crypto_instance *inst, struct crypto_alg *alg) { + /* Recursive pcrypt deadlocks due to the shared padata_instance */ + if (!strncmp(alg->cra_driver_name, "pcrypt(", 7) || + strstr(alg->cra_driver_name, "(pcrypt(") || + strstr(alg->cra_driver_name, ",pcrypt(")) + return -EINVAL; + if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "pcrypt(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) return -ENAMETOOLONG; @@ -236,7 +242,7 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb, ctx = aead_instance_ctx(inst); crypto_set_aead_spawn(&ctx->spawn, aead_crypto_instance(inst)); - err = crypto_grab_aead(&ctx->spawn, name, 0, 0); + err = crypto_grab_aead(&ctx->spawn, name, 0, CRYPTO_ALG_NEED_FALLBACK); if (err) goto out_free_inst;