Skip to contentSkip to conversation

crypto: misc fixes/cleanups

PATCH In review Eric Biggers 2 participants 13 messages Jan 10, 2019 – Jan 18, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover crypto: misc fixes/cleanups

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(-)
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#1 lore raw

PATCH 1/11 crypto: gcm - use correct endianness type in gcm_hash_len()

From: Eric Biggers <[email protected]>

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.

---
 crypto/gcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/gcm.c +1 -1
index e438492db2ca2..bbce31f6199ba 100644
@@ -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);
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#2 lore raw

PATCH 2/11 crypto: rsa-pkcs1pad - include <crypto/internal/rsa.h>

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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 <[email protected]>
---
 crypto/rsa-pkcs1pad.c | 1 +
 1 file changed, 1 insertion(+)
crypto/rsa-pkcs1pad.c +1 -0
index cfc04e15fd975..0a6680ca8cb6f 100644
@@ -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>
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#3 lore raw

PATCH 3/11 crypto: streebog - use correct endianness type

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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 <[email protected]>
---
 crypto/streebog_generic.c | 2 +-
 include/crypto/streebog.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
crypto/streebog_generic.c +1 -1
index 03272a22afcec..5a2eafed9c29f 100644
@@ -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;
 }
include/crypto/streebog.h +1 -1
index 4af119f7e07b9..856e32af86574 100644
@@ -19,7 +19,7 @@
 #define STREEBOG_BLOCK_SIZE	64
 
 struct streebog_uint512 {
-	u64 qword[8];
+	__le64 qword[8];
 };
 
 struct streebog_state {
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#4 lore raw

PATCH 4/11 crypto: testmgr - handle endianness correctly in alg_test_crc32c()

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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
---
 crypto/testmgr.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
crypto/testmgr.c +5 -5
index 0f684a414acbe..10b7208bd40be 100644
@@ -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);
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#5 lore raw

PATCH 5/11 crypto: user - forward declare crypto_nlsk

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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 <[email protected]>
---
 crypto/crypto_user_stat.c            | 2 --
 include/crypto/internal/cryptouser.h | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)
crypto/crypto_user_stat.c +0 -2
index 3e9a53233d804..d4d1cb2bedd7f 100644
@@ -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;
include/crypto/internal/cryptouser.h +2 -0
index 40623f4457df6..8c602b187c58a 100644
@@ -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
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#6 lore raw

PATCH 6/11 crypto: x86/aesni-gcm - make 'struct aesni_gcm_tfm_s' static const

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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.

---
 arch/x86/crypto/aesni-intel_glue.c | 34 ++++++++++++------------------
 1 file changed, 13 insertions(+), 21 deletions(-)
arch/x86/crypto/aesni-intel_glue.c +13 -21
index 1321700d6647f..9b5ccde3ef315 100644
@@ -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;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#7 lore raw

PATCH 7/11 crypto: tgr192 - fix unaligned memory access

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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

Fixes 06ace7a9bafe ("[CRYPTO] Use standard byte order macros wherever possible")
---
 crypto/tgr192.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
crypto/tgr192.c +3 -3
index 022d3dd76c3b2..f8e1d9f9938f5 100644
@@ -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;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#8 lore raw

PATCH 8/11 crypto: stat - remove unused mutex

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

crypto_cfg_mutex in crypto_user_stat.c is unused. Remove it.

Cc Corentin Labbe <[email protected]>
---
 crypto/crypto_user_stat.c | 2 --
 1 file changed, 2 deletions(-)
crypto/crypto_user_stat.c +0 -2
index d4d1cb2bedd7f..a03f326a63d32 100644
@@ -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;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#9 lore raw

PATCH 9/11 crypto: af_alg - make some functions static

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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

---
 crypto/af_alg.c         | 20 +++++++-------------
 include/crypto/if_alg.h |  7 -------
 2 files changed, 7 insertions(+), 20 deletions(-)
crypto/af_alg.c +7 -13
index 17eb09d222ff4..ccae4a7ada8ab 100644
@@ -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
include/crypto/if_alg.h +0 -7
index 482461d8931d9..0d464db74bf53 100644
@@ -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,
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#10 lore raw

PATCH 10/11 crypto: af_alg - use list_for_each_entry() in af_alg_count_tsgl()

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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.

---
 crypto/af_alg.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
crypto/af_alg.c +5 -5
index ccae4a7ada8ab..1dd573a441279 100644
@@ -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;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#11 lore raw

PATCH 11/11 crypto: af_alg - remove redundant initializations of sk_family

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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.

---
 crypto/af_alg.c | 3 ---
 1 file changed, 3 deletions(-)
crypto/af_alg.c +0 -3
index 1dd573a441279..c5937c8127999 100644
@@ -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;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
maintainer
#12 lore raw
In reply to Eric Biggers
Quoted 19 lines · Eric Biggers

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

Quoted 12 lines
 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.

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