diff options
author | Eric Biggers <ebiggers@google.com> | 2019-02-01 02:51:49 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-02-08 02:30:09 -0500 |
commit | fa353c99174e83ab59ab69ddbf923223b9e7ebbd (patch) | |
tree | b8400f1764dc2f0577bbb0dcbe94c9347ec21e8f /crypto/testmgr.c | |
parent | 4cc2dcf95f1c2849e489df91c07aee5f368a39f9 (diff) |
crypto: testmgr - check for skcipher_request corruption
Check that algorithms do not change the skcipher_request structure, as
users may rely on submitting the request again (e.g. after copying new
data into the same source buffer) without reinitializing everything.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r-- | crypto/testmgr.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index e5d8a0b8aea5..31df04baa85f 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -1535,6 +1535,47 @@ static int test_skcipher_vec_cfg(const char *driver, int enc, | |||
1535 | return err; | 1535 | return err; |
1536 | } | 1536 | } |
1537 | 1537 | ||
1538 | /* Check that the algorithm didn't overwrite things it shouldn't have */ | ||
1539 | if (req->cryptlen != vec->len || | ||
1540 | req->iv != iv || | ||
1541 | req->src != tsgls->src.sgl_ptr || | ||
1542 | req->dst != tsgls->dst.sgl_ptr || | ||
1543 | crypto_skcipher_reqtfm(req) != tfm || | ||
1544 | req->base.complete != crypto_req_done || | ||
1545 | req->base.flags != req_flags || | ||
1546 | req->base.data != &wait) { | ||
1547 | pr_err("alg: skcipher: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n", | ||
1548 | driver, op, vec_num, cfg->name); | ||
1549 | if (req->cryptlen != vec->len) | ||
1550 | pr_err("alg: skcipher: changed 'req->cryptlen'\n"); | ||
1551 | if (req->iv != iv) | ||
1552 | pr_err("alg: skcipher: changed 'req->iv'\n"); | ||
1553 | if (req->src != tsgls->src.sgl_ptr) | ||
1554 | pr_err("alg: skcipher: changed 'req->src'\n"); | ||
1555 | if (req->dst != tsgls->dst.sgl_ptr) | ||
1556 | pr_err("alg: skcipher: changed 'req->dst'\n"); | ||
1557 | if (crypto_skcipher_reqtfm(req) != tfm) | ||
1558 | pr_err("alg: skcipher: changed 'req->base.tfm'\n"); | ||
1559 | if (req->base.complete != crypto_req_done) | ||
1560 | pr_err("alg: skcipher: changed 'req->base.complete'\n"); | ||
1561 | if (req->base.flags != req_flags) | ||
1562 | pr_err("alg: skcipher: changed 'req->base.flags'\n"); | ||
1563 | if (req->base.data != &wait) | ||
1564 | pr_err("alg: skcipher: changed 'req->base.data'\n"); | ||
1565 | return -EINVAL; | ||
1566 | } | ||
1567 | if (is_test_sglist_corrupted(&tsgls->src)) { | ||
1568 | pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n", | ||
1569 | driver, op, vec_num, cfg->name); | ||
1570 | return -EINVAL; | ||
1571 | } | ||
1572 | if (tsgls->dst.sgl_ptr != tsgls->src.sgl && | ||
1573 | is_test_sglist_corrupted(&tsgls->dst)) { | ||
1574 | pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n", | ||
1575 | driver, op, vec_num, cfg->name); | ||
1576 | return -EINVAL; | ||
1577 | } | ||
1578 | |||
1538 | /* Check for the correct output (ciphertext or plaintext) */ | 1579 | /* Check for the correct output (ciphertext or plaintext) */ |
1539 | err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, | 1580 | err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, |
1540 | vec->len, 0, true); | 1581 | vec->len, 0, true); |