Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@mandelbit.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>
Cc: Antonio Quartulli <antonio@mandelbit.com>,
	"David S. Miller" <davem@davemloft.net>,
	Wang Jinchao <wangjinchao@xfusion.com>,
	linux-crypto@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v2 1/2] crypto: pcrypt - Make sure the instance can be found by the requested name
Date: Fri,  4 Dec 2026 23:37:32 +0100	[thread overview]
Message-ID: <20261204223734.4111964-2-antonio@mandelbit.com> (raw)
In-Reply-To: <20261204223734.4111964-1-antonio@mandelbit.com>

A pcrypt instance keeps the cra_name of the algorithm it wraps and
derives its driver name from the inner driver name. When pcrypt is
requested with a generic inner name, neither name matches the request,
so the new instance cannot be found and the lookup is retried. The next
instance then wraps the previous one, now the highest-priority match,
until the driver name overflows.

Refuse to create an instance that cannot be found under the requested
name, i.e. require the inner algorithm to be named by its driver name.

Fixes: 5068c7a883d1 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper")
Cc: stable@vger.kernel.org
Suggested-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v2:
- check that the instance can be found under the requested name instead of
  refusing to wrap a pcrypt instance (Herbert)

 crypto/pcrypt.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index 9f372442981e..292466f92063 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -226,8 +226,16 @@ static void pcrypt_free(struct aead_instance *inst)
 }
 
 static int pcrypt_init_instance(struct crypto_instance *inst,
-				struct crypto_alg *alg)
+				struct crypto_alg *alg, const char *name)
 {
+	/*
+	 * The instance keeps the cra_name of the inner algorithm, so it can
+	 * only be found under the requested name through its driver name.
+	 * That requires the inner algorithm to be named by its driver name.
+	 */
+	if (strcmp(alg->cra_driver_name, name))
+		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;
@@ -248,6 +256,7 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
 	struct aead_instance *inst;
 	struct aead_alg *alg;
 	u32 mask = crypto_algt_inherited_mask(algt);
+	const char *name;
 	int err;
 
 	inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
@@ -265,13 +274,15 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
 	if (!ctx->psdec)
 		goto err_free_inst;
 
+	name = crypto_attr_alg_name(tb[1]);
 	err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst),
-			       crypto_attr_alg_name(tb[1]), 0, mask);
+			       name, 0, mask);
 	if (err)
 		goto err_free_inst;
 
 	alg = crypto_spawn_aead_alg(&ctx->spawn);
-	err = pcrypt_init_instance(aead_crypto_instance(inst), &alg->base);
+	err = pcrypt_init_instance(aead_crypto_instance(inst), &alg->base,
+				   name);
 	if (err)
 		goto err_free_inst;
 
-- 
2.56.1


  reply	other threads:[~2026-12-04 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 22:37 [PATCH v2 0/2] crypto: pcrypt - Make sure the instance can be found by the requested name Antonio Quartulli
2026-12-04 22:37 ` Antonio Quartulli [this message]
2026-12-04 22:37 ` [PATCH v2 2/2] crypto: tcrypt - Wrap the driver name in the pcrypt speed example Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204223734.4111964-2-antonio@mandelbit.com \
    --to=antonio@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=wangjinchao@xfusion.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox