diff options
author | Jerome Marchand <jmarchan@redhat.com> | 2016-02-03 13:58:12 +0100 |
---|---|---|
committer | Sasha Levin <alexander.levin@verizon.com> | 2017-06-13 09:29:18 -0400 |
commit | f364181f7aa2e6dc6ae837da02c7c7811023c2cd (patch) | |
tree | ec7ba19181c0823eaf84a42f2dd3faf566e6b4a2 | |
parent | 9800a9a4b17ae1ede8cd0d3fbd55183fe5653406 (diff) |
crypto: testmgr - fix out of bound read in __test_aead()
[ Upstream commit abfa7f4357e3640fdee87dfc276fd0f379fb5ae6 ]
__test_aead() reads MAX_IVLEN bytes from template[i].iv, but the
actual length of the initialisation vector can be shorter.
The length of the IV is already calculated earlier in the
function. Let's just reuses that. Also the IV length is currently
calculated several time for no reason. Let's fix that too.
This fix an out-of-bound error detected by KASan.
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
-rw-r--r-- | crypto/testmgr.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index f9bce3d7ee7f..e6315d54e670 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -480,6 +480,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc, aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, tcrypt_complete, &result); + iv_len = crypto_aead_ivsize(tfm); + for (i = 0, j = 0; i < tcount; i++) { if (template[i].np) continue; @@ -500,7 +502,6 @@ static int __test_aead(struct crypto_aead *tfm, int enc, memcpy(input, template[i].input, template[i].ilen); memcpy(assoc, template[i].assoc, template[i].alen); - iv_len = crypto_aead_ivsize(tfm); if (template[i].iv) memcpy(iv, template[i].iv, iv_len); else @@ -605,7 +606,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, j++; if (template[i].iv) - memcpy(iv, template[i].iv, MAX_IVLEN); + memcpy(iv, template[i].iv, iv_len); else memset(iv, 0, MAX_IVLEN); |