]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
crypto: testmgr - don't copy from source IV too much
authorAndrey Ryabinin <aryabinin@virtuozzo.com>
Thu, 10 Sep 2015 10:11:55 +0000 (13:11 +0300)
committerChuck Anderson <chuck.anderson@oracle.com>
Sun, 26 Feb 2017 05:34:29 +0000 (21:34 -0800)
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 <aryabinin@virtuozzo.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit 84cba178a3b88efe2668a9039f70abda072faa21)
Signed-off-by: Ethan Zhao <ethan.zhao@oracle.com>
crypto/testmgr.c

index 09c06e7e085000ef1248580748fb5d926a362389..b852d9bd24d4ae1eb5e4af4932bca847ff56f1b0 100644 (file)
@@ -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);