aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorJerome Marchand <jmarchan@redhat.com>2016-02-03 07:58:12 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2016-02-06 02:33:29 -0500
commitabfa7f4357e3640fdee87dfc276fd0f379fb5ae6 (patch)
tree078981ec818395044e492b3a1b13d5ccdbd8a869 /crypto
parentd42cf2f1901e4fafb133d5fb680fc7138b9ba393 (diff)
crypto: testmgr - fix out of bound read in __test_aead()
__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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/testmgr.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index cde6a2983937..54681838da6c 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -613,6 +613,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
613 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 613 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
614 tcrypt_complete, &result); 614 tcrypt_complete, &result);
615 615
616 iv_len = crypto_aead_ivsize(tfm);
617
616 for (i = 0, j = 0; i < tcount; i++) { 618 for (i = 0, j = 0; i < tcount; i++) {
617 if (template[i].np) 619 if (template[i].np)
618 continue; 620 continue;
@@ -633,7 +635,6 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
633 635
634 memcpy(input, template[i].input, template[i].ilen); 636 memcpy(input, template[i].input, template[i].ilen);
635 memcpy(assoc, template[i].assoc, template[i].alen); 637 memcpy(assoc, template[i].assoc, template[i].alen);
636 iv_len = crypto_aead_ivsize(tfm);
637 if (template[i].iv) 638 if (template[i].iv)
638 memcpy(iv, template[i].iv, iv_len); 639 memcpy(iv, template[i].iv, iv_len);
639 else 640 else
@@ -742,7 +743,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
742 j++; 743 j++;
743 744
744 if (template[i].iv) 745 if (template[i].iv)
745 memcpy(iv, template[i].iv, MAX_IVLEN); 746 memcpy(iv, template[i].iv, iv_len);
746 else 747 else
747 memset(iv, 0, MAX_IVLEN); 748 memset(iv, 0, MAX_IVLEN);
748 749