diff options
author | Corentin Labbe <clabbe@baylibre.com> | 2018-11-29 09:42:18 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-12-07 01:15:00 -0500 |
commit | 6e8e72cd206e2ba68801e4f2490f639d41808c8d (patch) | |
tree | 6c89421ccb76ab0abe12e0d132c4c9a6a9de914b /crypto | |
parent | a6a31385364ca0f7b98ace0bad93d793f07f97f3 (diff) |
crypto: user - convert all stats from u32 to u64
All the 32-bit fields need to be 64-bit. In some cases, UINT32_MAX crypto
operations can be done in seconds.
Reported-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/algapi.c | 10 | ||||
-rw-r--r-- | crypto/crypto_user_stat.c | 114 |
2 files changed, 58 insertions, 66 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index f5396c88e8cd..42fe316f80ee 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c | |||
@@ -259,13 +259,13 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) | |||
259 | list_add(&larval->alg.cra_list, &crypto_alg_list); | 259 | list_add(&larval->alg.cra_list, &crypto_alg_list); |
260 | 260 | ||
261 | #ifdef CONFIG_CRYPTO_STATS | 261 | #ifdef CONFIG_CRYPTO_STATS |
262 | atomic_set(&alg->encrypt_cnt, 0); | 262 | atomic64_set(&alg->encrypt_cnt, 0); |
263 | atomic_set(&alg->decrypt_cnt, 0); | 263 | atomic64_set(&alg->decrypt_cnt, 0); |
264 | atomic64_set(&alg->encrypt_tlen, 0); | 264 | atomic64_set(&alg->encrypt_tlen, 0); |
265 | atomic64_set(&alg->decrypt_tlen, 0); | 265 | atomic64_set(&alg->decrypt_tlen, 0); |
266 | atomic_set(&alg->verify_cnt, 0); | 266 | atomic64_set(&alg->verify_cnt, 0); |
267 | atomic_set(&alg->cipher_err_cnt, 0); | 267 | atomic64_set(&alg->cipher_err_cnt, 0); |
268 | atomic_set(&alg->sign_cnt, 0); | 268 | atomic64_set(&alg->sign_cnt, 0); |
269 | #endif | 269 | #endif |
270 | 270 | ||
271 | out: | 271 | out: |
diff --git a/crypto/crypto_user_stat.c b/crypto/crypto_user_stat.c index a6fb2e6f618d..352569f378a0 100644 --- a/crypto/crypto_user_stat.c +++ b/crypto/crypto_user_stat.c | |||
@@ -35,22 +35,21 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg) | |||
35 | { | 35 | { |
36 | struct crypto_stat raead; | 36 | struct crypto_stat raead; |
37 | u64 v64; | 37 | u64 v64; |
38 | u32 v32; | ||
39 | 38 | ||
40 | memset(&raead, 0, sizeof(raead)); | 39 | memset(&raead, 0, sizeof(raead)); |
41 | 40 | ||
42 | strscpy(raead.type, "aead", sizeof(raead.type)); | 41 | strscpy(raead.type, "aead", sizeof(raead.type)); |
43 | 42 | ||
44 | v32 = atomic_read(&alg->encrypt_cnt); | 43 | v64 = atomic64_read(&alg->encrypt_cnt); |
45 | raead.stat_encrypt_cnt = v32; | 44 | raead.stat_encrypt_cnt = v64; |
46 | v64 = atomic64_read(&alg->encrypt_tlen); | 45 | v64 = atomic64_read(&alg->encrypt_tlen); |
47 | raead.stat_encrypt_tlen = v64; | 46 | raead.stat_encrypt_tlen = v64; |
48 | v32 = atomic_read(&alg->decrypt_cnt); | 47 | v64 = atomic64_read(&alg->decrypt_cnt); |
49 | raead.stat_decrypt_cnt = v32; | 48 | raead.stat_decrypt_cnt = v64; |
50 | v64 = atomic64_read(&alg->decrypt_tlen); | 49 | v64 = atomic64_read(&alg->decrypt_tlen); |
51 | raead.stat_decrypt_tlen = v64; | 50 | raead.stat_decrypt_tlen = v64; |
52 | v32 = atomic_read(&alg->aead_err_cnt); | 51 | v64 = atomic64_read(&alg->aead_err_cnt); |
53 | raead.stat_aead_err_cnt = v32; | 52 | raead.stat_aead_err_cnt = v64; |
54 | 53 | ||
55 | return nla_put(skb, CRYPTOCFGA_STAT_AEAD, sizeof(raead), &raead); | 54 | return nla_put(skb, CRYPTOCFGA_STAT_AEAD, sizeof(raead), &raead); |
56 | } | 55 | } |
@@ -59,22 +58,21 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) | |||
59 | { | 58 | { |
60 | struct crypto_stat rcipher; | 59 | struct crypto_stat rcipher; |
61 | u64 v64; | 60 | u64 v64; |
62 | u32 v32; | ||
63 | 61 | ||
64 | memset(&rcipher, 0, sizeof(rcipher)); | 62 | memset(&rcipher, 0, sizeof(rcipher)); |
65 | 63 | ||
66 | strscpy(rcipher.type, "cipher", sizeof(rcipher.type)); | 64 | strscpy(rcipher.type, "cipher", sizeof(rcipher.type)); |
67 | 65 | ||
68 | v32 = atomic_read(&alg->encrypt_cnt); | 66 | v64 = atomic64_read(&alg->encrypt_cnt); |
69 | rcipher.stat_encrypt_cnt = v32; | 67 | rcipher.stat_encrypt_cnt = v64; |
70 | v64 = atomic64_read(&alg->encrypt_tlen); | 68 | v64 = atomic64_read(&alg->encrypt_tlen); |
71 | rcipher.stat_encrypt_tlen = v64; | 69 | rcipher.stat_encrypt_tlen = v64; |
72 | v32 = atomic_read(&alg->decrypt_cnt); | 70 | v64 = atomic64_read(&alg->decrypt_cnt); |
73 | rcipher.stat_decrypt_cnt = v32; | 71 | rcipher.stat_decrypt_cnt = v64; |
74 | v64 = atomic64_read(&alg->decrypt_tlen); | 72 | v64 = atomic64_read(&alg->decrypt_tlen); |
75 | rcipher.stat_decrypt_tlen = v64; | 73 | rcipher.stat_decrypt_tlen = v64; |
76 | v32 = atomic_read(&alg->cipher_err_cnt); | 74 | v64 = atomic64_read(&alg->cipher_err_cnt); |
77 | rcipher.stat_cipher_err_cnt = v32; | 75 | rcipher.stat_cipher_err_cnt = v64; |
78 | 76 | ||
79 | return nla_put(skb, CRYPTOCFGA_STAT_CIPHER, sizeof(rcipher), &rcipher); | 77 | return nla_put(skb, CRYPTOCFGA_STAT_CIPHER, sizeof(rcipher), &rcipher); |
80 | } | 78 | } |
@@ -83,21 +81,20 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) | |||
83 | { | 81 | { |
84 | struct crypto_stat rcomp; | 82 | struct crypto_stat rcomp; |
85 | u64 v64; | 83 | u64 v64; |
86 | u32 v32; | ||
87 | 84 | ||
88 | memset(&rcomp, 0, sizeof(rcomp)); | 85 | memset(&rcomp, 0, sizeof(rcomp)); |
89 | 86 | ||
90 | strscpy(rcomp.type, "compression", sizeof(rcomp.type)); | 87 | strscpy(rcomp.type, "compression", sizeof(rcomp.type)); |
91 | v32 = atomic_read(&alg->compress_cnt); | 88 | v64 = atomic64_read(&alg->compress_cnt); |
92 | rcomp.stat_compress_cnt = v32; | 89 | rcomp.stat_compress_cnt = v64; |
93 | v64 = atomic64_read(&alg->compress_tlen); | 90 | v64 = atomic64_read(&alg->compress_tlen); |
94 | rcomp.stat_compress_tlen = v64; | 91 | rcomp.stat_compress_tlen = v64; |
95 | v32 = atomic_read(&alg->decompress_cnt); | 92 | v64 = atomic64_read(&alg->decompress_cnt); |
96 | rcomp.stat_decompress_cnt = v32; | 93 | rcomp.stat_decompress_cnt = v64; |
97 | v64 = atomic64_read(&alg->decompress_tlen); | 94 | v64 = atomic64_read(&alg->decompress_tlen); |
98 | rcomp.stat_decompress_tlen = v64; | 95 | rcomp.stat_decompress_tlen = v64; |
99 | v32 = atomic_read(&alg->cipher_err_cnt); | 96 | v64 = atomic64_read(&alg->cipher_err_cnt); |
100 | rcomp.stat_compress_err_cnt = v32; | 97 | rcomp.stat_compress_err_cnt = v64; |
101 | 98 | ||
102 | return nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, sizeof(rcomp), &rcomp); | 99 | return nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, sizeof(rcomp), &rcomp); |
103 | } | 100 | } |
@@ -106,21 +103,20 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg) | |||
106 | { | 103 | { |
107 | struct crypto_stat racomp; | 104 | struct crypto_stat racomp; |
108 | u64 v64; | 105 | u64 v64; |
109 | u32 v32; | ||
110 | 106 | ||
111 | memset(&racomp, 0, sizeof(racomp)); | 107 | memset(&racomp, 0, sizeof(racomp)); |
112 | 108 | ||
113 | strscpy(racomp.type, "acomp", sizeof(racomp.type)); | 109 | strscpy(racomp.type, "acomp", sizeof(racomp.type)); |
114 | v32 = atomic_read(&alg->compress_cnt); | 110 | v64 = atomic64_read(&alg->compress_cnt); |
115 | racomp.stat_compress_cnt = v32; | 111 | racomp.stat_compress_cnt = v64; |
116 | v64 = atomic64_read(&alg->compress_tlen); | 112 | v64 = atomic64_read(&alg->compress_tlen); |
117 | racomp.stat_compress_tlen = v64; | 113 | racomp.stat_compress_tlen = v64; |
118 | v32 = atomic_read(&alg->decompress_cnt); | 114 | v64 = atomic64_read(&alg->decompress_cnt); |
119 | racomp.stat_decompress_cnt = v32; | 115 | racomp.stat_decompress_cnt = v64; |
120 | v64 = atomic64_read(&alg->decompress_tlen); | 116 | v64 = atomic64_read(&alg->decompress_tlen); |
121 | racomp.stat_decompress_tlen = v64; | 117 | racomp.stat_decompress_tlen = v64; |
122 | v32 = atomic_read(&alg->cipher_err_cnt); | 118 | v64 = atomic64_read(&alg->cipher_err_cnt); |
123 | racomp.stat_compress_err_cnt = v32; | 119 | racomp.stat_compress_err_cnt = v64; |
124 | 120 | ||
125 | return nla_put(skb, CRYPTOCFGA_STAT_ACOMP, sizeof(racomp), &racomp); | 121 | return nla_put(skb, CRYPTOCFGA_STAT_ACOMP, sizeof(racomp), &racomp); |
126 | } | 122 | } |
@@ -129,25 +125,24 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) | |||
129 | { | 125 | { |
130 | struct crypto_stat rakcipher; | 126 | struct crypto_stat rakcipher; |
131 | u64 v64; | 127 | u64 v64; |
132 | u32 v32; | ||
133 | 128 | ||
134 | memset(&rakcipher, 0, sizeof(rakcipher)); | 129 | memset(&rakcipher, 0, sizeof(rakcipher)); |
135 | 130 | ||
136 | strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); | 131 | strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); |
137 | v32 = atomic_read(&alg->encrypt_cnt); | 132 | v64 = atomic64_read(&alg->encrypt_cnt); |
138 | rakcipher.stat_encrypt_cnt = v32; | 133 | rakcipher.stat_encrypt_cnt = v64; |
139 | v64 = atomic64_read(&alg->encrypt_tlen); | 134 | v64 = atomic64_read(&alg->encrypt_tlen); |
140 | rakcipher.stat_encrypt_tlen = v64; | 135 | rakcipher.stat_encrypt_tlen = v64; |
141 | v32 = atomic_read(&alg->decrypt_cnt); | 136 | v64 = atomic64_read(&alg->decrypt_cnt); |
142 | rakcipher.stat_decrypt_cnt = v32; | 137 | rakcipher.stat_decrypt_cnt = v64; |
143 | v64 = atomic64_read(&alg->decrypt_tlen); | 138 | v64 = atomic64_read(&alg->decrypt_tlen); |
144 | rakcipher.stat_decrypt_tlen = v64; | 139 | rakcipher.stat_decrypt_tlen = v64; |
145 | v32 = atomic_read(&alg->sign_cnt); | 140 | v64 = atomic64_read(&alg->sign_cnt); |
146 | rakcipher.stat_sign_cnt = v32; | 141 | rakcipher.stat_sign_cnt = v64; |
147 | v32 = atomic_read(&alg->verify_cnt); | 142 | v64 = atomic64_read(&alg->verify_cnt); |
148 | rakcipher.stat_verify_cnt = v32; | 143 | rakcipher.stat_verify_cnt = v64; |
149 | v32 = atomic_read(&alg->akcipher_err_cnt); | 144 | v64 = atomic64_read(&alg->akcipher_err_cnt); |
150 | rakcipher.stat_akcipher_err_cnt = v32; | 145 | rakcipher.stat_akcipher_err_cnt = v64; |
151 | 146 | ||
152 | return nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER, | 147 | return nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER, |
153 | sizeof(rakcipher), &rakcipher); | 148 | sizeof(rakcipher), &rakcipher); |
@@ -156,19 +151,19 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) | |||
156 | static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg) | 151 | static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg) |
157 | { | 152 | { |
158 | struct crypto_stat rkpp; | 153 | struct crypto_stat rkpp; |
159 | u32 v; | 154 | u64 v; |
160 | 155 | ||
161 | memset(&rkpp, 0, sizeof(rkpp)); | 156 | memset(&rkpp, 0, sizeof(rkpp)); |
162 | 157 | ||
163 | strscpy(rkpp.type, "kpp", sizeof(rkpp.type)); | 158 | strscpy(rkpp.type, "kpp", sizeof(rkpp.type)); |
164 | 159 | ||
165 | v = atomic_read(&alg->setsecret_cnt); | 160 | v = atomic64_read(&alg->setsecret_cnt); |
166 | rkpp.stat_setsecret_cnt = v; | 161 | rkpp.stat_setsecret_cnt = v; |
167 | v = atomic_read(&alg->generate_public_key_cnt); | 162 | v = atomic64_read(&alg->generate_public_key_cnt); |
168 | rkpp.stat_generate_public_key_cnt = v; | 163 | rkpp.stat_generate_public_key_cnt = v; |
169 | v = atomic_read(&alg->compute_shared_secret_cnt); | 164 | v = atomic64_read(&alg->compute_shared_secret_cnt); |
170 | rkpp.stat_compute_shared_secret_cnt = v; | 165 | rkpp.stat_compute_shared_secret_cnt = v; |
171 | v = atomic_read(&alg->kpp_err_cnt); | 166 | v = atomic64_read(&alg->kpp_err_cnt); |
172 | rkpp.stat_kpp_err_cnt = v; | 167 | rkpp.stat_kpp_err_cnt = v; |
173 | 168 | ||
174 | return nla_put(skb, CRYPTOCFGA_STAT_KPP, sizeof(rkpp), &rkpp); | 169 | return nla_put(skb, CRYPTOCFGA_STAT_KPP, sizeof(rkpp), &rkpp); |
@@ -178,18 +173,17 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg) | |||
178 | { | 173 | { |
179 | struct crypto_stat rhash; | 174 | struct crypto_stat rhash; |
180 | u64 v64; | 175 | u64 v64; |
181 | u32 v32; | ||
182 | 176 | ||
183 | memset(&rhash, 0, sizeof(rhash)); | 177 | memset(&rhash, 0, sizeof(rhash)); |
184 | 178 | ||
185 | strscpy(rhash.type, "ahash", sizeof(rhash.type)); | 179 | strscpy(rhash.type, "ahash", sizeof(rhash.type)); |
186 | 180 | ||
187 | v32 = atomic_read(&alg->hash_cnt); | 181 | v64 = atomic64_read(&alg->hash_cnt); |
188 | rhash.stat_hash_cnt = v32; | 182 | rhash.stat_hash_cnt = v64; |
189 | v64 = atomic64_read(&alg->hash_tlen); | 183 | v64 = atomic64_read(&alg->hash_tlen); |
190 | rhash.stat_hash_tlen = v64; | 184 | rhash.stat_hash_tlen = v64; |
191 | v32 = atomic_read(&alg->hash_err_cnt); | 185 | v64 = atomic64_read(&alg->hash_err_cnt); |
192 | rhash.stat_hash_err_cnt = v32; | 186 | rhash.stat_hash_err_cnt = v64; |
193 | 187 | ||
194 | return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash); | 188 | return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash); |
195 | } | 189 | } |
@@ -198,18 +192,17 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg) | |||
198 | { | 192 | { |
199 | struct crypto_stat rhash; | 193 | struct crypto_stat rhash; |
200 | u64 v64; | 194 | u64 v64; |
201 | u32 v32; | ||
202 | 195 | ||
203 | memset(&rhash, 0, sizeof(rhash)); | 196 | memset(&rhash, 0, sizeof(rhash)); |
204 | 197 | ||
205 | strscpy(rhash.type, "shash", sizeof(rhash.type)); | 198 | strscpy(rhash.type, "shash", sizeof(rhash.type)); |
206 | 199 | ||
207 | v32 = atomic_read(&alg->hash_cnt); | 200 | v64 = atomic64_read(&alg->hash_cnt); |
208 | rhash.stat_hash_cnt = v32; | 201 | rhash.stat_hash_cnt = v64; |
209 | v64 = atomic64_read(&alg->hash_tlen); | 202 | v64 = atomic64_read(&alg->hash_tlen); |
210 | rhash.stat_hash_tlen = v64; | 203 | rhash.stat_hash_tlen = v64; |
211 | v32 = atomic_read(&alg->hash_err_cnt); | 204 | v64 = atomic64_read(&alg->hash_err_cnt); |
212 | rhash.stat_hash_err_cnt = v32; | 205 | rhash.stat_hash_err_cnt = v64; |
213 | 206 | ||
214 | return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash); | 207 | return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash); |
215 | } | 208 | } |
@@ -218,20 +211,19 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg) | |||
218 | { | 211 | { |
219 | struct crypto_stat rrng; | 212 | struct crypto_stat rrng; |
220 | u64 v64; | 213 | u64 v64; |
221 | u32 v32; | ||
222 | 214 | ||
223 | memset(&rrng, 0, sizeof(rrng)); | 215 | memset(&rrng, 0, sizeof(rrng)); |
224 | 216 | ||
225 | strscpy(rrng.type, "rng", sizeof(rrng.type)); | 217 | strscpy(rrng.type, "rng", sizeof(rrng.type)); |
226 | 218 | ||
227 | v32 = atomic_read(&alg->generate_cnt); | 219 | v64 = atomic64_read(&alg->generate_cnt); |
228 | rrng.stat_generate_cnt = v32; | 220 | rrng.stat_generate_cnt = v64; |
229 | v64 = atomic64_read(&alg->generate_tlen); | 221 | v64 = atomic64_read(&alg->generate_tlen); |
230 | rrng.stat_generate_tlen = v64; | 222 | rrng.stat_generate_tlen = v64; |
231 | v32 = atomic_read(&alg->seed_cnt); | 223 | v64 = atomic64_read(&alg->seed_cnt); |
232 | rrng.stat_seed_cnt = v32; | 224 | rrng.stat_seed_cnt = v64; |
233 | v32 = atomic_read(&alg->hash_err_cnt); | 225 | v64 = atomic64_read(&alg->hash_err_cnt); |
234 | rrng.stat_rng_err_cnt = v32; | 226 | rrng.stat_rng_err_cnt = v64; |
235 | 227 | ||
236 | return nla_put(skb, CRYPTOCFGA_STAT_RNG, sizeof(rrng), &rrng); | 228 | return nla_put(skb, CRYPTOCFGA_STAT_RNG, sizeof(rrng), &rrng); |
237 | } | 229 | } |