* [PATCH v2 0/2] crypto: pcrypt - Make sure the instance can be found by the requested name
@ 2026-12-04 22:37 Antonio Quartulli
2026-12-04 22:37 ` [PATCH v2 1/2] " Antonio Quartulli
2026-12-04 22:37 ` [PATCH v2 2/2] crypto: tcrypt - Wrap the driver name in the pcrypt speed example Antonio Quartulli
0 siblings, 2 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
v1 refused to wrap a pcrypt instance. As Herbert suggested, patch 1
instead refuses to create an instance that cannot be found under the
requested name. pcrypt keeps the inner cra_name, so this means the inner
algorithm must be named by its driver name.
This can break existing setups, so please decide whether that is
acceptable. Requesting pcrypt with a generic inner name, e.g.
pcrypt(rfc4106(gcm(aes))), has always returned an error (-EAGAIN, or
-ENAMETOOLONG once nesting overflows the name), but as a side effect it
registered a pcrypt instance, which later allocations by the generic name
pick up by priority. Setups may rely on that despite the error. With
patch 1 such requests fail with -EINVAL and register nothing, so those
setups silently stop using pcrypt.
The only in-tree example is the setup in tcrypt_speed_compare.py. Under
virtme-ng on v7.4-rc4, its mode 211 run benchmarks
pcrypt(rfc4106-gcm-aes-lib) before patch 1 and rfc4106-gcm-aes-lib after.
Patch 2 makes it wrap the driver name.
If generic names should keep working, an alternative is to name the
instance after the request (driver name pcrypt(rfc4106(gcm(aes)))) so the
lookup finds it, at the cost of the driver name no longer identifying the
inner implementation.
Tested on v7.4-rc4 with virtme-ng: generic-name requests through
crypto_user NEWALG and AF_ALG fail with -EINVAL and register nothing
(before: one more nesting level per NEWALG); driver-name requests work
as before and pass the selftests; a generic-name request with a pcrypt
instance present no longer nests.
v1: https://lore.kernel.org/linux-crypto/20261124132443.3666372-1-antonio@mandelbit.com/
Antonio Quartulli (2):
crypto: pcrypt - Make sure the instance can be found by the requested
name
crypto: tcrypt - Wrap the driver name in the pcrypt speed example
crypto/pcrypt.c | 17 ++++++++++++++---
tools/crypto/tcrypt/tcrypt_speed_compare.py | 13 +++++++++++--
2 files changed, 25 insertions(+), 5 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [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
end of thread, other threads:[~2026-12-04 22:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 2/2] crypto: tcrypt - Wrap the driver name in the pcrypt speed example Antonio Quartulli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox