Commit 29b77e5d authored by Horia Geanta's avatar Horia Geanta Committed by Herbert Xu

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: default avatarHoria Geanta <horia.geanta@freescale.com>
Acked-by: default avatarKim Phillips <kim.phillips@freescale.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 126ae9ad
...@@ -198,13 +198,20 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -198,13 +198,20 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
unsigned int i, j, k, temp; unsigned int i, j, k, temp;
struct scatterlist sg[8]; struct scatterlist sg[8];
char result[64]; char *result;
char *key;
struct ahash_request *req; struct ahash_request *req;
struct tcrypt_result tresult; struct tcrypt_result tresult;
void *hash_buff; void *hash_buff;
char *xbuf[XBUFSIZE]; char *xbuf[XBUFSIZE];
int ret = -ENOMEM; int ret = -ENOMEM;
result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
if (!result)
return ret;
key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
if (!key)
goto out_nobuf;
if (testmgr_alloc_buf(xbuf)) if (testmgr_alloc_buf(xbuf))
goto out_nobuf; goto out_nobuf;
...@@ -229,7 +236,7 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -229,7 +236,7 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
goto out; goto out;
j++; j++;
memset(result, 0, 64); memset(result, 0, MAX_DIGEST_SIZE);
hash_buff = xbuf[0]; hash_buff = xbuf[0];
hash_buff += align_offset; hash_buff += align_offset;
...@@ -239,8 +246,14 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -239,8 +246,14 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
if (template[i].ksize) { if (template[i].ksize) {
crypto_ahash_clear_flags(tfm, ~0); crypto_ahash_clear_flags(tfm, ~0);
ret = crypto_ahash_setkey(tfm, template[i].key, if (template[i].ksize > MAX_KEYLEN) {
template[i].ksize); pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
j, algo, template[i].ksize, MAX_KEYLEN);
ret = -EINVAL;
goto out;
}
memcpy(key, template[i].key, template[i].ksize);
ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
if (ret) { if (ret) {
printk(KERN_ERR "alg: hash: setkey failed on " printk(KERN_ERR "alg: hash: setkey failed on "
"test %d for %s: ret=%d\n", j, algo, "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,7 +313,7 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
if (template[i].np) { if (template[i].np) {
j++; j++;
memset(result, 0, 64); memset(result, 0, MAX_DIGEST_SIZE);
temp = 0; temp = 0;
sg_init_table(sg, template[i].np); sg_init_table(sg, template[i].np);
...@@ -319,8 +332,16 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -319,8 +332,16 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
} }
if (template[i].ksize) { if (template[i].ksize) {
if (template[i].ksize > MAX_KEYLEN) {
pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
j, algo, template[i].ksize,
MAX_KEYLEN);
ret = -EINVAL;
goto out;
}
crypto_ahash_clear_flags(tfm, ~0); crypto_ahash_clear_flags(tfm, ~0);
ret = crypto_ahash_setkey(tfm, template[i].key, memcpy(key, template[i].key, template[i].ksize);
ret = crypto_ahash_setkey(tfm, key,
template[i].ksize); template[i].ksize);
if (ret) { if (ret) {
...@@ -372,6 +393,8 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -372,6 +393,8 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
out_noreq: out_noreq:
testmgr_free_buf(xbuf); testmgr_free_buf(xbuf);
out_nobuf: out_nobuf:
kfree(key);
kfree(result);
return ret; return ret;
} }
...@@ -429,6 +452,9 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -429,6 +452,9 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
iv = kzalloc(MAX_IVLEN, GFP_KERNEL); iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
if (!iv) if (!iv)
return ret; return ret;
key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
if (!key)
goto out_noxbuf;
if (testmgr_alloc_buf(xbuf)) if (testmgr_alloc_buf(xbuf))
goto out_noxbuf; goto out_noxbuf;
if (testmgr_alloc_buf(axbuf)) if (testmgr_alloc_buf(axbuf))
...@@ -493,7 +519,14 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -493,7 +519,14 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
crypto_aead_set_flags( crypto_aead_set_flags(
tfm, CRYPTO_TFM_REQ_WEAK_KEY); tfm, CRYPTO_TFM_REQ_WEAK_KEY);
key = template[i].key; if (template[i].klen > MAX_KEYLEN) {
pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
d, j, algo, template[i].klen,
MAX_KEYLEN);
ret = -EINVAL;
goto out;
}
memcpy(key, template[i].key, template[i].klen);
ret = crypto_aead_setkey(tfm, key, ret = crypto_aead_setkey(tfm, key,
template[i].klen); template[i].klen);
...@@ -594,7 +627,14 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -594,7 +627,14 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
if (template[i].wk) if (template[i].wk)
crypto_aead_set_flags( crypto_aead_set_flags(
tfm, CRYPTO_TFM_REQ_WEAK_KEY); tfm, CRYPTO_TFM_REQ_WEAK_KEY);
key = template[i].key; if (template[i].klen > MAX_KEYLEN) {
pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
d, j, algo, template[i].klen,
MAX_KEYLEN);
ret = -EINVAL;
goto out;
}
memcpy(key, template[i].key, template[i].klen);
ret = crypto_aead_setkey(tfm, key, template[i].klen); ret = crypto_aead_setkey(tfm, key, template[i].klen);
if (!ret == template[i].fail) { if (!ret == template[i].fail) {
...@@ -776,6 +816,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -776,6 +816,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
out_noaxbuf: out_noaxbuf:
testmgr_free_buf(xbuf); testmgr_free_buf(xbuf);
out_noxbuf: out_noxbuf:
kfree(key);
kfree(iv); kfree(iv);
return ret; return ret;
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#define MAX_DIGEST_SIZE 64 #define MAX_DIGEST_SIZE 64
#define MAX_TAP 8 #define MAX_TAP 8
#define MAX_KEYLEN 56 #define MAX_KEYLEN 160
#define MAX_IVLEN 32 #define MAX_IVLEN 32
struct hash_testvec { struct hash_testvec {
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment