diff options
author | Horia Geanta <horia.geanta@freescale.com> | 2014-07-23 04:59:38 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-07-23 09:28:40 -0400 |
commit | 29b77e5dd88e1b920e3e65681f0e7b961ebbdeb8 (patch) | |
tree | da212d3ff05961e7728f9cfc78f40e0fa4abab93 /crypto | |
parent | 126ae9adc1ec8d9006542f1a5e474b0183845e21 (diff) |
crypto: testmgr - avoid DMA mapping from text, rodata, stack
With DMA_API_DEBUG set, following warnings are emitted
(tested on CAAM accelerator):
DMA-API: device driver maps memory from kernel text or rodata
DMA-API: device driver maps memory from stack
and the culprits are:
-key in __test_aead and __test_hash
-result in __test_hash
MAX_KEYLEN is changed to accommodate maximum key length from
existing test vectors in crypto/testmgr.h (131 bytes) and rounded.
Signed-off-by: Horia Geanta <horia.geanta@freescale.com>
Acked-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/testmgr.c | 57 | ||||
-rw-r--r-- | crypto/testmgr.h | 2 |
2 files changed, 50 insertions, 9 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 0f90612a00b9..81818b9a1b83 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -198,13 +198,20 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | |||
198 | const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); | 198 | const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); |
199 | unsigned int i, j, k, temp; | 199 | unsigned int i, j, k, temp; |
200 | struct scatterlist sg[8]; | 200 | struct scatterlist sg[8]; |
201 | char result[64]; | 201 | char *result; |
202 | char *key; | ||
202 | struct ahash_request *req; | 203 | struct ahash_request *req; |
203 | struct tcrypt_result tresult; | 204 | struct tcrypt_result tresult; |
204 | void *hash_buff; | 205 | void *hash_buff; |
205 | char *xbuf[XBUFSIZE]; | 206 | char *xbuf[XBUFSIZE]; |
206 | int ret = -ENOMEM; | 207 | int ret = -ENOMEM; |
207 | 208 | ||
209 | result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); | ||
210 | if (!result) | ||
211 | return ret; | ||
212 | key = kmalloc(MAX_KEYLEN, GFP_KERNEL); | ||
213 | if (!key) | ||
214 | goto out_nobuf; | ||
208 | if (testmgr_alloc_buf(xbuf)) | 215 | if (testmgr_alloc_buf(xbuf)) |
209 | goto out_nobuf; | 216 | goto out_nobuf; |
210 | 217 | ||
@@ -229,7 +236,7 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | |||
229 | goto out; | 236 | goto out; |
230 | 237 | ||
231 | j++; | 238 | j++; |
232 | memset(result, 0, 64); | 239 | memset(result, 0, MAX_DIGEST_SIZE); |
233 | 240 | ||
234 | hash_buff = xbuf[0]; | 241 | hash_buff = xbuf[0]; |
235 | hash_buff += align_offset; | 242 | hash_buff += align_offset; |
@@ -239,8 +246,14 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | |||
239 | 246 | ||
240 | if (template[i].ksize) { | 247 | if (template[i].ksize) { |
241 | crypto_ahash_clear_flags(tfm, ~0); | 248 | crypto_ahash_clear_flags(tfm, ~0); |
242 | ret = crypto_ahash_setkey(tfm, template[i].key, | 249 | if (template[i].ksize > MAX_KEYLEN) { |
243 | template[i].ksize); | 250 | pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", |
251 | j, algo, template[i].ksize, MAX_KEYLEN); | ||
252 | ret = -EINVAL; | ||
253 | goto out; | ||
254 | } | ||
255 | memcpy(key, template[i].key, template[i].ksize); | ||
256 | ret = crypto_ahash_setkey(tfm, key, template[i].ksize); | ||
244 | if (ret) { | 257 | if (ret) { |
245 | printk(KERN_ERR "alg: hash: setkey failed on " | 258 | printk(KERN_ERR "alg: hash: setkey failed on " |
246 | "test %d for %s: ret=%d\n", j, algo, | 259 | "test %d for %s: ret=%d\n", j, algo, |
@@ -300,7 +313,7 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | |||
300 | 313 | ||
301 | if (template[i].np) { | 314 | if (template[i].np) { |
302 | j++; | 315 | j++; |
303 | memset(result, 0, 64); | 316 | memset(result, 0, MAX_DIGEST_SIZE); |
304 | 317 | ||
305 | temp = 0; | 318 | temp = 0; |
306 | sg_init_table(sg, template[i].np); | 319 | sg_init_table(sg, template[i].np); |
@@ -319,8 +332,16 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | |||
319 | } | 332 | } |
320 | 333 | ||
321 | if (template[i].ksize) { | 334 | if (template[i].ksize) { |
335 | if (template[i].ksize > MAX_KEYLEN) { | ||
336 | pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", | ||
337 | j, algo, template[i].ksize, | ||
338 | MAX_KEYLEN); | ||
339 | ret = -EINVAL; | ||
340 | goto out; | ||
341 | } | ||
322 | crypto_ahash_clear_flags(tfm, ~0); | 342 | crypto_ahash_clear_flags(tfm, ~0); |
323 | ret = crypto_ahash_setkey(tfm, template[i].key, | 343 | memcpy(key, template[i].key, template[i].ksize); |
344 | ret = crypto_ahash_setkey(tfm, key, | ||
324 | template[i].ksize); | 345 | template[i].ksize); |
325 | 346 | ||
326 | if (ret) { | 347 | if (ret) { |
@@ -372,6 +393,8 @@ out: | |||
372 | out_noreq: | 393 | out_noreq: |
373 | testmgr_free_buf(xbuf); | 394 | testmgr_free_buf(xbuf); |
374 | out_nobuf: | 395 | out_nobuf: |
396 | kfree(key); | ||
397 | kfree(result); | ||
375 | return ret; | 398 | return ret; |
376 | } | 399 | } |
377 | 400 | ||
@@ -429,6 +452,9 @@ static int __test_aead(struct crypto_aead *tfm, int enc, | |||
429 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); | 452 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
430 | if (!iv) | 453 | if (!iv) |
431 | return ret; | 454 | return ret; |
455 | key = kmalloc(MAX_KEYLEN, GFP_KERNEL); | ||
456 | if (!key) | ||
457 | goto out_noxbuf; | ||
432 | if (testmgr_alloc_buf(xbuf)) | 458 | if (testmgr_alloc_buf(xbuf)) |
433 | goto out_noxbuf; | 459 | goto out_noxbuf; |
434 | if (testmgr_alloc_buf(axbuf)) | 460 | if (testmgr_alloc_buf(axbuf)) |
@@ -493,7 +519,14 @@ static int __test_aead(struct crypto_aead *tfm, int enc, | |||
493 | crypto_aead_set_flags( | 519 | crypto_aead_set_flags( |
494 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | 520 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
495 | 521 | ||
496 | key = template[i].key; | 522 | if (template[i].klen > MAX_KEYLEN) { |
523 | pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", | ||
524 | d, j, algo, template[i].klen, | ||
525 | MAX_KEYLEN); | ||
526 | ret = -EINVAL; | ||
527 | goto out; | ||
528 | } | ||
529 | memcpy(key, template[i].key, template[i].klen); | ||
497 | 530 | ||
498 | ret = crypto_aead_setkey(tfm, key, | 531 | ret = crypto_aead_setkey(tfm, key, |
499 | template[i].klen); | 532 | template[i].klen); |
@@ -594,7 +627,14 @@ static int __test_aead(struct crypto_aead *tfm, int enc, | |||
594 | if (template[i].wk) | 627 | if (template[i].wk) |
595 | crypto_aead_set_flags( | 628 | crypto_aead_set_flags( |
596 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | 629 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
597 | key = template[i].key; | 630 | if (template[i].klen > MAX_KEYLEN) { |
631 | pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", | ||
632 | d, j, algo, template[i].klen, | ||
633 | MAX_KEYLEN); | ||
634 | ret = -EINVAL; | ||
635 | goto out; | ||
636 | } | ||
637 | memcpy(key, template[i].key, template[i].klen); | ||
598 | 638 | ||
599 | ret = crypto_aead_setkey(tfm, key, template[i].klen); | 639 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
600 | if (!ret == template[i].fail) { | 640 | if (!ret == template[i].fail) { |
@@ -776,6 +816,7 @@ out_nooutbuf: | |||
776 | out_noaxbuf: | 816 | out_noaxbuf: |
777 | testmgr_free_buf(xbuf); | 817 | testmgr_free_buf(xbuf); |
778 | out_noxbuf: | 818 | out_noxbuf: |
819 | kfree(key); | ||
779 | kfree(iv); | 820 | kfree(iv); |
780 | return ret; | 821 | return ret; |
781 | } | 822 | } |
diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 4bb607189b8d..46df9e88bbf3 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h | |||
@@ -32,7 +32,7 @@ | |||
32 | #define MAX_DIGEST_SIZE 64 | 32 | #define MAX_DIGEST_SIZE 64 |
33 | #define MAX_TAP 8 | 33 | #define MAX_TAP 8 |
34 | 34 | ||
35 | #define MAX_KEYLEN 56 | 35 | #define MAX_KEYLEN 160 |
36 | #define MAX_IVLEN 32 | 36 | #define MAX_IVLEN 32 |
37 | 37 | ||
38 | struct hash_testvec { | 38 | struct hash_testvec { |