linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] crypto: misc fixes/cleanups
@ 2019-01-10 20:17 Eric Biggers
  2019-01-10 20:17 ` [PATCH 01/11] crypto: gcm - use correct endianness type in gcm_hash_len() Eric Biggers
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

Some more miscellaneous crypto fixes and cleanups:

- Patch 1-6: fix sparse warnings in 6 files.
- Patch 7: fix unaligned memory access in tgr192.
- Patch 8-11: a few other cleanups.

Eric Biggers (11):
  crypto: gcm - use correct endianness type in gcm_hash_len()
  crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h>
  crypto: streebog - use correct endianness type
  crypto: testmgr - handle endianness correctly in alg_test_crc32c()
  crypto: user - forward declare crypto_nlsk
  crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const
  crypto: tgr192 - fix unaligned memory access
  crypto: stat - remove unused mutex
  crypto: af_alg - make some functions static
  crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl()
  crypto: af_alg - remove redundant initializations of sk_family

 arch/x86/crypto/aesni-intel_glue.c   | 34 +++++++++++-----------------
 crypto/af_alg.c                      | 33 ++++++++++-----------------
 crypto/crypto_user_stat.c            |  4 ----
 crypto/gcm.c                         |  2 +-
 crypto/rsa-pkcs1pad.c                |  1 +
 crypto/streebog_generic.c            |  2 +-
 crypto/testmgr.c                     | 10 ++++----
 crypto/tgr192.c                      |  6 ++---
 include/crypto/if_alg.h              |  7 ------
 include/crypto/internal/cryptouser.h |  2 ++
 include/crypto/streebog.h            |  2 +-
 11 files changed, 39 insertions(+), 64 deletions(-)

-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 01/11] crypto: gcm - use correct endianness type in gcm_hash_len()
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 02/11] crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h> Eric Biggers
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

From: Eric Biggers <ebiggers@google.com>

In gcm_hash_len(), use be128 rather than u128.  This fixes the following
sparse warnings:

    crypto/gcm.c:252:19: warning: incorrect type in assignment (different base types)
    crypto/gcm.c:252:19:    expected unsigned long long [usertype] a
    crypto/gcm.c:252:19:    got restricted __be64 [usertype]
    crypto/gcm.c:253:19: warning: incorrect type in assignment (different base types)
    crypto/gcm.c:253:19:    expected unsigned long long [usertype] b
    crypto/gcm.c:253:19:    got restricted __be64 [usertype]

No actual change in behavior.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/gcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/gcm.c b/crypto/gcm.c
index e438492db2ca2..bbce31f6199ba 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -247,7 +247,7 @@ static int gcm_hash_len(struct aead_request *req, u32 flags)
 	struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req);
 	struct ahash_request *ahreq = &pctx->u.ahreq;
 	struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx;
-	u128 lengths;
+	be128 lengths;
 
 	lengths.a = cpu_to_be64(req->assoclen * 8);
 	lengths.b = cpu_to_be64(gctx->cryptlen * 8);
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 02/11] crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h>
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
  2019-01-10 20:17 ` [PATCH 01/11] crypto: gcm - use correct endianness type in gcm_hash_len() Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 03/11] crypto: streebog - use correct endianness type Eric Biggers
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu; +Cc: Andrzej Zaborowski

From: Eric Biggers <ebiggers@google.com>

Include internal/rsa.h in rsa-pkcs1pad.c to get the declaration of
rsa_pkcs1pad_tmpl.  This fixes the following sparse warning:

    crypto/rsa-pkcs1pad.c:698:24: warning: symbol 'rsa_pkcs1pad_tmpl' was not declared. Should it be static?

Cc: Andrzej Zaborowski <andrew.zaborowski@intel.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/rsa-pkcs1pad.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c
index cfc04e15fd975..0a6680ca8cb6f 100644
--- a/crypto/rsa-pkcs1pad.c
+++ b/crypto/rsa-pkcs1pad.c
@@ -12,6 +12,7 @@
 #include <crypto/algapi.h>
 #include <crypto/akcipher.h>
 #include <crypto/internal/akcipher.h>
+#include <crypto/internal/rsa.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 03/11] crypto: streebog - use correct endianness type
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
  2019-01-10 20:17 ` [PATCH 01/11] crypto: gcm - use correct endianness type in gcm_hash_len() Eric Biggers
  2019-01-10 20:17 ` [PATCH 02/11] crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h> Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 04/11] crypto: testmgr - handle endianness correctly in alg_test_crc32c() Eric Biggers
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu; +Cc: Vitaly Chikunov

From: Eric Biggers <ebiggers@google.com>

streebog_uint512::qword needs to be __le64, not u64.  This fixes a large
number of sparse warnings:

    crypto/streebog_generic.c:25:9: warning: incorrect type in initializer (different base types)
    crypto/streebog_generic.c:25:9:    expected unsigned long long
    crypto/streebog_generic.c:25:9:    got restricted __le64 [usertype]
    [omitted many similar warnings]

No actual change in behavior.

Cc: Vitaly Chikunov <vt@altlinux.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/streebog_generic.c | 2 +-
 include/crypto/streebog.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/streebog_generic.c b/crypto/streebog_generic.c
index 03272a22afcec..5a2eafed9c29f 100644
--- a/crypto/streebog_generic.c
+++ b/crypto/streebog_generic.c
@@ -960,7 +960,7 @@ static int streebog_init(struct shash_desc *desc)
 	memset(ctx, 0, sizeof(struct streebog_state));
 	for (i = 0; i < 8; i++) {
 		if (digest_size == STREEBOG256_DIGEST_SIZE)
-			ctx->h.qword[i] = 0x0101010101010101ULL;
+			ctx->h.qword[i] = cpu_to_le64(0x0101010101010101ULL);
 	}
 	return 0;
 }
diff --git a/include/crypto/streebog.h b/include/crypto/streebog.h
index 4af119f7e07b9..856e32af86574 100644
--- a/include/crypto/streebog.h
+++ b/include/crypto/streebog.h
@@ -19,7 +19,7 @@
 #define STREEBOG_BLOCK_SIZE	64
 
 struct streebog_uint512 {
-	u64 qword[8];
+	__le64 qword[8];
 };
 
 struct streebog_state {
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 04/11] crypto: testmgr - handle endianness correctly in alg_test_crc32c()
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (2 preceding siblings ...)
  2019-01-10 20:17 ` [PATCH 03/11] crypto: streebog - use correct endianness type Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 05/11] crypto: user - forward declare crypto_nlsk Eric Biggers
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

From: Eric Biggers <ebiggers@google.com>

The crc32c context is in CPU endianness, whereas the final digest is
little endian.  alg_test_crc32c() got this mixed up.  Fix it.

The test passes both before and after, but this patch fixes the
following sparse warning:

    crypto/testmgr.c:1912:24: warning: cast to restricted __le32

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/testmgr.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 0f684a414acbe..10b7208bd40be 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1889,7 +1889,7 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
 			   const char *driver, u32 type, u32 mask)
 {
 	struct crypto_shash *tfm;
-	u32 val;
+	__le32 val;
 	int err;
 
 	err = alg_test_hash(desc, driver, type, mask);
@@ -1911,7 +1911,7 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
 		shash->tfm = tfm;
 		shash->flags = 0;
 
-		*ctx = le32_to_cpu(420553207);
+		*ctx = 420553207;
 		err = crypto_shash_final(shash, (u8 *)&val);
 		if (err) {
 			printk(KERN_ERR "alg: crc32c: Operation failed for "
@@ -1919,9 +1919,9 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
 			break;
 		}
 
-		if (val != ~420553207) {
-			printk(KERN_ERR "alg: crc32c: Test failed for %s: "
-			       "%d\n", driver, val);
+		if (val != cpu_to_le32(~420553207)) {
+			pr_err("alg: crc32c: Test failed for %s: %u\n",
+			       driver, le32_to_cpu(val));
 			err = -EINVAL;
 		}
 	} while (0);
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 05/11] crypto: user - forward declare crypto_nlsk
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (3 preceding siblings ...)
  2019-01-10 20:17 ` [PATCH 04/11] crypto: testmgr - handle endianness correctly in alg_test_crc32c() Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 06/11] crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const Eric Biggers
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu; +Cc: Corentin Labbe

From: Eric Biggers <ebiggers@google.com>

Move the declaration of crypto_nlsk into internal/cryptouser.h.  This
fixes the following sparse warning:

    crypto/crypto_user_base.c:41:13: warning: symbol 'crypto_nlsk' was not declared. Should it be static?

Cc: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/crypto_user_stat.c            | 2 --
 include/crypto/internal/cryptouser.h | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/crypto_user_stat.c b/crypto/crypto_user_stat.c
index 3e9a53233d804..d4d1cb2bedd7f 100644
--- a/crypto/crypto_user_stat.c
+++ b/crypto/crypto_user_stat.c
@@ -22,8 +22,6 @@
 
 static DEFINE_MUTEX(crypto_cfg_mutex);
 
-extern struct sock *crypto_nlsk;
-
 struct crypto_dump_info {
 	struct sk_buff *in_skb;
 	struct sk_buff *out_skb;
diff --git a/include/crypto/internal/cryptouser.h b/include/crypto/internal/cryptouser.h
index 40623f4457df6..8c602b187c58a 100644
--- a/include/crypto/internal/cryptouser.h
+++ b/include/crypto/internal/cryptouser.h
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 #include <net/netlink.h>
 
+extern struct sock *crypto_nlsk;
+
 struct crypto_alg *crypto_alg_match(struct crypto_user_alg *p, int exact);
 
 #ifdef CONFIG_CRYPTO_STATS
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 06/11] crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (4 preceding siblings ...)
  2019-01-10 20:17 ` [PATCH 05/11] crypto: user - forward declare crypto_nlsk Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 07/11] crypto: tgr192 - fix unaligned memory access Eric Biggers
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu; +Cc: Dave Watson

From: Eric Biggers <ebiggers@google.com>

Add missing static keywords to fix the following sparse warnings:

    arch/x86/crypto/aesni-intel_glue.c:197:24: warning: symbol 'aesni_gcm_tfm_sse' was not declared. Should it be static?
    arch/x86/crypto/aesni-intel_glue.c:246:24: warning: symbol 'aesni_gcm_tfm_avx_gen2' was not declared. Should it be static?
    arch/x86/crypto/aesni-intel_glue.c:291:24: warning: symbol 'aesni_gcm_tfm_avx_gen4' was not declared. Should it be static?

I also made the affected structures 'const', and adjusted the
indentation in the struct definition to not be insane.

Cc: Dave Watson <davejwatson@fb.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 arch/x86/crypto/aesni-intel_glue.c | 34 ++++++++++++------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 1321700d6647f..9b5ccde3ef315 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -175,26 +175,18 @@ asmlinkage void aesni_gcm_finalize(void *ctx,
 				   struct gcm_context_data *gdata,
 				   u8 *auth_tag, unsigned long auth_tag_len);
 
-static struct aesni_gcm_tfm_s {
-void (*init)(void *ctx,
-				struct gcm_context_data *gdata,
-				u8 *iv,
-				u8 *hash_subkey, const u8 *aad,
-				unsigned long aad_len);
-void (*enc_update)(void *ctx,
-					struct gcm_context_data *gdata, u8 *out,
-					const u8 *in,
-					unsigned long plaintext_len);
-void (*dec_update)(void *ctx,
-					struct gcm_context_data *gdata, u8 *out,
-					const u8 *in,
-					unsigned long ciphertext_len);
-void (*finalize)(void *ctx,
-				struct gcm_context_data *gdata,
-				u8 *auth_tag, unsigned long auth_tag_len);
+static const struct aesni_gcm_tfm_s {
+	void (*init)(void *ctx, struct gcm_context_data *gdata, u8 *iv,
+		     u8 *hash_subkey, const u8 *aad, unsigned long aad_len);
+	void (*enc_update)(void *ctx, struct gcm_context_data *gdata, u8 *out,
+			   const u8 *in, unsigned long plaintext_len);
+	void (*dec_update)(void *ctx, struct gcm_context_data *gdata, u8 *out,
+			   const u8 *in, unsigned long ciphertext_len);
+	void (*finalize)(void *ctx, struct gcm_context_data *gdata,
+			 u8 *auth_tag, unsigned long auth_tag_len);
 } *aesni_gcm_tfm;
 
-struct aesni_gcm_tfm_s aesni_gcm_tfm_sse = {
+static const struct aesni_gcm_tfm_s aesni_gcm_tfm_sse = {
 	.init = &aesni_gcm_init,
 	.enc_update = &aesni_gcm_enc_update,
 	.dec_update = &aesni_gcm_dec_update,
@@ -243,7 +235,7 @@ asmlinkage void aesni_gcm_dec_avx_gen2(void *ctx,
 			const u8 *aad, unsigned long aad_len,
 			u8 *auth_tag, unsigned long auth_tag_len);
 
-struct aesni_gcm_tfm_s aesni_gcm_tfm_avx_gen2 = {
+static const struct aesni_gcm_tfm_s aesni_gcm_tfm_avx_gen2 = {
 	.init = &aesni_gcm_init_avx_gen2,
 	.enc_update = &aesni_gcm_enc_update_avx_gen2,
 	.dec_update = &aesni_gcm_dec_update_avx_gen2,
@@ -288,7 +280,7 @@ asmlinkage void aesni_gcm_dec_avx_gen4(void *ctx,
 			const u8 *aad, unsigned long aad_len,
 			u8 *auth_tag, unsigned long auth_tag_len);
 
-struct aesni_gcm_tfm_s aesni_gcm_tfm_avx_gen4 = {
+static const struct aesni_gcm_tfm_s aesni_gcm_tfm_avx_gen4 = {
 	.init = &aesni_gcm_init_avx_gen4,
 	.enc_update = &aesni_gcm_enc_update_avx_gen4,
 	.dec_update = &aesni_gcm_dec_update_avx_gen4,
@@ -778,7 +770,7 @@ static int gcmaes_crypt_by_sg(bool enc, struct aead_request *req,
 {
 	struct crypto_aead *tfm = crypto_aead_reqtfm(req);
 	unsigned long auth_tag_len = crypto_aead_authsize(tfm);
-	struct aesni_gcm_tfm_s *gcm_tfm = aesni_gcm_tfm;
+	const struct aesni_gcm_tfm_s *gcm_tfm = aesni_gcm_tfm;
 	struct gcm_context_data data AESNI_ALIGN_ATTR;
 	struct scatter_walk dst_sg_walk = {};
 	unsigned long left = req->cryptlen;
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 07/11] crypto: tgr192 - fix unaligned memory access
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (5 preceding siblings ...)
  2019-01-10 20:17 ` [PATCH 06/11] crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:17 ` [PATCH 08/11] crypto: stat - remove unused mutex Eric Biggers
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

From: Eric Biggers <ebiggers@google.com>

Fix an unaligned memory access in tgr192_transform() by using the
unaligned access helpers.

Fixes: 06ace7a9bafe ("[CRYPTO] Use standard byte order macros wherever possible")
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/tgr192.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/crypto/tgr192.c b/crypto/tgr192.c
index 022d3dd76c3b2..f8e1d9f9938f5 100644
--- a/crypto/tgr192.c
+++ b/crypto/tgr192.c
@@ -25,8 +25,9 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/mm.h>
-#include <asm/byteorder.h>
 #include <linux/types.h>
+#include <asm/byteorder.h>
+#include <asm/unaligned.h>
 
 #define TGR192_DIGEST_SIZE 24
 #define TGR160_DIGEST_SIZE 20
@@ -468,10 +469,9 @@ static void tgr192_transform(struct tgr192_ctx *tctx, const u8 * data)
 	u64 a, b, c, aa, bb, cc;
 	u64 x[8];
 	int i;
-	const __le64 *ptr = (const __le64 *)data;
 
 	for (i = 0; i < 8; i++)
-		x[i] = le64_to_cpu(ptr[i]);
+		x[i] = get_unaligned_le64(data + i * sizeof(__le64));
 
 	/* save */
 	a = aa = tctx->a;
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 08/11] crypto: stat - remove unused mutex
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (6 preceding siblings ...)
  2019-01-10 20:17 ` [PATCH 07/11] crypto: tgr192 - fix unaligned memory access Eric Biggers
@ 2019-01-10 20:17 ` Eric Biggers
  2019-01-10 20:18 ` [PATCH 09/11] crypto: af_alg - make some functions static Eric Biggers
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:17 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu; +Cc: Corentin Labbe

From: Eric Biggers <ebiggers@google.com>

crypto_cfg_mutex in crypto_user_stat.c is unused.  Remove it.

Cc: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/crypto_user_stat.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/crypto/crypto_user_stat.c b/crypto/crypto_user_stat.c
index d4d1cb2bedd7f..a03f326a63d32 100644
--- a/crypto/crypto_user_stat.c
+++ b/crypto/crypto_user_stat.c
@@ -20,8 +20,6 @@
 
 #define null_terminated(x)	(strnlen(x, sizeof(x)) < sizeof(x))
 
-static DEFINE_MUTEX(crypto_cfg_mutex);
-
 struct crypto_dump_info {
 	struct sk_buff *in_skb;
 	struct sk_buff *out_skb;
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 09/11] crypto: af_alg - make some functions static
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (7 preceding siblings ...)
  2019-01-10 20:17 ` [PATCH 08/11] crypto: stat - remove unused mutex Eric Biggers
@ 2019-01-10 20:18 ` Eric Biggers
  2019-01-10 20:18 ` [PATCH 10/11] crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl() Eric Biggers
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:18 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

From: Eric Biggers <ebiggers@google.com>

Some exported functions in af_alg.c aren't used outside of that file.
Therefore, un-export them and make them 'static'.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/af_alg.c         | 20 +++++++-------------
 include/crypto/if_alg.h |  7 -------
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 17eb09d222ff4..ccae4a7ada8ab 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -425,12 +425,12 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len)
 }
 EXPORT_SYMBOL_GPL(af_alg_make_sg);
 
-void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new)
+static void af_alg_link_sg(struct af_alg_sgl *sgl_prev,
+			   struct af_alg_sgl *sgl_new)
 {
 	sg_unmark_end(sgl_prev->sg + sgl_prev->npages - 1);
 	sg_chain(sgl_prev->sg, sgl_prev->npages + 1, sgl_new->sg);
 }
-EXPORT_SYMBOL_GPL(af_alg_link_sg);
 
 void af_alg_free_sg(struct af_alg_sgl *sgl)
 {
@@ -441,7 +441,7 @@ void af_alg_free_sg(struct af_alg_sgl *sgl)
 }
 EXPORT_SYMBOL_GPL(af_alg_free_sg);
 
-int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
+static int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
 {
 	struct cmsghdr *cmsg;
 
@@ -480,7 +480,6 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(af_alg_cmsg_send);
 
 /**
  * af_alg_alloc_tsgl - allocate the TX SGL
@@ -488,7 +487,7 @@ EXPORT_SYMBOL_GPL(af_alg_cmsg_send);
  * @sk socket of connection to user space
  * @return: 0 upon success, < 0 upon error
  */
-int af_alg_alloc_tsgl(struct sock *sk)
+static int af_alg_alloc_tsgl(struct sock *sk)
 {
 	struct alg_sock *ask = alg_sk(sk);
 	struct af_alg_ctx *ctx = ask->private;
@@ -517,7 +516,6 @@ int af_alg_alloc_tsgl(struct sock *sk)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(af_alg_alloc_tsgl);
 
 /**
  * aead_count_tsgl - Count number of TX SG entries
@@ -654,7 +652,7 @@ EXPORT_SYMBOL_GPL(af_alg_pull_tsgl);
  *
  * @areq Request holding the TX and RX SGL
  */
-void af_alg_free_areq_sgls(struct af_alg_async_req *areq)
+static void af_alg_free_areq_sgls(struct af_alg_async_req *areq)
 {
 	struct sock *sk = areq->sk;
 	struct alg_sock *ask = alg_sk(sk);
@@ -683,7 +681,6 @@ void af_alg_free_areq_sgls(struct af_alg_async_req *areq)
 		sock_kfree_s(sk, tsgl, areq->tsgl_entries * sizeof(*tsgl));
 	}
 }
-EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls);
 
 /**
  * af_alg_wait_for_wmem - wait for availability of writable memory
@@ -692,7 +689,7 @@ EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls);
  * @flags If MSG_DONTWAIT is set, then only report if function would sleep
  * @return 0 when writable memory is available, < 0 upon error
  */
-int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags)
+static int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags)
 {
 	DEFINE_WAIT_FUNC(wait, woken_wake_function);
 	int err = -ERESTARTSYS;
@@ -717,7 +714,6 @@ int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags)
 
 	return err;
 }
-EXPORT_SYMBOL_GPL(af_alg_wait_for_wmem);
 
 /**
  * af_alg_wmem_wakeup - wakeup caller when writable memory is available
@@ -786,8 +782,7 @@ EXPORT_SYMBOL_GPL(af_alg_wait_for_data);
  *
  * @sk socket of connection to user space
  */
-
-void af_alg_data_wakeup(struct sock *sk)
+static void af_alg_data_wakeup(struct sock *sk)
 {
 	struct alg_sock *ask = alg_sk(sk);
 	struct af_alg_ctx *ctx = ask->private;
@@ -805,7 +800,6 @@ void af_alg_data_wakeup(struct sock *sk)
 	sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
 	rcu_read_unlock();
 }
-EXPORT_SYMBOL_GPL(af_alg_data_wakeup);
 
 /**
  * af_alg_sendmsg - implementation of sendmsg system call handler
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
index 482461d8931d9..0d464db74bf53 100644
--- a/include/crypto/if_alg.h
+++ b/include/crypto/if_alg.h
@@ -169,9 +169,6 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern);
 
 int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
 void af_alg_free_sg(struct af_alg_sgl *sgl);
-void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new);
-
-int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
 
 static inline struct alg_sock *alg_sk(struct sock *sk)
 {
@@ -230,15 +227,11 @@ static inline bool af_alg_readable(struct sock *sk)
 	return PAGE_SIZE <= af_alg_rcvbuf(sk);
 }
 
-int af_alg_alloc_tsgl(struct sock *sk);
 unsigned int af_alg_count_tsgl(struct sock *sk, size_t bytes, size_t offset);
 void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst,
 		      size_t dst_offset);
-void af_alg_free_areq_sgls(struct af_alg_async_req *areq);
-int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags);
 void af_alg_wmem_wakeup(struct sock *sk);
 int af_alg_wait_for_data(struct sock *sk, unsigned flags);
-void af_alg_data_wakeup(struct sock *sk);
 int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
 		   unsigned int ivsize);
 ssize_t af_alg_sendpage(struct socket *sock, struct page *page,
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 10/11] crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl()
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (8 preceding siblings ...)
  2019-01-10 20:18 ` [PATCH 09/11] crypto: af_alg - make some functions static Eric Biggers
@ 2019-01-10 20:18 ` Eric Biggers
  2019-01-10 20:18 ` [PATCH 11/11] crypto: af_alg - remove redundant initializations of sk_family Eric Biggers
  2019-01-18 10:57 ` [PATCH 00/11] crypto: misc fixes/cleanups Herbert Xu
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:18 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

From: Eric Biggers <ebiggers@google.com>

af_alg_count_tsgl() iterates through a list without modifying it, so use
list_for_each_entry() rather than list_for_each_entry_safe().  Also make
the pointers 'const' to make it clearer that nothing is modified.

No actual change in behavior.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/af_alg.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index ccae4a7ada8ab..1dd573a441279 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -530,17 +530,17 @@ static int af_alg_alloc_tsgl(struct sock *sk)
  */
 unsigned int af_alg_count_tsgl(struct sock *sk, size_t bytes, size_t offset)
 {
-	struct alg_sock *ask = alg_sk(sk);
-	struct af_alg_ctx *ctx = ask->private;
-	struct af_alg_tsgl *sgl, *tmp;
+	const struct alg_sock *ask = alg_sk(sk);
+	const struct af_alg_ctx *ctx = ask->private;
+	const struct af_alg_tsgl *sgl;
 	unsigned int i;
 	unsigned int sgl_count = 0;
 
 	if (!bytes)
 		return 0;
 
-	list_for_each_entry_safe(sgl, tmp, &ctx->tsgl_list, list) {
-		struct scatterlist *sg = sgl->sg;
+	list_for_each_entry(sgl, &ctx->tsgl_list, list) {
+		const struct scatterlist *sg = sgl->sg;
 
 		for (i = 0; i < sgl->cur; i++) {
 			size_t bytes_count;
-- 
2.20.1.97.g81188d93c3-goog

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

* [PATCH 11/11] crypto: af_alg - remove redundant initializations of sk_family
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (9 preceding siblings ...)
  2019-01-10 20:18 ` [PATCH 10/11] crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl() Eric Biggers
@ 2019-01-10 20:18 ` Eric Biggers
  2019-01-18 10:57 ` [PATCH 00/11] crypto: misc fixes/cleanups Herbert Xu
  11 siblings, 0 replies; 13+ messages in thread
From: Eric Biggers @ 2019-01-10 20:18 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu

From: Eric Biggers <ebiggers@google.com>

sk_alloc() already sets sock::sk_family to PF_ALG which is passed as the
'family' argument, so there's no need to set it again.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/af_alg.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 1dd573a441279..c5937c8127999 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -302,8 +302,6 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
 	if (err)
 		goto unlock;
 
-	sk2->sk_family = PF_ALG;
-
 	if (nokey || !ask->refcnt++)
 		sock_hold(sk);
 	ask->nokey_refcnt += nokey;
@@ -380,7 +378,6 @@ static int alg_create(struct net *net, struct socket *sock, int protocol,
 	sock->ops = &alg_proto_ops;
 	sock_init_data(sock, sk);
 
-	sk->sk_family = PF_ALG;
 	sk->sk_destruct = alg_sock_destruct;
 
 	return 0;
-- 
2.20.1.97.g81188d93c3-goog

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

* Re: [PATCH 00/11] crypto: misc fixes/cleanups
  2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
                   ` (10 preceding siblings ...)
  2019-01-10 20:18 ` [PATCH 11/11] crypto: af_alg - remove redundant initializations of sk_family Eric Biggers
@ 2019-01-18 10:57 ` Herbert Xu
  11 siblings, 0 replies; 13+ messages in thread
From: Herbert Xu @ 2019-01-18 10:57 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto

On Thu, Jan 10, 2019 at 12:17:51PM -0800, Eric Biggers wrote:
> Some more miscellaneous crypto fixes and cleanups:
> 
> - Patch 1-6: fix sparse warnings in 6 files.
> - Patch 7: fix unaligned memory access in tgr192.
> - Patch 8-11: a few other cleanups.
> 
> Eric Biggers (11):
>   crypto: gcm - use correct endianness type in gcm_hash_len()
>   crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h>
>   crypto: streebog - use correct endianness type
>   crypto: testmgr - handle endianness correctly in alg_test_crc32c()
>   crypto: user - forward declare crypto_nlsk
>   crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const
>   crypto: tgr192 - fix unaligned memory access
>   crypto: stat - remove unused mutex
>   crypto: af_alg - make some functions static
>   crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl()
>   crypto: af_alg - remove redundant initializations of sk_family
> 
>  arch/x86/crypto/aesni-intel_glue.c   | 34 +++++++++++-----------------
>  crypto/af_alg.c                      | 33 ++++++++++-----------------
>  crypto/crypto_user_stat.c            |  4 ----
>  crypto/gcm.c                         |  2 +-
>  crypto/rsa-pkcs1pad.c                |  1 +
>  crypto/streebog_generic.c            |  2 +-
>  crypto/testmgr.c                     | 10 ++++----
>  crypto/tgr192.c                      |  6 ++---
>  include/crypto/if_alg.h              |  7 ------
>  include/crypto/internal/cryptouser.h |  2 ++
>  include/crypto/streebog.h            |  2 +-
>  11 files changed, 39 insertions(+), 64 deletions(-)

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] 13+ messages in thread

end of thread, other threads:[~2019-01-18 10:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-10 20:17 [PATCH 00/11] crypto: misc fixes/cleanups Eric Biggers
2019-01-10 20:17 ` [PATCH 01/11] crypto: gcm - use correct endianness type in gcm_hash_len() Eric Biggers
2019-01-10 20:17 ` [PATCH 02/11] crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h> Eric Biggers
2019-01-10 20:17 ` [PATCH 03/11] crypto: streebog - use correct endianness type Eric Biggers
2019-01-10 20:17 ` [PATCH 04/11] crypto: testmgr - handle endianness correctly in alg_test_crc32c() Eric Biggers
2019-01-10 20:17 ` [PATCH 05/11] crypto: user - forward declare crypto_nlsk Eric Biggers
2019-01-10 20:17 ` [PATCH 06/11] crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const Eric Biggers
2019-01-10 20:17 ` [PATCH 07/11] crypto: tgr192 - fix unaligned memory access Eric Biggers
2019-01-10 20:17 ` [PATCH 08/11] crypto: stat - remove unused mutex Eric Biggers
2019-01-10 20:18 ` [PATCH 09/11] crypto: af_alg - make some functions static Eric Biggers
2019-01-10 20:18 ` [PATCH 10/11] crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl() Eric Biggers
2019-01-10 20:18 ` [PATCH 11/11] crypto: af_alg - remove redundant initializations of sk_family Eric Biggers
2019-01-18 10:57 ` [PATCH 00/11] crypto: misc fixes/cleanups Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).