* [PATCH v2 1/2] crypto: pcrypt - Make sure the instance can be found by the requested name
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
2026-12-04 22:37 ` [PATCH v2 2/2] crypto: tcrypt - Wrap the driver name in the pcrypt speed example Antonio Quartulli
1 sibling, 0 replies; 3+ messages in thread
From: Antonio Quartulli @ 2026-12-04 22:37 UTC (permalink / raw)
To: Herbert Xu, Steffen Klassert
Cc: Antonio Quartulli, David S. Miller, Wang Jinchao, linux-crypto,
stable
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2 2/2] crypto: tcrypt - Wrap the driver name in the pcrypt speed example
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 ` [PATCH v2 1/2] " Antonio Quartulli
@ 2026-12-04 22:37 ` Antonio Quartulli
1 sibling, 0 replies; 3+ messages in thread
From: Antonio Quartulli @ 2026-12-04 22:37 UTC (permalink / raw)
To: Herbert Xu, Steffen Klassert
Cc: Antonio Quartulli, David S. Miller, Wang Jinchao, linux-crypto
pcrypt now refuses a generic inner algorithm name, so the example setup
in tcrypt_speed_compare.py no longer creates a pcrypt instance and the
benchmark silently measures rfc4106(gcm(aes)) without pcrypt.
Look up the driver name of rfc4106(gcm(aes)) and wrap that instead.
Cc: Wang Jinchao <wangjinchao@xfusion.com>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
tools/crypto/tcrypt/tcrypt_speed_compare.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/crypto/tcrypt/tcrypt_speed_compare.py b/tools/crypto/tcrypt/tcrypt_speed_compare.py
index f3f5783cdc06..2accb80bab01 100755
--- a/tools/crypto/tcrypt/tcrypt_speed_compare.py
+++ b/tools/crypto/tcrypt/tcrypt_speed_compare.py
@@ -27,17 +27,26 @@ sec=0
num_mb=8
mode=211
+# pcrypt must be given the driver name of the algorithm it wraps
+setup_pcrypt() {
+ modprobe tcrypt alg="rfc4106(gcm(aes))" type=3
+ drv=$(awk -F': ' '/^name/ { n = $2 } /^driver/ { d = $2 }
+ /^priority/ && n == "rfc4106(gcm(aes))" && d !~ /^pcrypt/ &&
+ $2 + 0 > p { p = $2 + 0; best = d } END { print best }' /proc/crypto)
+ modprobe tcrypt alg="pcrypt($drv)" type=3
+}
+
# base speed test
lsmod | grep pcrypt && modprobe -r pcrypt
dmesg -C
-modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
+setup_pcrypt
modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
dmesg > ${seq_num}_base_dmesg.log
# new speed test
lsmod | grep pcrypt && modprobe -r pcrypt
dmesg -C
-modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
+setup_pcrypt
modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
dmesg > ${seq_num}_new_dmesg.log
lsmod | grep pcrypt && modprobe -r pcrypt
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread