Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1321745 > unrolled thread

[PATCH] fix out of bound read in __test_aead()

Started by"Jerome Marchand" <jmarchan@redhat.com>
First post2016-01-29 14:20 +0100
Last post2016-02-06 08:50 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] fix out of bound read in __test_aead() "Jerome Marchand" <jmarchan@redhat.com> - 2016-01-29 14:20 +0100
    Re: [PATCH] fix out of bound read in __test_aead() Herbert Xu <herbert@gondor.apana.org.au> - 2016-02-01 15:30 +0100
      Re: [PATCH] fix out of bound read in __test_aead() Jerome Marchand <jmarchan@redhat.com> - 2016-02-01 16:50 +0100
    [PATCH v2] fix out of bound read in __test_aead() "Jerome Marchand" <jmarchan@redhat.com> - 2016-02-03 14:00 +0100
      Re: [PATCH v2] fix out of bound read in __test_aead() Herbert Xu <herbert@gondor.apana.org.au> - 2016-02-06 08:50 +0100

#1321745 — [PATCH] fix out of bound read in __test_aead()

From"Jerome Marchand" <jmarchan@redhat.com>
Date2016-01-29 14:20 +0100
Subject[PATCH] fix out of bound read in __test_aead()
Message-ID<qWh7Y-3Bi-7@gated-at.bofh.it>
__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.
This fix an out-of-bound error detected by KASan.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 crypto/testmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index ae8c57fd..d3587d5 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -617,7 +617,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);
 
-- 
2.5.0

[toc] | [next] | [standalone]


#1323167

FromHerbert Xu <herbert@gondor.apana.org.au>
Date2016-02-01 15:30 +0100
Message-ID<qXnEn-45e-47@gated-at.bofh.it>
In reply to#1321745
On Fri, Jan 29, 2016 at 02:10:09PM +0100, Jerome Marchand wrote:
> __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.
> This fix an out-of-bound error detected by KASan.
> 
> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>

This patch creates a new warning that iv_len may be uninitialised.

Please fix this and resubmit.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[toc] | [prev] | [next] | [standalone]


#1323250

FromJerome Marchand <jmarchan@redhat.com>
Date2016-02-01 16:50 +0100
Message-ID<qXoTN-4WL-31@gated-at.bofh.it>
In reply to#1323167

[Multipart message — attachments visible in raw view] — view raw

On 02/01/2016 03:26 PM, Herbert Xu wrote:
> On Fri, Jan 29, 2016 at 02:10:09PM +0100, Jerome Marchand wrote:
>> __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.
>> This fix an out-of-bound error detected by KASan.
>>
>> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
> 
> This patch creates a new warning that iv_len may be uninitialised.

I see. iv_len is set for each templates. I don't see why we would like
to call crypto_aead_ivsize() more than once. Moving the initialization
of iv_len out of the loop should solve the warning.

> 
> Please fix this and resubmit.

Will do.

Jerome

> 
> Thanks,
> 


[toc] | [prev] | [next] | [standalone]


#1325380 — [PATCH v2] fix out of bound read in __test_aead()

From"Jerome Marchand" <jmarchan@redhat.com>
Date2016-02-03 14:00 +0100
Subject[PATCH v2] fix out of bound read in __test_aead()
Message-ID<qY5cn-24p-13@gated-at.bofh.it>
In reply to#1321745
__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>
---
 crypto/testmgr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index ae8c57fd..6691756 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -488,6 +488,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;
@@ -508,7 +510,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
@@ -617,7 +618,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);
 
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1328252 — Re: [PATCH v2] fix out of bound read in __test_aead()

FromHerbert Xu <herbert@gondor.apana.org.au>
Date2016-02-06 08:50 +0100
SubjectRe: [PATCH v2] fix out of bound read in __test_aead()
Message-ID<qZ5N0-46X-19@gated-at.bofh.it>
In reply to#1325380
On Wed, Feb 03, 2016 at 01:58:12PM +0100, Jerome Marchand wrote:
> __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>

Applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web