DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1] examples/fips_validation: fix memory leak in sha test
@ 2022-07-02 14:51 Gowrishankar Muthukrishnan
  2022-07-02 14:58 ` [PATCH v2] " Gowrishankar Muthukrishnan
  2022-07-02 18:44 ` Gowrishankar Muthukrishnan
  0 siblings, 2 replies; 11+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-07-02 14:51 UTC (permalink / raw)
  To: dev
  Cc: Akhil Goyal, Fan Zhang, Brian Dooley, Anoob Joseph,
	Archana Muniganti, Jerin Jacob, Gowrishankar Muthukrishnan

There is wrong size used for allocation of digest buffer which in
some cases cause memory corruption. Also, fixed places where memory
leak is observed.

Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 examples/fips_validation/fips_validation_sha.c | 10 ++++++++--
 examples/fips_validation/main.c                |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c
index a2928618d7..538cb6647a 100644
--- a/examples/fips_validation/fips_validation_sha.c
+++ b/examples/fips_validation/fips_validation_sha.c
@@ -229,13 +229,19 @@ parse_test_sha_json_algorithm(void)
 	for (i = 0; i < RTE_DIM(phsc); i++) {
 		if (info.interim_info.sha_data.algo == phsc[i].algo) {
 			vec.cipher_auth.digest.len = atoi(phsc[i].str);
-			vec.cipher_auth.digest.val = calloc(0, vec.cipher_auth.digest.len * 8);
+			if (vec.cipher_auth.digest.val)
+				free(vec.cipher_auth.digest.val);
+
+			vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);
 			break;
 		}
 	}
 
-	if (i == RTE_DIM(phsc))
+	if (i == RTE_DIM(phsc)) {
+		free(vec.cipher_auth.digest.val);
+		vec.cipher_auth.digest.val = NULL;
 		return -1;
+	}
 
 	return 0;
 }
diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 6d52048b5c..8bd5a66889 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -2099,6 +2099,7 @@ fips_test_one_json_file(void)
 		json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
 		fips_test_one_vector_set();
 		json_array_append_new(json_info.json_write_root, json_info.json_write_set);
+		json_incref(json_info.json_write_set);
 	}
 
 	json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-02 14:51 [PATCH v1] examples/fips_validation: fix memory leak in sha test Gowrishankar Muthukrishnan
@ 2022-07-02 14:58 ` Gowrishankar Muthukrishnan
  2022-07-04  7:48   ` David Marchand
  2022-07-02 18:44 ` Gowrishankar Muthukrishnan
  1 sibling, 1 reply; 11+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-07-02 14:58 UTC (permalink / raw)
  To: dev
  Cc: Akhil Goyal, Fan Zhang, Brian Dooley, Anoob Joseph,
	Archana Muniganti, Jerin Jacob, Gowrishankar Muthukrishnan

There is wrong size used for allocation of digest buffer which in
some cases cause memory corruption. Also, fixed places where memory
leak is observed. This fix would enable sha 384 and 512 NIST vectors
be supported fully.

Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
v2:
 - doc update to support 384 and 512 sha.
---
 doc/guides/sample_app_ug/fips_validation.rst   |  2 +-
 examples/fips_validation/fips_validation_sha.c | 10 ++++++++--
 examples/fips_validation/main.c                |  1 +
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/doc/guides/sample_app_ug/fips_validation.rst b/doc/guides/sample_app_ug/fips_validation.rst
index 4b68226665..6f4bd34726 100644
--- a/doc/guides/sample_app_ug/fips_validation.rst
+++ b/doc/guides/sample_app_ug/fips_validation.rst
@@ -63,7 +63,7 @@ ACVP
     * AES-CMAC (128,192,256) - AFT
     * AES-XTS (128,256) - AFT
     * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
-    * SHA (1,256) - AFT, MCT
+    * SHA (1, 256, 384, 512) - AFT, MCT
 
 
 Application Information
diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c
index a2928618d7..538cb6647a 100644
--- a/examples/fips_validation/fips_validation_sha.c
+++ b/examples/fips_validation/fips_validation_sha.c
@@ -229,13 +229,19 @@ parse_test_sha_json_algorithm(void)
 	for (i = 0; i < RTE_DIM(phsc); i++) {
 		if (info.interim_info.sha_data.algo == phsc[i].algo) {
 			vec.cipher_auth.digest.len = atoi(phsc[i].str);
-			vec.cipher_auth.digest.val = calloc(0, vec.cipher_auth.digest.len * 8);
+			if (vec.cipher_auth.digest.val)
+				free(vec.cipher_auth.digest.val);
+
+			vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);
 			break;
 		}
 	}
 
-	if (i == RTE_DIM(phsc))
+	if (i == RTE_DIM(phsc)) {
+		free(vec.cipher_auth.digest.val);
+		vec.cipher_auth.digest.val = NULL;
 		return -1;
+	}
 
 	return 0;
 }
diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 6d52048b5c..8bd5a66889 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -2099,6 +2099,7 @@ fips_test_one_json_file(void)
 		json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
 		fips_test_one_vector_set();
 		json_array_append_new(json_info.json_write_root, json_info.json_write_set);
+		json_incref(json_info.json_write_set);
 	}
 
 	json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-02 14:51 [PATCH v1] examples/fips_validation: fix memory leak in sha test Gowrishankar Muthukrishnan
  2022-07-02 14:58 ` [PATCH v2] " Gowrishankar Muthukrishnan
@ 2022-07-02 18:44 ` Gowrishankar Muthukrishnan
  2022-07-04  7:00   ` Akhil Goyal
  2022-07-04  9:55   ` [PATCH v3] " Gowrishankar Muthukrishnan
  1 sibling, 2 replies; 11+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-07-02 18:44 UTC (permalink / raw)
  To: dev
  Cc: Akhil Goyal, Fan Zhang, Brian Dooley, Anoob Joseph,
	Archana Muniganti, Jerin Jacob, Gowrishankar Muthukrishnan

There is wrong size used for allocation of digest buffer which in
some cases cause memory corruption. Also, fixed places where memory
leak is observed. This fix would enable sha 384 and 512 NIST vectors
be supported fully.

Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
Depends-on: series-23828 ("example/fips_validation: add xts and sha json parsing")
---
 doc/guides/sample_app_ug/fips_validation.rst   |  2 +-
 examples/fips_validation/fips_validation_sha.c | 10 ++++++++--
 examples/fips_validation/main.c                |  1 +
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/doc/guides/sample_app_ug/fips_validation.rst b/doc/guides/sample_app_ug/fips_validation.rst
index 4b68226665..6f4bd34726 100644
--- a/doc/guides/sample_app_ug/fips_validation.rst
+++ b/doc/guides/sample_app_ug/fips_validation.rst
@@ -63,7 +63,7 @@ ACVP
     * AES-CMAC (128,192,256) - AFT
     * AES-XTS (128,256) - AFT
     * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
-    * SHA (1,256) - AFT, MCT
+    * SHA (1, 256, 384, 512) - AFT, MCT
 
 
 Application Information
diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c
index a2928618d7..538cb6647a 100644
--- a/examples/fips_validation/fips_validation_sha.c
+++ b/examples/fips_validation/fips_validation_sha.c
@@ -229,13 +229,19 @@ parse_test_sha_json_algorithm(void)
 	for (i = 0; i < RTE_DIM(phsc); i++) {
 		if (info.interim_info.sha_data.algo == phsc[i].algo) {
 			vec.cipher_auth.digest.len = atoi(phsc[i].str);
-			vec.cipher_auth.digest.val = calloc(0, vec.cipher_auth.digest.len * 8);
+			if (vec.cipher_auth.digest.val)
+				free(vec.cipher_auth.digest.val);
+
+			vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);
 			break;
 		}
 	}
 
-	if (i == RTE_DIM(phsc))
+	if (i == RTE_DIM(phsc)) {
+		free(vec.cipher_auth.digest.val);
+		vec.cipher_auth.digest.val = NULL;
 		return -1;
+	}
 
 	return 0;
 }
diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 6d52048b5c..8bd5a66889 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -2099,6 +2099,7 @@ fips_test_one_json_file(void)
 		json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
 		fips_test_one_vector_set();
 		json_array_append_new(json_info.json_write_root, json_info.json_write_set);
+		json_incref(json_info.json_write_set);
 	}
 
 	json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-02 18:44 ` Gowrishankar Muthukrishnan
@ 2022-07-04  7:00   ` Akhil Goyal
  2022-07-04  9:55   ` [PATCH v3] " Gowrishankar Muthukrishnan
  1 sibling, 0 replies; 11+ messages in thread
From: Akhil Goyal @ 2022-07-04  7:00 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, dev
  Cc: Fan Zhang, Brian Dooley, Anoob Joseph, Archana Muniganti,
	Jerin Jacob Kollanukkaran, Gowrishankar Muthukrishnan

> Subject: [PATCH v2] examples/fips_validation: fix memory leak in sha test
> 
> There is wrong size used for allocation of digest buffer which in
> some cases cause memory corruption. Also, fixed places where memory
> leak is observed. This fix would enable sha 384 and 512 NIST vectors
> be supported fully.
> 
> Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
Applied to dpdk-next-crypto

Thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-02 14:58 ` [PATCH v2] " Gowrishankar Muthukrishnan
@ 2022-07-04  7:48   ` David Marchand
  2022-07-04  7:50     ` [EXT] " Akhil Goyal
  2022-07-04  8:18     ` Gowrishankar Muthukrishnan
  0 siblings, 2 replies; 11+ messages in thread
From: David Marchand @ 2022-07-04  7:48 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, Akhil Goyal
  Cc: dev, Fan Zhang, Brian Dooley, Anoob Joseph, Archana Muniganti,
	Jerin Jacob, Thomas Monjalon

On Sat, Jul 2, 2022 at 4:59 PM Gowrishankar Muthukrishnan
<gmuthukrishn@marvell.com> wrote:
>
> There is wrong size used for allocation of digest buffer which in
> some cases cause memory corruption. Also, fixed places where memory
> leak is observed. This fix would enable sha 384 and 512 NIST vectors
> be supported fully.
>
> Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")

This sha1 is not valid anymore, or maybe Akhil will squash the fix in
the next-crypto tree before reaching main.

>
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
> v2:
>  - doc update to support 384 and 512 sha.
> ---
>  doc/guides/sample_app_ug/fips_validation.rst   |  2 +-
>  examples/fips_validation/fips_validation_sha.c | 10 ++++++++--
>  examples/fips_validation/main.c                |  1 +
>  3 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/doc/guides/sample_app_ug/fips_validation.rst b/doc/guides/sample_app_ug/fips_validation.rst
> index 4b68226665..6f4bd34726 100644
> --- a/doc/guides/sample_app_ug/fips_validation.rst
> +++ b/doc/guides/sample_app_ug/fips_validation.rst
> @@ -63,7 +63,7 @@ ACVP
>      * AES-CMAC (128,192,256) - AFT
>      * AES-XTS (128,256) - AFT
>      * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
> -    * SHA (1,256) - AFT, MCT
> +    * SHA (1, 256, 384, 512) - AFT, MCT
>
>
>  Application Information
> diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c
> index a2928618d7..538cb6647a 100644
> --- a/examples/fips_validation/fips_validation_sha.c
> +++ b/examples/fips_validation/fips_validation_sha.c
> @@ -229,13 +229,19 @@ parse_test_sha_json_algorithm(void)
>         for (i = 0; i < RTE_DIM(phsc); i++) {
>                 if (info.interim_info.sha_data.algo == phsc[i].algo) {
>                         vec.cipher_auth.digest.len = atoi(phsc[i].str);
> -                       vec.cipher_auth.digest.val = calloc(0, vec.cipher_auth.digest.len * 8);
> +                       if (vec.cipher_auth.digest.val)
> +                               free(vec.cipher_auth.digest.val);

Unneeded if().

We just did a tree-wide cleanup to avoid these.
Please don't reintroduce some.


> +
> +                       vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);

Don't we need to check for allocation success?


>                         break;
>                 }
>         }
>
> -       if (i == RTE_DIM(phsc))
> +       if (i == RTE_DIM(phsc)) {
> +               free(vec.cipher_auth.digest.val);
> +               vec.cipher_auth.digest.val = NULL;
>                 return -1;
> +       }
>
>         return 0;
>  }


-- 
David Marchand


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [EXT] Re: [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-04  7:48   ` David Marchand
@ 2022-07-04  7:50     ` Akhil Goyal
  2022-07-04  8:26       ` Thomas Monjalon
  2022-07-04  8:18     ` Gowrishankar Muthukrishnan
  1 sibling, 1 reply; 11+ messages in thread
From: Akhil Goyal @ 2022-07-04  7:50 UTC (permalink / raw)
  To: David Marchand, Gowrishankar Muthukrishnan
  Cc: dev, Fan Zhang, Brian Dooley, Anoob Joseph, Archana Muniganti,
	Jerin Jacob Kollanukkaran, Thomas Monjalon

> On Sat, Jul 2, 2022 at 4:59 PM Gowrishankar Muthukrishnan
> <gmuthukrishn@marvell.com> wrote:
> >
> > There is wrong size used for allocation of digest buffer which in
> > some cases cause memory corruption. Also, fixed places where memory
> > leak is observed. This fix would enable sha 384 and 512 NIST vectors
> > be supported fully.
> >
> > Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")
> 
> This sha1 is not valid anymore, or maybe Akhil will squash the fix in
> the next-crypto tree before reaching main.
Fixed the SHA and applied on top of next-crypto as I had already asked Thomas to pull the tree.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [EXT] Re: [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-04  7:48   ` David Marchand
  2022-07-04  7:50     ` [EXT] " Akhil Goyal
@ 2022-07-04  8:18     ` Gowrishankar Muthukrishnan
  1 sibling, 0 replies; 11+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-07-04  8:18 UTC (permalink / raw)
  To: David Marchand, Akhil Goyal
  Cc: dev, Fan Zhang, Brian Dooley, Anoob Joseph, Archana Muniganti,
	Jerin Jacob Kollanukkaran, Thomas Monjalon

> vec.cipher_auth.digest.len * 8);
> > +                       if (vec.cipher_auth.digest.val)
> > +                               free(vec.cipher_auth.digest.val);
> 
> Unneeded if().
> 
Ack.

> We just did a tree-wide cleanup to avoid these.
> Please don't reintroduce some.
> 
> 
> > +
> > +                       vec.cipher_auth.digest.val = calloc(1,
> > + vec.cipher_auth.digest.len);
> 
> Don't we need to check for allocation success?
> 
Sure. I ll post fix for the  above and thanks for the review.

Regards,
Gowrishankar
> 
> >                         break;
> >                 }
> >         }
> >
> > -       if (i == RTE_DIM(phsc))
> > +       if (i == RTE_DIM(phsc)) {
> > +               free(vec.cipher_auth.digest.val);
> > +               vec.cipher_auth.digest.val = NULL;
> >                 return -1;
> > +       }
> >
> >         return 0;
> >  }
> 
> 
> --
> David Marchand


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [EXT] Re: [PATCH v2] examples/fips_validation: fix memory leak in sha test
  2022-07-04  7:50     ` [EXT] " Akhil Goyal
@ 2022-07-04  8:26       ` Thomas Monjalon
  0 siblings, 0 replies; 11+ messages in thread
From: Thomas Monjalon @ 2022-07-04  8:26 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, Akhil Goyal
  Cc: David Marchand, dev, Fan Zhang, Brian Dooley, Anoob Joseph,
	Archana Muniganti, Jerin Jacob Kollanukkaran

04/07/2022 09:50, Akhil Goyal:
> > On Sat, Jul 2, 2022 at 4:59 PM Gowrishankar Muthukrishnan
> > <gmuthukrishn@marvell.com> wrote:
> > >
> > > There is wrong size used for allocation of digest buffer which in
> > > some cases cause memory corruption. Also, fixed places where memory
> > > leak is observed. This fix would enable sha 384 and 512 NIST vectors
> > > be supported fully.
> > >
> > > Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")
> > 
> > This sha1 is not valid anymore, or maybe Akhil will squash the fix in
> > the next-crypto tree before reaching main.
> Fixed the SHA and applied on top of next-crypto as I had already asked Thomas to pull the tree.

David did some good comments, I will wait for a better version of the patch.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3] examples/fips_validation: fix memory leak in sha test
  2022-07-02 18:44 ` Gowrishankar Muthukrishnan
  2022-07-04  7:00   ` Akhil Goyal
@ 2022-07-04  9:55   ` Gowrishankar Muthukrishnan
  2022-07-04 10:34     ` Akhil Goyal
  1 sibling, 1 reply; 11+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-07-04  9:55 UTC (permalink / raw)
  To: dev
  Cc: Akhil Goyal, Fan Zhang, Brian Dooley, Anoob Joseph,
	Archana Muniganti, Jerin Jacob, Gowrishankar Muthukrishnan

There is wrong size used for allocation of digest buffer which in
some cases cause memory corruption. Also, fixed places where memory
leak is observed. This fix would enable sha 384 and 512 NIST vectors
be supported fully.

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
v3:
 - addes fixes for suggestions in v2.
---
 doc/guides/sample_app_ug/fips_validation.rst   |  2 +-
 examples/fips_validation/fips_validation_sha.c | 11 +++++++++--
 examples/fips_validation/main.c                |  1 +
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/doc/guides/sample_app_ug/fips_validation.rst b/doc/guides/sample_app_ug/fips_validation.rst
index 4b68226665..6f4bd34726 100644
--- a/doc/guides/sample_app_ug/fips_validation.rst
+++ b/doc/guides/sample_app_ug/fips_validation.rst
@@ -63,7 +63,7 @@ ACVP
     * AES-CMAC (128,192,256) - AFT
     * AES-XTS (128,256) - AFT
     * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
-    * SHA (1,256) - AFT, MCT
+    * SHA (1, 256, 384, 512) - AFT, MCT
 
 
 Application Information
diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c
index a2928618d7..dff552586f 100644
--- a/examples/fips_validation/fips_validation_sha.c
+++ b/examples/fips_validation/fips_validation_sha.c
@@ -229,13 +229,20 @@ parse_test_sha_json_algorithm(void)
 	for (i = 0; i < RTE_DIM(phsc); i++) {
 		if (info.interim_info.sha_data.algo == phsc[i].algo) {
 			vec.cipher_auth.digest.len = atoi(phsc[i].str);
-			vec.cipher_auth.digest.val = calloc(0, vec.cipher_auth.digest.len * 8);
+			free(vec.cipher_auth.digest.val);
+			vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);
+			if (vec.cipher_auth.digest.val == NULL)
+				return -1;
+
 			break;
 		}
 	}
 
-	if (i == RTE_DIM(phsc))
+	if (i == RTE_DIM(phsc)) {
+		free(vec.cipher_auth.digest.val);
+		vec.cipher_auth.digest.val = NULL;
 		return -1;
+	}
 
 	return 0;
 }
diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 6d52048b5c..8bd5a66889 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -2099,6 +2099,7 @@ fips_test_one_json_file(void)
 		json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
 		fips_test_one_vector_set();
 		json_array_append_new(json_info.json_write_root, json_info.json_write_set);
+		json_incref(json_info.json_write_set);
 	}
 
 	json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH v3] examples/fips_validation: fix memory leak in sha test
  2022-07-04  9:55   ` [PATCH v3] " Gowrishankar Muthukrishnan
@ 2022-07-04 10:34     ` Akhil Goyal
  2022-07-04 17:32       ` Akhil Goyal
  0 siblings, 1 reply; 11+ messages in thread
From: Akhil Goyal @ 2022-07-04 10:34 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, dev, David Marchand, Thomas Monjalon
  Cc: Fan Zhang, Brian Dooley, Anoob Joseph, Archana Muniganti,
	Jerin Jacob Kollanukkaran, Gowrishankar Muthukrishnan

> Subject: [PATCH v3] examples/fips_validation: fix memory leak in sha test
> 
> There is wrong size used for allocation of digest buffer which in
> some cases cause memory corruption. Also, fixed places where memory
> leak is observed. This fix would enable sha 384 and 512 NIST vectors
> be supported fully.

Fixes: c9819d389b4b ("examples/fips_validation: add parsing for SHA")

++David/Thomas
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
> v3:
>  - addes fixes for suggestions in v2.
> ---
>  doc/guides/sample_app_ug/fips_validation.rst   |  2 +-
>  examples/fips_validation/fips_validation_sha.c | 11 +++++++++--
>  examples/fips_validation/main.c                |  1 +
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/doc/guides/sample_app_ug/fips_validation.rst
> b/doc/guides/sample_app_ug/fips_validation.rst
> index 4b68226665..6f4bd34726 100644
> --- a/doc/guides/sample_app_ug/fips_validation.rst
> +++ b/doc/guides/sample_app_ug/fips_validation.rst
> @@ -63,7 +63,7 @@ ACVP
>      * AES-CMAC (128,192,256) - AFT
>      * AES-XTS (128,256) - AFT
>      * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
> -    * SHA (1,256) - AFT, MCT
> +    * SHA (1, 256, 384, 512) - AFT, MCT
> 
> 
>  Application Information
> diff --git a/examples/fips_validation/fips_validation_sha.c
> b/examples/fips_validation/fips_validation_sha.c
> index a2928618d7..dff552586f 100644
> --- a/examples/fips_validation/fips_validation_sha.c
> +++ b/examples/fips_validation/fips_validation_sha.c
> @@ -229,13 +229,20 @@ parse_test_sha_json_algorithm(void)
>  	for (i = 0; i < RTE_DIM(phsc); i++) {
>  		if (info.interim_info.sha_data.algo == phsc[i].algo) {
>  			vec.cipher_auth.digest.len = atoi(phsc[i].str);
> -			vec.cipher_auth.digest.val = calloc(0,
> vec.cipher_auth.digest.len * 8);
> +			free(vec.cipher_auth.digest.val);
> +			vec.cipher_auth.digest.val = calloc(1,
> vec.cipher_auth.digest.len);
> +			if (vec.cipher_auth.digest.val == NULL)
> +				return -1;
> +
>  			break;
>  		}
>  	}
> 
> -	if (i == RTE_DIM(phsc))
> +	if (i == RTE_DIM(phsc)) {
> +		free(vec.cipher_auth.digest.val);
> +		vec.cipher_auth.digest.val = NULL;
>  		return -1;
> +	}
> 
>  	return 0;
>  }
> diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
> index 6d52048b5c..8bd5a66889 100644
> --- a/examples/fips_validation/main.c
> +++ b/examples/fips_validation/main.c
> @@ -2099,6 +2099,7 @@ fips_test_one_json_file(void)
>  		json_info.json_vector_set =
> json_array_get(json_info.json_root, vector_set_idx);
>  		fips_test_one_vector_set();
>  		json_array_append_new(json_info.json_write_root,
> json_info.json_write_set);
> +		json_incref(json_info.json_write_set);
>  	}
> 
>  	json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
> --
> 2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH v3] examples/fips_validation: fix memory leak in sha test
  2022-07-04 10:34     ` Akhil Goyal
@ 2022-07-04 17:32       ` Akhil Goyal
  0 siblings, 0 replies; 11+ messages in thread
From: Akhil Goyal @ 2022-07-04 17:32 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, dev, David Marchand, Thomas Monjalon
  Cc: Fan Zhang, Brian Dooley, Anoob Joseph, Archana Muniganti,
	Jerin Jacob Kollanukkaran, Gowrishankar Muthukrishnan

> Subject: RE: [PATCH v3] examples/fips_validation: fix memory leak in sha test
> 
> > Subject: [PATCH v3] examples/fips_validation: fix memory leak in sha test
> >
> > There is wrong size used for allocation of digest buffer which in
> > some cases cause memory corruption. Also, fixed places where memory
> > leak is observed. This fix would enable sha 384 and 512 NIST vectors
> > be supported fully.
> 
> Fixes: c9819d389b4b ("examples/fips_validation: add parsing for SHA")
> 
> ++David/Thomas
Squashed with original commit.

Thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-07-04 17:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-02 14:51 [PATCH v1] examples/fips_validation: fix memory leak in sha test Gowrishankar Muthukrishnan
2022-07-02 14:58 ` [PATCH v2] " Gowrishankar Muthukrishnan
2022-07-04  7:48   ` David Marchand
2022-07-04  7:50     ` [EXT] " Akhil Goyal
2022-07-04  8:26       ` Thomas Monjalon
2022-07-04  8:18     ` Gowrishankar Muthukrishnan
2022-07-02 18:44 ` Gowrishankar Muthukrishnan
2022-07-04  7:00   ` Akhil Goyal
2022-07-04  9:55   ` [PATCH v3] " Gowrishankar Muthukrishnan
2022-07-04 10:34     ` Akhil Goyal
2022-07-04 17:32       ` Akhil Goyal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).