From d368a1e8eb230126eb2cbe19f56ff60b9f95169d Mon Sep 17 00:00:00 2001 From: Andrey Ryabinin Date: Thu, 10 Sep 2015 13:11:55 +0300 Subject: [PATCH] crypto: testmgr - don't copy from source IV too much Orabug: 25243093 While the destination buffer 'iv' is MAX_IVLEN size, the source 'template[i].iv' could be smaller, thus memcpy may read read invalid memory. Use crypto_skcipher_ivsize() to get real ivsize and pass it to memcpy. Signed-off-by: Andrey Ryabinin Signed-off-by: Herbert Xu (cherry picked from commit 84cba178a3b88efe2668a9039f70abda072faa21) Signed-off-by: Ethan Zhao --- crypto/testmgr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 09c06e7e0850..b852d9bd24d4 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -923,6 +923,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, char *xbuf[XBUFSIZE]; char *xoutbuf[XBUFSIZE]; int ret = -ENOMEM; + unsigned int ivsize = crypto_ablkcipher_ivsize(tfm); if (testmgr_alloc_buf(xbuf)) goto out_nobuf; @@ -958,7 +959,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, continue; if (template[i].iv) - memcpy(iv, template[i].iv, MAX_IVLEN); + memcpy(iv, template[i].iv, ivsize); else memset(iv, 0, MAX_IVLEN); @@ -1033,7 +1034,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, continue; if (template[i].iv) - memcpy(iv, template[i].iv, MAX_IVLEN); + memcpy(iv, template[i].iv, ivsize); else memset(iv, 0, MAX_IVLEN); -- 2.50.1