crypto: testmgr - test misuse of result in ahash
Async hash operations can use result pointer in final/finup/digest, but not in init/update/export/import, so test it for misuse. Signed-off-by: Kamil Konieczny <k.konieczny@partner.samsung.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
059bfd1171
commit
466d7b9f61
|
@ -177,6 +177,18 @@ static void testmgr_free_buf(char *buf[XBUFSIZE])
|
||||||
free_page((unsigned long)buf[i]);
|
free_page((unsigned long)buf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ahash_guard_result(char *result, char c, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
if (result[i] != c)
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int ahash_partial_update(struct ahash_request **preq,
|
static int ahash_partial_update(struct ahash_request **preq,
|
||||||
struct crypto_ahash *tfm, const struct hash_testvec *template,
|
struct crypto_ahash *tfm, const struct hash_testvec *template,
|
||||||
void *hash_buff, int k, int temp, struct scatterlist *sg,
|
void *hash_buff, int k, int temp, struct scatterlist *sg,
|
||||||
|
@ -186,6 +198,7 @@ static int ahash_partial_update(struct ahash_request **preq,
|
||||||
struct ahash_request *req;
|
struct ahash_request *req;
|
||||||
int statesize, ret = -EINVAL;
|
int statesize, ret = -EINVAL;
|
||||||
static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
|
static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
|
||||||
|
int digestsize = crypto_ahash_digestsize(tfm);
|
||||||
|
|
||||||
req = *preq;
|
req = *preq;
|
||||||
statesize = crypto_ahash_statesize(
|
statesize = crypto_ahash_statesize(
|
||||||
|
@ -196,12 +209,19 @@ static int ahash_partial_update(struct ahash_request **preq,
|
||||||
goto out_nostate;
|
goto out_nostate;
|
||||||
}
|
}
|
||||||
memcpy(state + statesize, guard, sizeof(guard));
|
memcpy(state + statesize, guard, sizeof(guard));
|
||||||
|
memset(result, 1, digestsize);
|
||||||
ret = crypto_ahash_export(req, state);
|
ret = crypto_ahash_export(req, state);
|
||||||
WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
|
WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("alg: hash: Failed to export() for %s\n", algo);
|
pr_err("alg: hash: Failed to export() for %s\n", algo);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
ret = ahash_guard_result(result, 1, digestsize);
|
||||||
|
if (ret) {
|
||||||
|
pr_err("alg: hash: Failed, export used req->result for %s\n",
|
||||||
|
algo);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
ahash_request_free(req);
|
ahash_request_free(req);
|
||||||
req = ahash_request_alloc(tfm, GFP_KERNEL);
|
req = ahash_request_alloc(tfm, GFP_KERNEL);
|
||||||
if (!req) {
|
if (!req) {
|
||||||
|
@ -221,6 +241,12 @@ static int ahash_partial_update(struct ahash_request **preq,
|
||||||
pr_err("alg: hash: Failed to import() for %s\n", algo);
|
pr_err("alg: hash: Failed to import() for %s\n", algo);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
ret = ahash_guard_result(result, 1, digestsize);
|
||||||
|
if (ret) {
|
||||||
|
pr_err("alg: hash: Failed, import used req->result for %s\n",
|
||||||
|
algo);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
ret = crypto_wait_req(crypto_ahash_update(req), wait);
|
ret = crypto_wait_req(crypto_ahash_update(req), wait);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -316,18 +342,31 @@ static int __test_hash(struct crypto_ahash *tfm,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
memset(result, 1, digest_size);
|
||||||
ret = crypto_wait_req(crypto_ahash_init(req), &wait);
|
ret = crypto_wait_req(crypto_ahash_init(req), &wait);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("alg: hash: init failed on test %d "
|
pr_err("alg: hash: init failed on test %d "
|
||||||
"for %s: ret=%d\n", j, algo, -ret);
|
"for %s: ret=%d\n", j, algo, -ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
ret = ahash_guard_result(result, 1, digest_size);
|
||||||
|
if (ret) {
|
||||||
|
pr_err("alg: hash: init failed on test %d "
|
||||||
|
"for %s: used req->result\n", j, algo);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
ret = crypto_wait_req(crypto_ahash_update(req), &wait);
|
ret = crypto_wait_req(crypto_ahash_update(req), &wait);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("alg: hash: update failed on test %d "
|
pr_err("alg: hash: update failed on test %d "
|
||||||
"for %s: ret=%d\n", j, algo, -ret);
|
"for %s: ret=%d\n", j, algo, -ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
ret = ahash_guard_result(result, 1, digest_size);
|
||||||
|
if (ret) {
|
||||||
|
pr_err("alg: hash: update failed on test %d "
|
||||||
|
"for %s: used req->result\n", j, algo);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
ret = crypto_wait_req(crypto_ahash_final(req), &wait);
|
ret = crypto_wait_req(crypto_ahash_final(req), &wait);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("alg: hash: final failed on test %d "
|
pr_err("alg: hash: final failed on test %d "
|
||||||
|
|
Loading…
Reference in New Issue