summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2018-11-03 17:56:03 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2018-11-09 04:41:39 -0500
commit37db69e0b4923bff331820ee6969681937d8b065 (patch)
tree2ee519e8fc4e7d04122ec5efbf406ffc8168496a
parented848b652cc6a7a3e7f5e539edc3c2009366093e (diff)
crypto: user - clean up report structure copying
There have been a pretty ridiculous number of issues with initializing the report structures that are copied to userspace by NETLINK_CRYPTO. Commit 4473710df1f8 ("crypto: user - Prepare for CRYPTO_MAX_ALG_NAME expansion") replaced some strncpy()s with strlcpy()s, thereby introducing information leaks. Later two other people tried to replace other strncpy()s with strlcpy() too, which would have introduced even more information leaks: - https://lore.kernel.org/patchwork/patch/954991/ - https://patchwork.kernel.org/patch/10434351/ Commit cac5818c25d0 ("crypto: user - Implement a generic crypto statistics") also uses the buggy strlcpy() approach and therefore leaks uninitialized memory to userspace. A fix was proposed, but it was originally incomplete. Seeing as how apparently no one can get this right with the current approach, change all the reporting functions to: - Start by memsetting the report structure to 0. This guarantees it's always initialized, regardless of what happens later. - Initialize all strings using strscpy(). This is safe after the memset, ensures null termination of long strings, avoids unnecessary work, and avoids the -Wstringop-truncation warnings from gcc. - Use sizeof(var) instead of sizeof(type). This is more robust against copy+paste errors. For simplicity, also reuse the -EMSGSIZE return value from nla_put(). Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/ablkcipher.c32
-rw-r--r--crypto/acompress.c10
-rw-r--r--crypto/aead.c14
-rw-r--r--crypto/ahash.c12
-rw-r--r--crypto/akcipher.c11
-rw-r--r--crypto/blkcipher.c16
-rw-r--r--crypto/crypto_user_base.c38
-rw-r--r--crypto/crypto_user_stat.c102
-rw-r--r--crypto/kpp.c10
-rw-r--r--crypto/rng.c12
-rw-r--r--crypto/scompress.c11
-rw-r--r--crypto/shash.c12
-rw-r--r--crypto/skcipher.c15
13 files changed, 96 insertions, 199 deletions
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index 8882e90e868e..b5e9ce19d324 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -365,23 +365,19 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
365{ 365{
366 struct crypto_report_blkcipher rblkcipher; 366 struct crypto_report_blkcipher rblkcipher;
367 367
368 strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type)); 368 memset(&rblkcipher, 0, sizeof(rblkcipher));
369 strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>", 369
370 strscpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
371 strscpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
370 sizeof(rblkcipher.geniv)); 372 sizeof(rblkcipher.geniv));
371 rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0';
372 373
373 rblkcipher.blocksize = alg->cra_blocksize; 374 rblkcipher.blocksize = alg->cra_blocksize;
374 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; 375 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
375 rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize; 376 rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
376 rblkcipher.ivsize = alg->cra_ablkcipher.ivsize; 377 rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
377 378
378 if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, 379 return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
379 sizeof(struct crypto_report_blkcipher), &rblkcipher)) 380 sizeof(rblkcipher), &rblkcipher);
380 goto nla_put_failure;
381 return 0;
382
383nla_put_failure:
384 return -EMSGSIZE;
385} 381}
386#else 382#else
387static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) 383static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
@@ -440,23 +436,19 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
440{ 436{
441 struct crypto_report_blkcipher rblkcipher; 437 struct crypto_report_blkcipher rblkcipher;
442 438
443 strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type)); 439 memset(&rblkcipher, 0, sizeof(rblkcipher));
444 strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>", 440
441 strscpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
442 strscpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
445 sizeof(rblkcipher.geniv)); 443 sizeof(rblkcipher.geniv));
446 rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0';
447 444
448 rblkcipher.blocksize = alg->cra_blocksize; 445 rblkcipher.blocksize = alg->cra_blocksize;
449 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; 446 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
450 rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize; 447 rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
451 rblkcipher.ivsize = alg->cra_ablkcipher.ivsize; 448 rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
452 449
453 if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, 450 return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
454 sizeof(struct crypto_report_blkcipher), &rblkcipher)) 451 sizeof(rblkcipher), &rblkcipher);
455 goto nla_put_failure;
456 return 0;
457
458nla_put_failure:
459 return -EMSGSIZE;
460} 452}
461#else 453#else
462static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) 454static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/acompress.c b/crypto/acompress.c
index 1544b7c057fb..0c5bedd06e70 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -33,15 +33,11 @@ static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
33{ 33{
34 struct crypto_report_acomp racomp; 34 struct crypto_report_acomp racomp;
35 35
36 strncpy(racomp.type, "acomp", sizeof(racomp.type)); 36 memset(&racomp, 0, sizeof(racomp));
37 37
38 if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, 38 strscpy(racomp.type, "acomp", sizeof(racomp.type));
39 sizeof(struct crypto_report_acomp), &racomp))
40 goto nla_put_failure;
41 return 0;
42 39
43nla_put_failure: 40 return nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, sizeof(racomp), &racomp);
44 return -EMSGSIZE;
45} 41}
46#else 42#else
47static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg) 43static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/aead.c b/crypto/aead.c
index 60b3bbe973e7..189c52d1f63a 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -119,20 +119,16 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
119 struct crypto_report_aead raead; 119 struct crypto_report_aead raead;
120 struct aead_alg *aead = container_of(alg, struct aead_alg, base); 120 struct aead_alg *aead = container_of(alg, struct aead_alg, base);
121 121
122 strncpy(raead.type, "aead", sizeof(raead.type)); 122 memset(&raead, 0, sizeof(raead));
123 strncpy(raead.geniv, "<none>", sizeof(raead.geniv)); 123
124 strscpy(raead.type, "aead", sizeof(raead.type));
125 strscpy(raead.geniv, "<none>", sizeof(raead.geniv));
124 126
125 raead.blocksize = alg->cra_blocksize; 127 raead.blocksize = alg->cra_blocksize;
126 raead.maxauthsize = aead->maxauthsize; 128 raead.maxauthsize = aead->maxauthsize;
127 raead.ivsize = aead->ivsize; 129 raead.ivsize = aead->ivsize;
128 130
129 if (nla_put(skb, CRYPTOCFGA_REPORT_AEAD, 131 return nla_put(skb, CRYPTOCFGA_REPORT_AEAD, sizeof(raead), &raead);
130 sizeof(struct crypto_report_aead), &raead))
131 goto nla_put_failure;
132 return 0;
133
134nla_put_failure:
135 return -EMSGSIZE;
136} 132}
137#else 133#else
138static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg) 134static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/ahash.c b/crypto/ahash.c
index e21667b4e10a..3a348fbcf8f9 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -498,18 +498,14 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
498{ 498{
499 struct crypto_report_hash rhash; 499 struct crypto_report_hash rhash;
500 500
501 strncpy(rhash.type, "ahash", sizeof(rhash.type)); 501 memset(&rhash, 0, sizeof(rhash));
502
503 strscpy(rhash.type, "ahash", sizeof(rhash.type));
502 504
503 rhash.blocksize = alg->cra_blocksize; 505 rhash.blocksize = alg->cra_blocksize;
504 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize; 506 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
505 507
506 if (nla_put(skb, CRYPTOCFGA_REPORT_HASH, 508 return nla_put(skb, CRYPTOCFGA_REPORT_HASH, sizeof(rhash), &rhash);
507 sizeof(struct crypto_report_hash), &rhash))
508 goto nla_put_failure;
509 return 0;
510
511nla_put_failure:
512 return -EMSGSIZE;
513} 509}
514#else 510#else
515static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg) 511static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/akcipher.c b/crypto/akcipher.c
index cfbdb06d8ca8..0cbeae137e0a 100644
--- a/crypto/akcipher.c
+++ b/crypto/akcipher.c
@@ -30,15 +30,12 @@ static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30{ 30{
31 struct crypto_report_akcipher rakcipher; 31 struct crypto_report_akcipher rakcipher;
32 32
33 strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); 33 memset(&rakcipher, 0, sizeof(rakcipher));
34 34
35 if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, 35 strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
36 sizeof(struct crypto_report_akcipher), &rakcipher))
37 goto nla_put_failure;
38 return 0;
39 36
40nla_put_failure: 37 return nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
41 return -EMSGSIZE; 38 sizeof(rakcipher), &rakcipher);
42} 39}
43#else 40#else
44static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) 41static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index f93abf13b5d4..193237514e90 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -507,23 +507,19 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
507{ 507{
508 struct crypto_report_blkcipher rblkcipher; 508 struct crypto_report_blkcipher rblkcipher;
509 509
510 strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type)); 510 memset(&rblkcipher, 0, sizeof(rblkcipher));
511 strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>", 511
512 strscpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
513 strscpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
512 sizeof(rblkcipher.geniv)); 514 sizeof(rblkcipher.geniv));
513 rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0';
514 515
515 rblkcipher.blocksize = alg->cra_blocksize; 516 rblkcipher.blocksize = alg->cra_blocksize;
516 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize; 517 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
517 rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize; 518 rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
518 rblkcipher.ivsize = alg->cra_blkcipher.ivsize; 519 rblkcipher.ivsize = alg->cra_blkcipher.ivsize;
519 520
520 if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, 521 return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
521 sizeof(struct crypto_report_blkcipher), &rblkcipher)) 522 sizeof(rblkcipher), &rblkcipher);
522 goto nla_put_failure;
523 return 0;
524
525nla_put_failure:
526 return -EMSGSIZE;
527} 523}
528#else 524#else
529static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) 525static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/crypto_user_base.c b/crypto/crypto_user_base.c
index 1ecd9b08e38f..7021efbb35a1 100644
--- a/crypto/crypto_user_base.c
+++ b/crypto/crypto_user_base.c
@@ -84,42 +84,38 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
84{ 84{
85 struct crypto_report_cipher rcipher; 85 struct crypto_report_cipher rcipher;
86 86
87 strncpy(rcipher.type, "cipher", sizeof(rcipher.type)); 87 memset(&rcipher, 0, sizeof(rcipher));
88
89 strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
88 90
89 rcipher.blocksize = alg->cra_blocksize; 91 rcipher.blocksize = alg->cra_blocksize;
90 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize; 92 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
91 rcipher.max_keysize = alg->cra_cipher.cia_max_keysize; 93 rcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
92 94
93 if (nla_put(skb, CRYPTOCFGA_REPORT_CIPHER, 95 return nla_put(skb, CRYPTOCFGA_REPORT_CIPHER,
94 sizeof(struct crypto_report_cipher), &rcipher)) 96 sizeof(rcipher), &rcipher);
95 goto nla_put_failure;
96 return 0;
97
98nla_put_failure:
99 return -EMSGSIZE;
100} 97}
101 98
102static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) 99static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
103{ 100{
104 struct crypto_report_comp rcomp; 101 struct crypto_report_comp rcomp;
105 102
106 strncpy(rcomp.type, "compression", sizeof(rcomp.type)); 103 memset(&rcomp, 0, sizeof(rcomp));
107 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
108 sizeof(struct crypto_report_comp), &rcomp))
109 goto nla_put_failure;
110 return 0;
111 104
112nla_put_failure: 105 strscpy(rcomp.type, "compression", sizeof(rcomp.type));
113 return -EMSGSIZE; 106
107 return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, sizeof(rcomp), &rcomp);
114} 108}
115 109
116static int crypto_report_one(struct crypto_alg *alg, 110static int crypto_report_one(struct crypto_alg *alg,
117 struct crypto_user_alg *ualg, struct sk_buff *skb) 111 struct crypto_user_alg *ualg, struct sk_buff *skb)
118{ 112{
119 strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name)); 113 memset(ualg, 0, sizeof(*ualg));
120 strncpy(ualg->cru_driver_name, alg->cra_driver_name, 114
115 strscpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
116 strscpy(ualg->cru_driver_name, alg->cra_driver_name,
121 sizeof(ualg->cru_driver_name)); 117 sizeof(ualg->cru_driver_name));
122 strncpy(ualg->cru_module_name, module_name(alg->cra_module), 118 strscpy(ualg->cru_module_name, module_name(alg->cra_module),
123 sizeof(ualg->cru_module_name)); 119 sizeof(ualg->cru_module_name));
124 120
125 ualg->cru_type = 0; 121 ualg->cru_type = 0;
@@ -132,9 +128,9 @@ static int crypto_report_one(struct crypto_alg *alg,
132 if (alg->cra_flags & CRYPTO_ALG_LARVAL) { 128 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
133 struct crypto_report_larval rl; 129 struct crypto_report_larval rl;
134 130
135 strncpy(rl.type, "larval", sizeof(rl.type)); 131 memset(&rl, 0, sizeof(rl));
136 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, 132 strscpy(rl.type, "larval", sizeof(rl.type));
137 sizeof(struct crypto_report_larval), &rl)) 133 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, sizeof(rl), &rl))
138 goto nla_put_failure; 134 goto nla_put_failure;
139 goto out; 135 goto out;
140 } 136 }
diff --git a/crypto/crypto_user_stat.c b/crypto/crypto_user_stat.c
index 1dfaa0ccd555..a6fb2e6f618d 100644
--- a/crypto/crypto_user_stat.c
+++ b/crypto/crypto_user_stat.c
@@ -39,7 +39,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
39 39
40 memset(&raead, 0, sizeof(raead)); 40 memset(&raead, 0, sizeof(raead));
41 41
42 strncpy(raead.type, "aead", sizeof(raead.type)); 42 strscpy(raead.type, "aead", sizeof(raead.type));
43 43
44 v32 = atomic_read(&alg->encrypt_cnt); 44 v32 = atomic_read(&alg->encrypt_cnt);
45 raead.stat_encrypt_cnt = v32; 45 raead.stat_encrypt_cnt = v32;
@@ -52,13 +52,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
52 v32 = atomic_read(&alg->aead_err_cnt); 52 v32 = atomic_read(&alg->aead_err_cnt);
53 raead.stat_aead_err_cnt = v32; 53 raead.stat_aead_err_cnt = v32;
54 54
55 if (nla_put(skb, CRYPTOCFGA_STAT_AEAD, 55 return nla_put(skb, CRYPTOCFGA_STAT_AEAD, sizeof(raead), &raead);
56 sizeof(struct crypto_stat), &raead))
57 goto nla_put_failure;
58 return 0;
59
60nla_put_failure:
61 return -EMSGSIZE;
62} 56}
63 57
64static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) 58static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
@@ -69,7 +63,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
69 63
70 memset(&rcipher, 0, sizeof(rcipher)); 64 memset(&rcipher, 0, sizeof(rcipher));
71 65
72 strlcpy(rcipher.type, "cipher", sizeof(rcipher.type)); 66 strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
73 67
74 v32 = atomic_read(&alg->encrypt_cnt); 68 v32 = atomic_read(&alg->encrypt_cnt);
75 rcipher.stat_encrypt_cnt = v32; 69 rcipher.stat_encrypt_cnt = v32;
@@ -82,13 +76,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
82 v32 = atomic_read(&alg->cipher_err_cnt); 76 v32 = atomic_read(&alg->cipher_err_cnt);
83 rcipher.stat_cipher_err_cnt = v32; 77 rcipher.stat_cipher_err_cnt = v32;
84 78
85 if (nla_put(skb, CRYPTOCFGA_STAT_CIPHER, 79 return nla_put(skb, CRYPTOCFGA_STAT_CIPHER, sizeof(rcipher), &rcipher);
86 sizeof(struct crypto_stat), &rcipher))
87 goto nla_put_failure;
88 return 0;
89
90nla_put_failure:
91 return -EMSGSIZE;
92} 80}
93 81
94static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) 82static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
@@ -99,7 +87,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
99 87
100 memset(&rcomp, 0, sizeof(rcomp)); 88 memset(&rcomp, 0, sizeof(rcomp));
101 89
102 strlcpy(rcomp.type, "compression", sizeof(rcomp.type)); 90 strscpy(rcomp.type, "compression", sizeof(rcomp.type));
103 v32 = atomic_read(&alg->compress_cnt); 91 v32 = atomic_read(&alg->compress_cnt);
104 rcomp.stat_compress_cnt = v32; 92 rcomp.stat_compress_cnt = v32;
105 v64 = atomic64_read(&alg->compress_tlen); 93 v64 = atomic64_read(&alg->compress_tlen);
@@ -111,13 +99,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
111 v32 = atomic_read(&alg->cipher_err_cnt); 99 v32 = atomic_read(&alg->cipher_err_cnt);
112 rcomp.stat_compress_err_cnt = v32; 100 rcomp.stat_compress_err_cnt = v32;
113 101
114 if (nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, 102 return nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, sizeof(rcomp), &rcomp);
115 sizeof(struct crypto_stat), &rcomp))
116 goto nla_put_failure;
117 return 0;
118
119nla_put_failure:
120 return -EMSGSIZE;
121} 103}
122 104
123static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg) 105static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
@@ -128,7 +110,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
128 110
129 memset(&racomp, 0, sizeof(racomp)); 111 memset(&racomp, 0, sizeof(racomp));
130 112
131 strlcpy(racomp.type, "acomp", sizeof(racomp.type)); 113 strscpy(racomp.type, "acomp", sizeof(racomp.type));
132 v32 = atomic_read(&alg->compress_cnt); 114 v32 = atomic_read(&alg->compress_cnt);
133 racomp.stat_compress_cnt = v32; 115 racomp.stat_compress_cnt = v32;
134 v64 = atomic64_read(&alg->compress_tlen); 116 v64 = atomic64_read(&alg->compress_tlen);
@@ -140,13 +122,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
140 v32 = atomic_read(&alg->cipher_err_cnt); 122 v32 = atomic_read(&alg->cipher_err_cnt);
141 racomp.stat_compress_err_cnt = v32; 123 racomp.stat_compress_err_cnt = v32;
142 124
143 if (nla_put(skb, CRYPTOCFGA_STAT_ACOMP, 125 return nla_put(skb, CRYPTOCFGA_STAT_ACOMP, sizeof(racomp), &racomp);
144 sizeof(struct crypto_stat), &racomp))
145 goto nla_put_failure;
146 return 0;
147
148nla_put_failure:
149 return -EMSGSIZE;
150} 126}
151 127
152static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) 128static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
@@ -157,7 +133,7 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
157 133
158 memset(&rakcipher, 0, sizeof(rakcipher)); 134 memset(&rakcipher, 0, sizeof(rakcipher));
159 135
160 strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); 136 strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
161 v32 = atomic_read(&alg->encrypt_cnt); 137 v32 = atomic_read(&alg->encrypt_cnt);
162 rakcipher.stat_encrypt_cnt = v32; 138 rakcipher.stat_encrypt_cnt = v32;
163 v64 = atomic64_read(&alg->encrypt_tlen); 139 v64 = atomic64_read(&alg->encrypt_tlen);
@@ -173,13 +149,8 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
173 v32 = atomic_read(&alg->akcipher_err_cnt); 149 v32 = atomic_read(&alg->akcipher_err_cnt);
174 rakcipher.stat_akcipher_err_cnt = v32; 150 rakcipher.stat_akcipher_err_cnt = v32;
175 151
176 if (nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER, 152 return nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER,
177 sizeof(struct crypto_stat), &rakcipher)) 153 sizeof(rakcipher), &rakcipher);
178 goto nla_put_failure;
179 return 0;
180
181nla_put_failure:
182 return -EMSGSIZE;
183} 154}
184 155
185static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg) 156static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
@@ -189,7 +160,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
189 160
190 memset(&rkpp, 0, sizeof(rkpp)); 161 memset(&rkpp, 0, sizeof(rkpp));
191 162
192 strlcpy(rkpp.type, "kpp", sizeof(rkpp.type)); 163 strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
193 164
194 v = atomic_read(&alg->setsecret_cnt); 165 v = atomic_read(&alg->setsecret_cnt);
195 rkpp.stat_setsecret_cnt = v; 166 rkpp.stat_setsecret_cnt = v;
@@ -200,13 +171,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
200 v = atomic_read(&alg->kpp_err_cnt); 171 v = atomic_read(&alg->kpp_err_cnt);
201 rkpp.stat_kpp_err_cnt = v; 172 rkpp.stat_kpp_err_cnt = v;
202 173
203 if (nla_put(skb, CRYPTOCFGA_STAT_KPP, 174 return nla_put(skb, CRYPTOCFGA_STAT_KPP, sizeof(rkpp), &rkpp);
204 sizeof(struct crypto_stat), &rkpp))
205 goto nla_put_failure;
206 return 0;
207
208nla_put_failure:
209 return -EMSGSIZE;
210} 175}
211 176
212static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg) 177static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
@@ -217,7 +182,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
217 182
218 memset(&rhash, 0, sizeof(rhash)); 183 memset(&rhash, 0, sizeof(rhash));
219 184
220 strncpy(rhash.type, "ahash", sizeof(rhash.type)); 185 strscpy(rhash.type, "ahash", sizeof(rhash.type));
221 186
222 v32 = atomic_read(&alg->hash_cnt); 187 v32 = atomic_read(&alg->hash_cnt);
223 rhash.stat_hash_cnt = v32; 188 rhash.stat_hash_cnt = v32;
@@ -226,13 +191,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
226 v32 = atomic_read(&alg->hash_err_cnt); 191 v32 = atomic_read(&alg->hash_err_cnt);
227 rhash.stat_hash_err_cnt = v32; 192 rhash.stat_hash_err_cnt = v32;
228 193
229 if (nla_put(skb, CRYPTOCFGA_STAT_HASH, 194 return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
230 sizeof(struct crypto_stat), &rhash))
231 goto nla_put_failure;
232 return 0;
233
234nla_put_failure:
235 return -EMSGSIZE;
236} 195}
237 196
238static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg) 197static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
@@ -243,7 +202,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
243 202
244 memset(&rhash, 0, sizeof(rhash)); 203 memset(&rhash, 0, sizeof(rhash));
245 204
246 strncpy(rhash.type, "shash", sizeof(rhash.type)); 205 strscpy(rhash.type, "shash", sizeof(rhash.type));
247 206
248 v32 = atomic_read(&alg->hash_cnt); 207 v32 = atomic_read(&alg->hash_cnt);
249 rhash.stat_hash_cnt = v32; 208 rhash.stat_hash_cnt = v32;
@@ -252,13 +211,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
252 v32 = atomic_read(&alg->hash_err_cnt); 211 v32 = atomic_read(&alg->hash_err_cnt);
253 rhash.stat_hash_err_cnt = v32; 212 rhash.stat_hash_err_cnt = v32;
254 213
255 if (nla_put(skb, CRYPTOCFGA_STAT_HASH, 214 return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
256 sizeof(struct crypto_stat), &rhash))
257 goto nla_put_failure;
258 return 0;
259
260nla_put_failure:
261 return -EMSGSIZE;
262} 215}
263 216
264static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg) 217static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
@@ -269,7 +222,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
269 222
270 memset(&rrng, 0, sizeof(rrng)); 223 memset(&rrng, 0, sizeof(rrng));
271 224
272 strncpy(rrng.type, "rng", sizeof(rrng.type)); 225 strscpy(rrng.type, "rng", sizeof(rrng.type));
273 226
274 v32 = atomic_read(&alg->generate_cnt); 227 v32 = atomic_read(&alg->generate_cnt);
275 rrng.stat_generate_cnt = v32; 228 rrng.stat_generate_cnt = v32;
@@ -280,13 +233,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
280 v32 = atomic_read(&alg->hash_err_cnt); 233 v32 = atomic_read(&alg->hash_err_cnt);
281 rrng.stat_rng_err_cnt = v32; 234 rrng.stat_rng_err_cnt = v32;
282 235
283 if (nla_put(skb, CRYPTOCFGA_STAT_RNG, 236 return nla_put(skb, CRYPTOCFGA_STAT_RNG, sizeof(rrng), &rrng);
284 sizeof(struct crypto_stat), &rrng))
285 goto nla_put_failure;
286 return 0;
287
288nla_put_failure:
289 return -EMSGSIZE;
290} 237}
291 238
292static int crypto_reportstat_one(struct crypto_alg *alg, 239static int crypto_reportstat_one(struct crypto_alg *alg,
@@ -295,10 +242,10 @@ static int crypto_reportstat_one(struct crypto_alg *alg,
295{ 242{
296 memset(ualg, 0, sizeof(*ualg)); 243 memset(ualg, 0, sizeof(*ualg));
297 244
298 strlcpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name)); 245 strscpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
299 strlcpy(ualg->cru_driver_name, alg->cra_driver_name, 246 strscpy(ualg->cru_driver_name, alg->cra_driver_name,
300 sizeof(ualg->cru_driver_name)); 247 sizeof(ualg->cru_driver_name));
301 strlcpy(ualg->cru_module_name, module_name(alg->cra_module), 248 strscpy(ualg->cru_module_name, module_name(alg->cra_module),
302 sizeof(ualg->cru_module_name)); 249 sizeof(ualg->cru_module_name));
303 250
304 ualg->cru_type = 0; 251 ualg->cru_type = 0;
@@ -312,9 +259,8 @@ static int crypto_reportstat_one(struct crypto_alg *alg,
312 struct crypto_stat rl; 259 struct crypto_stat rl;
313 260
314 memset(&rl, 0, sizeof(rl)); 261 memset(&rl, 0, sizeof(rl));
315 strlcpy(rl.type, "larval", sizeof(rl.type)); 262 strscpy(rl.type, "larval", sizeof(rl.type));
316 if (nla_put(skb, CRYPTOCFGA_STAT_LARVAL, 263 if (nla_put(skb, CRYPTOCFGA_STAT_LARVAL, sizeof(rl), &rl))
317 sizeof(struct crypto_stat), &rl))
318 goto nla_put_failure; 264 goto nla_put_failure;
319 goto out; 265 goto out;
320 } 266 }
diff --git a/crypto/kpp.c b/crypto/kpp.c
index a90edc27af77..bc2f1006a2f7 100644
--- a/crypto/kpp.c
+++ b/crypto/kpp.c
@@ -30,15 +30,11 @@ static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg)
30{ 30{
31 struct crypto_report_kpp rkpp; 31 struct crypto_report_kpp rkpp;
32 32
33 strncpy(rkpp.type, "kpp", sizeof(rkpp.type)); 33 memset(&rkpp, 0, sizeof(rkpp));
34 34
35 if (nla_put(skb, CRYPTOCFGA_REPORT_KPP, 35 strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
36 sizeof(struct crypto_report_kpp), &rkpp))
37 goto nla_put_failure;
38 return 0;
39 36
40nla_put_failure: 37 return nla_put(skb, CRYPTOCFGA_REPORT_KPP, sizeof(rkpp), &rkpp);
41 return -EMSGSIZE;
42} 38}
43#else 39#else
44static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg) 40static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/rng.c b/crypto/rng.c
index 547f16ecbfb0..2406501b90b7 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -74,17 +74,13 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
74{ 74{
75 struct crypto_report_rng rrng; 75 struct crypto_report_rng rrng;
76 76
77 strncpy(rrng.type, "rng", sizeof(rrng.type)); 77 memset(&rrng, 0, sizeof(rrng));
78 78
79 rrng.seedsize = seedsize(alg); 79 strscpy(rrng.type, "rng", sizeof(rrng.type));
80 80
81 if (nla_put(skb, CRYPTOCFGA_REPORT_RNG, 81 rrng.seedsize = seedsize(alg);
82 sizeof(struct crypto_report_rng), &rrng))
83 goto nla_put_failure;
84 return 0;
85 82
86nla_put_failure: 83 return nla_put(skb, CRYPTOCFGA_REPORT_RNG, sizeof(rrng), &rrng);
87 return -EMSGSIZE;
88} 84}
89#else 85#else
90static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg) 86static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/scompress.c b/crypto/scompress.c
index 968bbcf65c94..6f8305f8c300 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -40,15 +40,12 @@ static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
40{ 40{
41 struct crypto_report_comp rscomp; 41 struct crypto_report_comp rscomp;
42 42
43 strncpy(rscomp.type, "scomp", sizeof(rscomp.type)); 43 memset(&rscomp, 0, sizeof(rscomp));
44 44
45 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, 45 strscpy(rscomp.type, "scomp", sizeof(rscomp.type));
46 sizeof(struct crypto_report_comp), &rscomp))
47 goto nla_put_failure;
48 return 0;
49 46
50nla_put_failure: 47 return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
51 return -EMSGSIZE; 48 sizeof(rscomp), &rscomp);
52} 49}
53#else 50#else
54static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) 51static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/shash.c b/crypto/shash.c
index d21f04d70dce..44d297b82a8f 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -408,18 +408,14 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
408 struct crypto_report_hash rhash; 408 struct crypto_report_hash rhash;
409 struct shash_alg *salg = __crypto_shash_alg(alg); 409 struct shash_alg *salg = __crypto_shash_alg(alg);
410 410
411 strncpy(rhash.type, "shash", sizeof(rhash.type)); 411 memset(&rhash, 0, sizeof(rhash));
412
413 strscpy(rhash.type, "shash", sizeof(rhash.type));
412 414
413 rhash.blocksize = alg->cra_blocksize; 415 rhash.blocksize = alg->cra_blocksize;
414 rhash.digestsize = salg->digestsize; 416 rhash.digestsize = salg->digestsize;
415 417
416 if (nla_put(skb, CRYPTOCFGA_REPORT_HASH, 418 return nla_put(skb, CRYPTOCFGA_REPORT_HASH, sizeof(rhash), &rhash);
417 sizeof(struct crypto_report_hash), &rhash))
418 goto nla_put_failure;
419 return 0;
420
421nla_put_failure:
422 return -EMSGSIZE;
423} 419}
424#else 420#else
425static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg) 421static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 4caab81d2d02..17be8d9c714e 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -897,21 +897,18 @@ static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
897 struct skcipher_alg *skcipher = container_of(alg, struct skcipher_alg, 897 struct skcipher_alg *skcipher = container_of(alg, struct skcipher_alg,
898 base); 898 base);
899 899
900 strncpy(rblkcipher.type, "skcipher", sizeof(rblkcipher.type)); 900 memset(&rblkcipher, 0, sizeof(rblkcipher));
901 strncpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv)); 901
902 strscpy(rblkcipher.type, "skcipher", sizeof(rblkcipher.type));
903 strscpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
902 904
903 rblkcipher.blocksize = alg->cra_blocksize; 905 rblkcipher.blocksize = alg->cra_blocksize;
904 rblkcipher.min_keysize = skcipher->min_keysize; 906 rblkcipher.min_keysize = skcipher->min_keysize;
905 rblkcipher.max_keysize = skcipher->max_keysize; 907 rblkcipher.max_keysize = skcipher->max_keysize;
906 rblkcipher.ivsize = skcipher->ivsize; 908 rblkcipher.ivsize = skcipher->ivsize;
907 909
908 if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, 910 return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
909 sizeof(struct crypto_report_blkcipher), &rblkcipher)) 911 sizeof(rblkcipher), &rblkcipher);
910 goto nla_put_failure;
911 return 0;
912
913nla_put_failure:
914 return -EMSGSIZE;
915} 912}
916#else 913#else
917static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg) 914static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg)