浏览代码

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>
Jerome Marchand 9 年之前
父节点
当前提交
abfa7f4357
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      crypto/testmgr.c

+ 3 - 2
crypto/testmgr.c

@@ -613,6 +613,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
 	aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
 	aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
 				  tcrypt_complete, &result);
 				  tcrypt_complete, &result);
 
 
+	iv_len = crypto_aead_ivsize(tfm);
+
 	for (i = 0, j = 0; i < tcount; i++) {
 	for (i = 0, j = 0; i < tcount; i++) {
 		if (template[i].np)
 		if (template[i].np)
 			continue;
 			continue;
@@ -633,7 +635,6 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
 
 
 		memcpy(input, template[i].input, template[i].ilen);
 		memcpy(input, template[i].input, template[i].ilen);
 		memcpy(assoc, template[i].assoc, template[i].alen);
 		memcpy(assoc, template[i].assoc, template[i].alen);
-		iv_len = crypto_aead_ivsize(tfm);
 		if (template[i].iv)
 		if (template[i].iv)
 			memcpy(iv, template[i].iv, iv_len);
 			memcpy(iv, template[i].iv, iv_len);
 		else
 		else
@@ -742,7 +743,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
 		j++;
 		j++;
 
 
 		if (template[i].iv)
 		if (template[i].iv)
-			memcpy(iv, template[i].iv, MAX_IVLEN);
+			memcpy(iv, template[i].iv, iv_len);
 		else
 		else
 			memset(iv, 0, MAX_IVLEN);
 			memset(iv, 0, MAX_IVLEN);