Skip to contentSkip to conversation

crypto: simd - reject compat registrations without __ prefixes

PATCH In review Wesley Atwell 2 participants 2 messages Mar 9 – Mar 21 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: simd - reject compat registrations without __ prefixes

simd_register_skciphers_compat() and simd_register_aeads_compat() derive the wrapper algorithm names by stripping the __ prefix from the internal algorithm names.

Currently they only WARN if cra_name or cra_driver_name lacks that prefix, but they still continue and unconditionally add 2 to both strings. That registers wrapper algorithms with incorrectly truncated names after a violated precondition.

Reject such inputs with -EINVAL before registering anything, while keeping the warning so invalid internal API usage is still visible.

Fixes d14f0a1fc488 ("crypto: simd - allow registering multiple algorithms at once")
Fixes 1661131a0479 ("crypto: simd - support wrapping AEAD algorithms")
Assisted-by Codex:GPT-5
---
 crypto/simd.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
crypto/simd.c +12 -4
index f71c4a334c7d..4e6f437e9e77 100644
@@ -214,13 +214,17 @@ int simd_register_skciphers_compat(struct skcipher_alg *algs, int count,
 	const char *basename;
 	struct simd_skcipher_alg *simd;
 
+	for (i = 0; i < count; i++) {
+		if (WARN_ON(strncmp(algs[i].base.cra_name, "__", 2) ||
+			    strncmp(algs[i].base.cra_driver_name, "__", 2)))
+			return -EINVAL;
+	}
+
 	err = crypto_register_skciphers(algs, count);
 	if (err)
 		return err;
 
 	for (i = 0; i < count; i++) {
-		WARN_ON(strncmp(algs[i].base.cra_name, "__", 2));
-		WARN_ON(strncmp(algs[i].base.cra_driver_name, "__", 2));
 		algname = algs[i].base.cra_name + 2;
 		drvname = algs[i].base.cra_driver_name + 2;
 		basename = algs[i].base.cra_driver_name;
@@ -437,13 +441,17 @@ int simd_register_aeads_compat(struct aead_alg *algs, int count,
 	const char *basename;
 	struct simd_aead_alg *simd;
 
+	for (i = 0; i < count; i++) {
+		if (WARN_ON(strncmp(algs[i].base.cra_name, "__", 2) ||
+			    strncmp(algs[i].base.cra_driver_name, "__", 2)))
+			return -EINVAL;
+	}
+
 	err = crypto_register_aeads(algs, count);
 	if (err)
 		return err;
 
 	for (i = 0; i < count; i++) {
-		WARN_ON(strncmp(algs[i].base.cra_name, "__", 2));
-		WARN_ON(strncmp(algs[i].base.cra_driver_name, "__", 2));
 		algname = algs[i].base.cra_name + 2;
 		drvname = algs[i].base.cra_driver_name + 2;
 		basename = algs[i].base.cra_driver_name;

base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 12 lines · Wesley Atwell

simd_register_skciphers_compat() and simd_register_aeads_compat() derive the wrapper algorithm names by stripping the __ prefix from the internal algorithm names.

Currently they only WARN if cra_name or cra_driver_name lacks that prefix, but they still continue and unconditionally add 2 to both strings. That registers wrapper algorithms with incorrectly truncated names after a violated precondition.

Reject such inputs with -EINVAL before registering anything, while keeping the warning so invalid internal API usage is still visible.

Quoted 7 lines
Fixes d14f0a1fc488 ("crypto: simd - allow registering multiple algorithms at once")
Fixes 1661131a0479 ("crypto: simd - support wrapping AEAD algorithms")
Assisted-by Codex:GPT-5
---
 crypto/simd.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt