Cleanup ressource leaks in test_aead_speed()
PATCH 2/3 crypto: Fix potential leak in test_aead_speed() if crypto_alloc_aead() fails
In reply to Christian EngelmayerFix a potential memory leak in the error handling of test_aead_speed(). In case crypto_alloc_aead() fails, the function returns without going through the centralized cleanup path. Reported by Coverity - CID 1163870.
--- crypto/tcrypt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
crypto/tcrypt.c +2 -1
@@ -313,7 +313,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,if (IS_ERR (tfm)) {pr_err ("alg: aead: Failed to load transform for %s: %ld\n" , algo,PTR_ERR (tfm)); -return ; + goto out_notfm; } req =aead_request_alloc (tfm,GFP_KERNEL );
@@ -391,6 +391,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, out:crypto_free_aead (tfm); +out_notfm:kfree (sg); out_nosg:testmgr_free_buf (xoutbuf);
Signature · 1 line
1.9.1
PATCH 3/3 crypto: Fix leak of struct aead_request in test_aead_speed()
In reply to Christian EngelmayerFix leakage of memory for struct aead_request that is allocated via aead_request_alloc() but not released via aead_request_free(). Reported by Coverity - CID 1163869.
--- crypto/tcrypt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/tcrypt.c +3 -1
@@ -320,7 +320,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,if (!req) {pr_err ("alg: aead: Failed to allocate request for %s\n" , algo); - goto out; + goto out_noreq; } i =0 ;
@@ -390,6 +390,8 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, }while (*keysize); out: +aead_request_free (req); +out_noreq:crypto_free_aead (tfm); out_notfm:kfree (sg);
Signature · 1 line
1.9.1
cover Cleanup ressource leaks in test_aead_speed()
This is a cleanup of Coverity ressource leak findings for the quick & dirty crypto testing module crypto/tcrypt.c.
All 3 changesets address function test_aead_speed() that was introduced in 53f52d7a (crypto: tcrypt - Added speed tests for AEAD crypto alogrithms in tcrypt test suite)
The series applies against v3.15-rc2 as well as branch master in tree git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git and is compile tested only.
Christian Engelmayer (3):
crypto: Fix potential leak in test_aead_speed() if aad_size is too big
crypto: Fix potential leak in test_aead_speed() if crypto_alloc_aead() fails
crypto: Fix leak of struct aead_request in test_aead_speed()
crypto/tcrypt.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 crypto: Fix potential leak in test_aead_speed() if aad_size is too big
Fix a potential memory leak in the error handling of test_aead_speed(). In case the size check on the associate data length parameter fails, the function goes through the wrong exit label. Reported by Coverity - CID 1163870.
--- crypto/tcrypt.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
crypto/tcrypt.c +6 -8
@@ -282,6 +282,11 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,unsigned int *b_size;unsigned int iv_len; +if (aad_size >=PAGE_SIZE ) { +pr_err ("associate data length (%u) too big\n" , aad_size); +return ; + } +if (enc ==ENCRYPT ) e ="encryption" ;else
@@ -323,14 +328,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, b_size = aead_sizes; do { assoc = axbuf[0]; - - if (aad_size < PAGE_SIZE) - memset(assoc, 0xff, aad_size); - else { - pr_err("associate data length (%u) too big\n", - aad_size); - goto out_nosg; - } + memset(assoc, 0xff, aad_size); sg_init_one(&asg[0], assoc, aad_size); if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
Signature · 1 line
1.9.1
Re: [PATCH 1/3] crypto: Fix potential leak in test_aead_speed() if aad_size is too big
Quoted 15 lines · Christian Engelmayer
Fix a potential memory leak in the error handling of
test_aead_speed(). In case the size check on the associate data length parameter fails, the function goes through the wrong exit label. Reported by Coverity - CID 1163870.Signed-off-by Christian Engelmayer <[email protected]>--- crypto/tcrypt.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)crypto/tcrypt.c +0
-0
crypto/tcrypt.c static void test_aead_speed(const char *algo, int enc, · line 285
Quoted 4 lines
crypto/tcrypt.c +1
-0@@ -282,6 +282,11 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, unsigned int *b_size;unsigned int iv_len; +if (aad_size >=PAGE_SIZE ) {
On an unrelated note ... Won't if (aad_size > PAGE_SIZE) be sufficient here?
Cheers!
Re: [PATCH 2/3] crypto: Fix potential leak in test_aead_speed() if crypto_alloc_aead() fails
In reply to Christian EngelmayerQuoted 5 lines · Christian Engelmayer
Fix a potential memory leak in the error handling of
test_aead_speed(). In casecrypto_alloc_aead()fails, the function returns without going through the centralized cleanup path. Reported by Coverity - CID 1163870.Signed-off-by Christian Engelmayer <[email protected]>
Looks OK to me, thanks.
Best regards,
Marek Vasut
Re: [PATCH 3/3] crypto: Fix leak of struct aead_request in test_aead_speed()
In reply to Christian EngelmayerQuoted 5 lines · Christian Engelmayer
Fix leakage of memory for struct
aead_requestthat is allocated viaaead_request_alloc()but not released viaaead_request_free(). Reported by Coverity - CID 1163869.Signed-off-by Christian Engelmayer <[email protected]>
Best regards,
Marek Vasut
Re: [PATCH 1/3] crypto: Fix potential leak in test_aead_speed() if aad_size is too big
In reply to Christian EngelmayerQuoted 5 lines · Christian Engelmayer
Fix a potential memory leak in the error handling of
test_aead_speed(). In case the size check on the associate data length parameter fails, the function goes through the wrong exit label. Reported by Coverity - CID 1163870.Signed-off-by Christian Engelmayer <[email protected]>
Acked.
Tim
Quoted 36 lines
--- crypto/tcrypt.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)crypto/tcrypt.c +6
-8@@ -282,6 +282,11 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,unsigned int *b_size;unsigned int iv_len; +if (aad_size >=PAGE_SIZE ) { +pr_err ("associate data length (%u) too big\n" , aad_size); +return ; + } +if (enc ==ENCRYPT ) e ="encryption" ;else @@ -323,14 +328,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, b_size = aead_sizes; do { assoc = axbuf[0]; - - if (aad_size < PAGE_SIZE) - memset(assoc, 0xff, aad_size); - else { - pr_err("associate data length (%u) too big\n", - aad_size); - goto out_nosg; - } + memset(assoc, 0xff, aad_size); sg_init_one(&asg[0], assoc, aad_size); if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
Re: [PATCH 2/3] crypto: Fix potential leak in test_aead_speed() if crypto_alloc_aead() fails
In reply to Christian EngelmayerQuoted 5 lines · Christian Engelmayer
Fix a potential memory leak in the error handling of
test_aead_speed(). In casecrypto_alloc_aead()fails, the function returns without going through the centralized cleanup path. Reported by Coverity - CID 1163870.Signed-off-by Christian Engelmayer <[email protected]>
Acked.
Tim
Quoted 25 lines
--- crypto/tcrypt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)crypto/tcrypt.c +2
-1@@ -313,7 +313,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,if (IS_ERR (tfm)) {pr_err ("alg: aead: Failed to load transform for %s: %ld\n" , algo,PTR_ERR (tfm)); -return ; + goto out_notfm; } req =aead_request_alloc (tfm,GFP_KERNEL );@@ -391,6 +391,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, out:crypto_free_aead (tfm); +out_notfm:kfree (sg); out_nosg:testmgr_free_buf (xoutbuf);
Re: [PATCH 3/3] crypto: Fix leak of struct aead_request in test_aead_speed()
In reply to Christian EngelmayerQuoted 5 lines · Christian Engelmayer
Fix leakage of memory for struct
aead_requestthat is allocated viaaead_request_alloc()but not released viaaead_request_free(). Reported by Coverity - CID 1163869.Signed-off-by Christian Engelmayer <[email protected]>
Acked. Thanks for fixing the leak.
Tim
Quoted 26 lines
--- crypto/tcrypt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)crypto/tcrypt.c +3
-1@@ -320,7 +320,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec,if (!req) {pr_err ("alg: aead: Failed to allocate request for %s\n" , algo); - goto out; + goto out_noreq; } i =0 ;@@ -390,6 +390,8 @@ static void test_aead_speed(const char *algo, int enc, unsigned int sec, }while (*keysize); out: +aead_request_free (req); +out_noreq:crypto_free_aead (tfm); out_notfm:kfree (sg);
Re: [PATCH 1/3] crypto: Fix potential leak in test_aead_speed() if aad_size is too big
In reply to Marek VasutQuoted 4 lines · Marek Vasut
crypto/tcrypt.c static void test_aead_speed(const char *algo, int enc, unsigned int sec, · line 285
Quoted 1 line · Christian Engelmayer
crypto/tcrypt.c +1
-0+if (aad_size >=PAGE_SIZE ) {On an unrelated note ... Won't if (
aad_size>PAGE_SIZE) be sufficient here?
From what I have seen how the buffers are allocated via __get_free_page() I thought so too. However, as it previously read
if (aad_size < PAGE_SIZE)
memset(assoc, 0xff, aad_size);
else {my intention was simply to make the modification so that the bug is addressed without introducing an additional change.
Regards,
Christian
Re: [PATCH 1/3] crypto: Fix potential leak in test_aead_speed() if aad_size is too big
Quoted 10 lines · Christian Engelmayer
Quoted 5 lines · Marek Vasut
crypto/tcrypt.c static void test_aead_speed(const char *algo, int enc, unsigned int sec, · line 285
Quoted 1 line · Christian Engelmayer
crypto/tcrypt.c +1
-0+if (aad_size >=PAGE_SIZE ) {On an unrelated note ... Won't if (
aad_size>PAGE_SIZE) be sufficient here?From what I have seen how the buffers are allocated via
__get_free_page()I thought so too. However, as it previously read
Quoted 6 lines
if (aad_size < PAGE_SIZE) memset(assoc, 0xff, aad_size); else {my intention was simply to make the modification so that the bug is addressed without introducing an additional change.
I fully agree with you. I was just curious about the comparison here.
Best regards,
Marek Vasut
Herbert Xu
maintainerQuoted 6 lines · Christian Engelmayer
This is a cleanup of Coverity ressource leak findings for the quick & dirty crypto testing module
crypto/tcrypt.c.All 3 changesets address function
test_aead_speed()that was introduced in53f52d7a(crypto: tcrypt - Added speed tests for AEAD crypto alogrithms in tcrypt test suite)
All applied. Thanks!
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt