A pcrypt instance keeps the cra_name of the algorithm it wraps. When pcrypt is requested with a generic inner name, the new instance cannot be found by the requested name, so the request is retried and the next instance wraps the previous one, now the highest-priority match. Each retry adds a nesting level until the driver name overflows. Nesting pcrypt is pointless, so refuse it. Fixes: 5068c7a883d1 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper") Cc: stable@vger.kernel.org Signed-off-by: Antonio Quartulli --- Found while enabling pcrypt for rfc7539(chacha20,poly1305) on 6.18: an AF_ALG bind of "pcrypt(rfc7539(chacha20,poly1305))" left 11 nested instances and failed with -ENAMETOOLONG. On v7.4-rc4 the same happens through crypto_user: each CRYPTO_MSG_NEWALG for that name adds a level. With this patch only one instance is created. crypto/pcrypt.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c index 9f372442981e..d2acc64bcee3 100644 --- a/crypto/pcrypt.c +++ b/crypto/pcrypt.c @@ -271,6 +271,15 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb, goto err_free_inst; alg = crypto_spawn_aead_alg(&ctx->spawn); + + /* + * A pcrypt instance keeps the cra_name of the algorithm it wraps, so + * the inner lookup can return an existing pcrypt instance. Do not nest. + */ + err = -EEXIST; + if (strstarts(alg->base.cra_driver_name, "pcrypt(")) + goto err_free_inst; + err = pcrypt_init_instance(aead_crypto_instance(inst), &alg->base); if (err) goto err_free_inst; -- 2.56.1