All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] crypto: make cra_driver_name mandatory
@ 2019-06-03  5:40 Eric Biggers
  2019-06-03  5:40 ` [PATCH 1/2] crypto: make all generic algorithms set cra_driver_name Eric Biggers
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Biggers @ 2019-06-03  5:40 UTC (permalink / raw)
  To: linux-crypto

Most generic crypto algorithms declare a driver name ending in
"-generic".  The rest don't declare a driver name and instead rely on
the crypto API automagically appending "-generic" upon registration.

Having multiple conventions is unnecessarily confusing and makes it
harder to grep for all generic algorithms in the kernel source tree.
But also, allowing NULL driver names is problematic because sometimes
people fail to set it, e.g. the case fixed by commit 417980364300
("crypto: cavium/zip - fix collision with generic cra_driver_name").

Of course, people can also incorrectly name their drivers "-generic".
But that's much easier to notice / grep for.

Therefore, let's make cra_driver_name mandatory.  Patch 1 gives all
generic algorithms an explicit cra_driver_name, and Patch 2 makes
cra_driver_name required for algorithm registration.

Eric Biggers (2):
  crypto: make all generic algorithms set cra_driver_name
  crypto: algapi - require cra_name and cra_driver_name

 crypto/algapi.c          | 22 ++++------------------
 crypto/anubis.c          |  1 +
 crypto/arc4.c            |  2 ++
 crypto/crypto_null.c     |  3 +++
 crypto/deflate.c         |  1 +
 crypto/fcrypt.c          |  1 +
 crypto/khazad.c          |  1 +
 crypto/lz4.c             |  1 +
 crypto/lz4hc.c           |  1 +
 crypto/lzo-rle.c         |  1 +
 crypto/lzo.c             |  1 +
 crypto/md4.c             |  7 ++++---
 crypto/md5.c             |  7 ++++---
 crypto/michael_mic.c     |  1 +
 crypto/rmd128.c          |  1 +
 crypto/rmd160.c          |  1 +
 crypto/rmd256.c          |  1 +
 crypto/rmd320.c          |  1 +
 crypto/serpent_generic.c |  1 +
 crypto/tea.c             |  3 +++
 crypto/tgr192.c          | 21 ++++++++++++---------
 crypto/wp512.c           | 21 ++++++++++++---------
 crypto/zstd.c            |  1 +
 23 files changed, 59 insertions(+), 42 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] crypto: make all generic algorithms set cra_driver_name
  2019-06-03  5:40 [PATCH 0/2] crypto: make cra_driver_name mandatory Eric Biggers
@ 2019-06-03  5:40 ` Eric Biggers
  2019-06-03  5:40 ` [PATCH 2/2] crypto: algapi - require cra_name and cra_driver_name Eric Biggers
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2019-06-03  5:40 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Most generic crypto algorithms declare a driver name ending in
"-generic".  The rest don't declare a driver name and instead rely on
the crypto API automagically appending "-generic" upon registration.

Having multiple conventions is unnecessarily confusing and makes it
harder to grep for all generic algorithms in the kernel source tree.
But also, allowing NULL driver names is problematic because sometimes
people fail to set it, e.g. the case fixed by commit 417980364300
("crypto: cavium/zip - fix collision with generic cra_driver_name").

Of course, people can also incorrectly name their drivers "-generic".
But that's much easier to notice / grep for.

Therefore, let's make cra_driver_name mandatory.  In preparation for
this, this patch makes all generic algorithms set cra_driver_name.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/anubis.c          |  1 +
 crypto/arc4.c            |  2 ++
 crypto/crypto_null.c     |  3 +++
 crypto/deflate.c         |  1 +
 crypto/fcrypt.c          |  1 +
 crypto/khazad.c          |  1 +
 crypto/lz4.c             |  1 +
 crypto/lz4hc.c           |  1 +
 crypto/lzo-rle.c         |  1 +
 crypto/lzo.c             |  1 +
 crypto/md4.c             |  7 ++++---
 crypto/md5.c             |  7 ++++---
 crypto/michael_mic.c     |  1 +
 crypto/rmd128.c          |  1 +
 crypto/rmd160.c          |  1 +
 crypto/rmd256.c          |  1 +
 crypto/rmd320.c          |  1 +
 crypto/serpent_generic.c |  1 +
 crypto/tea.c             |  3 +++
 crypto/tgr192.c          | 21 ++++++++++++---------
 crypto/wp512.c           | 21 ++++++++++++---------
 crypto/zstd.c            |  1 +
 22 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/crypto/anubis.c b/crypto/anubis.c
index 673927de0eb92..f9ce78fde6eee 100644
--- a/crypto/anubis.c
+++ b/crypto/anubis.c
@@ -673,6 +673,7 @@ static void anubis_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 
 static struct crypto_alg anubis_alg = {
 	.cra_name		=	"anubis",
+	.cra_driver_name	=	"anubis-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	ANUBIS_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof (struct anubis_ctx),
diff --git a/crypto/arc4.c b/crypto/arc4.c
index 2233d36456e27..b78dcb390a7e2 100644
--- a/crypto/arc4.c
+++ b/crypto/arc4.c
@@ -115,6 +115,7 @@ static int ecb_arc4_crypt(struct skcipher_request *req)
 
 static struct crypto_alg arc4_cipher = {
 	.cra_name		=	"arc4",
+	.cra_driver_name	=	"arc4-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	ARC4_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof(struct arc4_ctx),
@@ -132,6 +133,7 @@ static struct crypto_alg arc4_cipher = {
 
 static struct skcipher_alg arc4_skcipher = {
 	.base.cra_name		=	"ecb(arc4)",
+	.base.cra_driver_name	=	"ecb(arc4)-generic",
 	.base.cra_priority	=	100,
 	.base.cra_blocksize	=	ARC4_BLOCK_SIZE,
 	.base.cra_ctxsize	=	sizeof(struct arc4_ctx),
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index 9320d4eaa4a8a..6aa9a4c29edf8 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -105,6 +105,7 @@ static struct shash_alg digest_null = {
 	.final  		=	null_final,
 	.base			=	{
 		.cra_name		=	"digest_null",
+		.cra_driver_name	=	"digest_null-generic",
 		.cra_blocksize		=	NULL_BLOCK_SIZE,
 		.cra_module		=	THIS_MODULE,
 	}
@@ -127,6 +128,7 @@ static struct skcipher_alg skcipher_null = {
 
 static struct crypto_alg null_algs[] = { {
 	.cra_name		=	"cipher_null",
+	.cra_driver_name	=	"cipher_null-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	NULL_BLOCK_SIZE,
 	.cra_ctxsize		=	0,
@@ -139,6 +141,7 @@ static struct crypto_alg null_algs[] = { {
 	.cia_decrypt		=	null_crypt } }
 }, {
 	.cra_name		=	"compress_null",
+	.cra_driver_name	=	"compress_null-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_blocksize		=	NULL_BLOCK_SIZE,
 	.cra_ctxsize		=	0,
diff --git a/crypto/deflate.c b/crypto/deflate.c
index aab089cde1bf8..1143ccbe0296b 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -279,6 +279,7 @@ static int deflate_sdecompress(struct crypto_scomp *tfm, const u8 *src,
 
 static struct crypto_alg alg = {
 	.cra_name		= "deflate",
+	.cra_driver_name	= "deflate-generic",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_ctxsize		= sizeof(struct deflate_ctx),
 	.cra_module		= THIS_MODULE,
diff --git a/crypto/fcrypt.c b/crypto/fcrypt.c
index 4e8704405a3b9..58f935315cf8f 100644
--- a/crypto/fcrypt.c
+++ b/crypto/fcrypt.c
@@ -391,6 +391,7 @@ static int fcrypt_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key
 
 static struct crypto_alg fcrypt_alg = {
 	.cra_name		=	"fcrypt",
+	.cra_driver_name	=	"fcrypt-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	8,
 	.cra_ctxsize		=	sizeof(struct fcrypt_ctx),
diff --git a/crypto/khazad.c b/crypto/khazad.c
index b50aa8a3ab4cf..14ca7f1631c79 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -848,6 +848,7 @@ static void khazad_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 
 static struct crypto_alg khazad_alg = {
 	.cra_name		=	"khazad",
+	.cra_driver_name	=	"khazad-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	KHAZAD_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof (struct khazad_ctx),
diff --git a/crypto/lz4.c b/crypto/lz4.c
index 1e35134d0a98d..ed9088c97c6e7 100644
--- a/crypto/lz4.c
+++ b/crypto/lz4.c
@@ -119,6 +119,7 @@ static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
 
 static struct crypto_alg alg_lz4 = {
 	.cra_name		= "lz4",
+	.cra_driver_name	= "lz4-generic",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_ctxsize		= sizeof(struct lz4_ctx),
 	.cra_module		= THIS_MODULE,
diff --git a/crypto/lz4hc.c b/crypto/lz4hc.c
index 4a220b628fe7e..21a342c6b9d4c 100644
--- a/crypto/lz4hc.c
+++ b/crypto/lz4hc.c
@@ -120,6 +120,7 @@ static int lz4hc_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
 
 static struct crypto_alg alg_lz4hc = {
 	.cra_name		= "lz4hc",
+	.cra_driver_name	= "lz4hc-generic",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_ctxsize		= sizeof(struct lz4hc_ctx),
 	.cra_module		= THIS_MODULE,
diff --git a/crypto/lzo-rle.c b/crypto/lzo-rle.c
index 4c82bf18440f0..469814926f02b 100644
--- a/crypto/lzo-rle.c
+++ b/crypto/lzo-rle.c
@@ -122,6 +122,7 @@ static int lzorle_sdecompress(struct crypto_scomp *tfm, const u8 *src,
 
 static struct crypto_alg alg = {
 	.cra_name		= "lzo-rle",
+	.cra_driver_name	= "lzo-rle-generic",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_ctxsize		= sizeof(struct lzorle_ctx),
 	.cra_module		= THIS_MODULE,
diff --git a/crypto/lzo.c b/crypto/lzo.c
index 4a6ac8f247d0a..a98ac046613a1 100644
--- a/crypto/lzo.c
+++ b/crypto/lzo.c
@@ -122,6 +122,7 @@ static int lzo_sdecompress(struct crypto_scomp *tfm, const u8 *src,
 
 static struct crypto_alg alg = {
 	.cra_name		= "lzo",
+	.cra_driver_name	= "lzo-generic",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_ctxsize		= sizeof(struct lzo_ctx),
 	.cra_module		= THIS_MODULE,
diff --git a/crypto/md4.c b/crypto/md4.c
index 9a1a228a0c695..2e7f2f319f950 100644
--- a/crypto/md4.c
+++ b/crypto/md4.c
@@ -216,9 +216,10 @@ static struct shash_alg alg = {
 	.final		=	md4_final,
 	.descsize	=	sizeof(struct md4_ctx),
 	.base		=	{
-		.cra_name	=	"md4",
-		.cra_blocksize	=	MD4_HMAC_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"md4",
+		.cra_driver_name =	"md4-generic",
+		.cra_blocksize	 =	MD4_HMAC_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 };
 
diff --git a/crypto/md5.c b/crypto/md5.c
index 221c2c0932f83..22dc60bc04375 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -228,9 +228,10 @@ static struct shash_alg alg = {
 	.descsize	=	sizeof(struct md5_state),
 	.statesize	=	sizeof(struct md5_state),
 	.base		=	{
-		.cra_name	=	"md5",
-		.cra_blocksize	=	MD5_HMAC_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"md5",
+		.cra_driver_name =	"md5-generic",
+		.cra_blocksize	 =	MD5_HMAC_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 };
 
diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c
index 538ae79337957..be5c07ea6841c 100644
--- a/crypto/michael_mic.c
+++ b/crypto/michael_mic.c
@@ -159,6 +159,7 @@ static struct shash_alg alg = {
 	.descsize		=	sizeof(struct michael_mic_desc_ctx),
 	.base			=	{
 		.cra_name		=	"michael_mic",
+		.cra_driver_name	=	"michael_mic-generic",
 		.cra_blocksize		=	8,
 		.cra_alignmask		=	3,
 		.cra_ctxsize		=	sizeof(struct michael_mic_ctx),
diff --git a/crypto/rmd128.c b/crypto/rmd128.c
index faf4252c4b856..81fcae094bd5e 100644
--- a/crypto/rmd128.c
+++ b/crypto/rmd128.c
@@ -303,6 +303,7 @@ static struct shash_alg alg = {
 	.descsize	=	sizeof(struct rmd128_ctx),
 	.base		=	{
 		.cra_name	 =	"rmd128",
+		.cra_driver_name =	"rmd128-generic",
 		.cra_blocksize	 =	RMD128_BLOCK_SIZE,
 		.cra_module	 =	THIS_MODULE,
 	}
diff --git a/crypto/rmd160.c b/crypto/rmd160.c
index b33309916d4fe..0c0d178dee9dd 100644
--- a/crypto/rmd160.c
+++ b/crypto/rmd160.c
@@ -347,6 +347,7 @@ static struct shash_alg alg = {
 	.descsize	=	sizeof(struct rmd160_ctx),
 	.base		=	{
 		.cra_name	 =	"rmd160",
+		.cra_driver_name =	"rmd160-generic",
 		.cra_blocksize	 =	RMD160_BLOCK_SIZE,
 		.cra_module	 =	THIS_MODULE,
 	}
diff --git a/crypto/rmd256.c b/crypto/rmd256.c
index 2a643250c9a5c..cdbbe37266c35 100644
--- a/crypto/rmd256.c
+++ b/crypto/rmd256.c
@@ -322,6 +322,7 @@ static struct shash_alg alg = {
 	.descsize	=	sizeof(struct rmd256_ctx),
 	.base		=	{
 		.cra_name	 =	"rmd256",
+		.cra_driver_name =	"rmd256-generic",
 		.cra_blocksize	 =	RMD256_BLOCK_SIZE,
 		.cra_module	 =	THIS_MODULE,
 	}
diff --git a/crypto/rmd320.c b/crypto/rmd320.c
index 2f062574fc8c8..9327af0fe4b7a 100644
--- a/crypto/rmd320.c
+++ b/crypto/rmd320.c
@@ -371,6 +371,7 @@ static struct shash_alg alg = {
 	.descsize	=	sizeof(struct rmd320_ctx),
 	.base		=	{
 		.cra_name	 =	"rmd320",
+		.cra_driver_name =	"rmd320-generic",
 		.cra_blocksize	 =	RMD320_BLOCK_SIZE,
 		.cra_module	 =	THIS_MODULE,
 	}
diff --git a/crypto/serpent_generic.c b/crypto/serpent_generic.c
index ec4ec89ad1085..f2f549330d2b7 100644
--- a/crypto/serpent_generic.c
+++ b/crypto/serpent_generic.c
@@ -641,6 +641,7 @@ static struct crypto_alg srp_algs[2] = { {
 	.cia_decrypt		=	serpent_decrypt } }
 }, {
 	.cra_name		=	"tnepres",
+	.cra_driver_name	=	"tnepres-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	SERPENT_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof(struct serpent_ctx),
diff --git a/crypto/tea.c b/crypto/tea.c
index 786b589e13995..fa012589d3b0d 100644
--- a/crypto/tea.c
+++ b/crypto/tea.c
@@ -221,6 +221,7 @@ static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 
 static struct crypto_alg tea_algs[3] = { {
 	.cra_name		=	"tea",
+	.cra_driver_name	=	"tea-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	TEA_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof (struct tea_ctx),
@@ -234,6 +235,7 @@ static struct crypto_alg tea_algs[3] = { {
 	.cia_decrypt		=	tea_decrypt } }
 }, {
 	.cra_name		=	"xtea",
+	.cra_driver_name	=	"xtea-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	XTEA_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof (struct xtea_ctx),
@@ -247,6 +249,7 @@ static struct crypto_alg tea_algs[3] = { {
 	.cia_decrypt		=	xtea_decrypt } }
 }, {
 	.cra_name		=	"xeta",
+	.cra_driver_name	=	"xeta-generic",
 	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
 	.cra_blocksize		=	XTEA_BLOCK_SIZE,
 	.cra_ctxsize		=	sizeof (struct xtea_ctx),
diff --git a/crypto/tgr192.c b/crypto/tgr192.c
index 40020f8adc46a..39b3ffd22f5d7 100644
--- a/crypto/tgr192.c
+++ b/crypto/tgr192.c
@@ -635,9 +635,10 @@ static struct shash_alg tgr_algs[3] = { {
 	.final		=	tgr192_final,
 	.descsize	=	sizeof(struct tgr192_ctx),
 	.base		=	{
-		.cra_name	=	"tgr192",
-		.cra_blocksize	=	TGR192_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"tgr192",
+		.cra_driver_name =	"tgr192-generic",
+		.cra_blocksize	 =	TGR192_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 }, {
 	.digestsize	=	TGR160_DIGEST_SIZE,
@@ -646,9 +647,10 @@ static struct shash_alg tgr_algs[3] = { {
 	.final		=	tgr160_final,
 	.descsize	=	sizeof(struct tgr192_ctx),
 	.base		=	{
-		.cra_name	=	"tgr160",
-		.cra_blocksize	=	TGR192_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"tgr160",
+		.cra_driver_name =	"tgr160-generic",
+		.cra_blocksize	 =	TGR192_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 }, {
 	.digestsize	=	TGR128_DIGEST_SIZE,
@@ -657,9 +659,10 @@ static struct shash_alg tgr_algs[3] = { {
 	.final		=	tgr128_final,
 	.descsize	=	sizeof(struct tgr192_ctx),
 	.base		=	{
-		.cra_name	=	"tgr128",
-		.cra_blocksize	=	TGR192_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"tgr128",
+		.cra_driver_name =	"tgr128-generic",
+		.cra_blocksize	 =	TGR192_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 } };
 
diff --git a/crypto/wp512.c b/crypto/wp512.c
index 1b8e502d999ff..feadc13ccae06 100644
--- a/crypto/wp512.c
+++ b/crypto/wp512.c
@@ -1126,9 +1126,10 @@ static struct shash_alg wp_algs[3] = { {
 	.final		=	wp512_final,
 	.descsize	=	sizeof(struct wp512_ctx),
 	.base		=	{
-		.cra_name	=	"wp512",
-		.cra_blocksize	=	WP512_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"wp512",
+		.cra_driver_name =	"wp512-generic",
+		.cra_blocksize	 =	WP512_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 }, {
 	.digestsize	=	WP384_DIGEST_SIZE,
@@ -1137,9 +1138,10 @@ static struct shash_alg wp_algs[3] = { {
 	.final		=	wp384_final,
 	.descsize	=	sizeof(struct wp512_ctx),
 	.base		=	{
-		.cra_name	=	"wp384",
-		.cra_blocksize	=	WP512_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"wp384",
+		.cra_driver_name =	"wp384-generic",
+		.cra_blocksize	 =	WP512_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 }, {
 	.digestsize	=	WP256_DIGEST_SIZE,
@@ -1148,9 +1150,10 @@ static struct shash_alg wp_algs[3] = { {
 	.final		=	wp256_final,
 	.descsize	=	sizeof(struct wp512_ctx),
 	.base		=	{
-		.cra_name	=	"wp256",
-		.cra_blocksize	=	WP512_BLOCK_SIZE,
-		.cra_module	=	THIS_MODULE,
+		.cra_name	 =	"wp256",
+		.cra_driver_name =	"wp256-generic",
+		.cra_blocksize	 =	WP512_BLOCK_SIZE,
+		.cra_module	 =	THIS_MODULE,
 	}
 } };
 
diff --git a/crypto/zstd.c b/crypto/zstd.c
index 2c04055e407f0..c9ff2ec8d4a32 100644
--- a/crypto/zstd.c
+++ b/crypto/zstd.c
@@ -214,6 +214,7 @@ static int zstd_sdecompress(struct crypto_scomp *tfm, const u8 *src,
 
 static struct crypto_alg alg = {
 	.cra_name		= "zstd",
+	.cra_driver_name	= "zstd-generic",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
 	.cra_ctxsize		= sizeof(struct zstd_ctx),
 	.cra_module		= THIS_MODULE,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] crypto: algapi - require cra_name and cra_driver_name
  2019-06-03  5:40 [PATCH 0/2] crypto: make cra_driver_name mandatory Eric Biggers
  2019-06-03  5:40 ` [PATCH 1/2] crypto: make all generic algorithms set cra_driver_name Eric Biggers
@ 2019-06-03  5:40 ` Eric Biggers
  2019-06-03  6:52 ` [PATCH 0/2] crypto: make cra_driver_name mandatory Ard Biesheuvel
  2019-06-13  6:53 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2019-06-03  5:40 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Now that all algorithms explicitly set cra_driver_name, make it required
for algorithm registration and remove the code that generated a default
cra_driver_name.

Also add an explicit check that cra_name is set too, since that's
obviously required too, yet it didn't seem to be checked anywhere.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/algapi.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/crypto/algapi.c b/crypto/algapi.c
index 7c51f45d1cf16..5278e139a161e 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -26,23 +26,6 @@
 
 static LIST_HEAD(crypto_template_list);
 
-static inline int crypto_set_driver_name(struct crypto_alg *alg)
-{
-	static const char suffix[] = "-generic";
-	char *driver_name = alg->cra_driver_name;
-	int len;
-
-	if (*driver_name)
-		return 0;
-
-	len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
-	if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
-		return -ENAMETOOLONG;
-
-	memcpy(driver_name + len, suffix, sizeof(suffix));
-	return 0;
-}
-
 static inline void crypto_check_module_sig(struct module *mod)
 {
 	if (fips_enabled && mod && !module_sig_ok(mod))
@@ -54,6 +37,9 @@ static int crypto_check_alg(struct crypto_alg *alg)
 {
 	crypto_check_module_sig(alg->cra_module);
 
+	if (!alg->cra_name[0] || !alg->cra_driver_name[0])
+		return -EINVAL;
+
 	if (alg->cra_alignmask & (alg->cra_alignmask + 1))
 		return -EINVAL;
 
@@ -79,7 +65,7 @@ static int crypto_check_alg(struct crypto_alg *alg)
 
 	refcount_set(&alg->cra_refcnt, 1);
 
-	return crypto_set_driver_name(alg);
+	return 0;
 }
 
 static void crypto_free_instance(struct crypto_instance *inst)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] crypto: make cra_driver_name mandatory
  2019-06-03  5:40 [PATCH 0/2] crypto: make cra_driver_name mandatory Eric Biggers
  2019-06-03  5:40 ` [PATCH 1/2] crypto: make all generic algorithms set cra_driver_name Eric Biggers
  2019-06-03  5:40 ` [PATCH 2/2] crypto: algapi - require cra_name and cra_driver_name Eric Biggers
@ 2019-06-03  6:52 ` Ard Biesheuvel
  2019-06-13  6:53 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2019-06-03  6:52 UTC (permalink / raw)
  To: Eric Biggers; +Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE

On Mon, 3 Jun 2019 at 07:41, Eric Biggers <ebiggers@kernel.org> wrote:
>
> Most generic crypto algorithms declare a driver name ending in
> "-generic".  The rest don't declare a driver name and instead rely on
> the crypto API automagically appending "-generic" upon registration.
>
> Having multiple conventions is unnecessarily confusing and makes it
> harder to grep for all generic algorithms in the kernel source tree.
> But also, allowing NULL driver names is problematic because sometimes
> people fail to set it, e.g. the case fixed by commit 417980364300
> ("crypto: cavium/zip - fix collision with generic cra_driver_name").
>
> Of course, people can also incorrectly name their drivers "-generic".
> But that's much easier to notice / grep for.
>
> Therefore, let's make cra_driver_name mandatory.  Patch 1 gives all
> generic algorithms an explicit cra_driver_name, and Patch 2 makes
> cra_driver_name required for algorithm registration.
>
> Eric Biggers (2):
>   crypto: make all generic algorithms set cra_driver_name
>   crypto: algapi - require cra_name and cra_driver_name
>

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] crypto: make cra_driver_name mandatory
  2019-06-03  5:40 [PATCH 0/2] crypto: make cra_driver_name mandatory Eric Biggers
                   ` (2 preceding siblings ...)
  2019-06-03  6:52 ` [PATCH 0/2] crypto: make cra_driver_name mandatory Ard Biesheuvel
@ 2019-06-13  6:53 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2019-06-13  6:53 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto

Eric Biggers <ebiggers@kernel.org> wrote:
> Most generic crypto algorithms declare a driver name ending in
> "-generic".  The rest don't declare a driver name and instead rely on
> the crypto API automagically appending "-generic" upon registration.
> 
> Having multiple conventions is unnecessarily confusing and makes it
> harder to grep for all generic algorithms in the kernel source tree.
> But also, allowing NULL driver names is problematic because sometimes
> people fail to set it, e.g. the case fixed by commit 417980364300
> ("crypto: cavium/zip - fix collision with generic cra_driver_name").
> 
> Of course, people can also incorrectly name their drivers "-generic".
> But that's much easier to notice / grep for.
> 
> Therefore, let's make cra_driver_name mandatory.  Patch 1 gives all
> generic algorithms an explicit cra_driver_name, and Patch 2 makes
> cra_driver_name required for algorithm registration.
> 
> Eric Biggers (2):
>  crypto: make all generic algorithms set cra_driver_name
>  crypto: algapi - require cra_name and cra_driver_name

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-13 16:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03  5:40 [PATCH 0/2] crypto: make cra_driver_name mandatory Eric Biggers
2019-06-03  5:40 ` [PATCH 1/2] crypto: make all generic algorithms set cra_driver_name Eric Biggers
2019-06-03  5:40 ` [PATCH 2/2] crypto: algapi - require cra_name and cra_driver_name Eric Biggers
2019-06-03  6:52 ` [PATCH 0/2] crypto: make cra_driver_name mandatory Ard Biesheuvel
2019-06-13  6:53 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.