patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH v1] net/cpfl: fix cpfl parser issue
@ 2024-07-30  5:09 Praveen Shetty
  2024-07-31  7:23 ` [PATCH v2] " Praveen Shetty
  0 siblings, 1 reply; 6+ messages in thread
From: Praveen Shetty @ 2024-07-30  5:09 UTC (permalink / raw)
  To: dev, bruce.richardson; +Cc: stable

CPFL parser was incorrectly parsing the mask value of the
next_proto_id field as a string instead of unsigned integer.
This patch will fix this issue.

Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
Cc: stable@dpdk.org

Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
---
 drivers/net/cpfl/cpfl_flow_parser.c | 31 ++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/net/cpfl/cpfl_flow_parser.c b/drivers/net/cpfl/cpfl_flow_parser.c
index 40569ddc6f..9845bd1ad3 100644
--- a/drivers/net/cpfl/cpfl_flow_parser.c
+++ b/drivers/net/cpfl/cpfl_flow_parser.c
@@ -213,16 +213,29 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
 
 		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
 		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
-			mask = cpfl_json_t_to_string(object, "mask");
-			if (!mask) {
-				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
-				goto err;
-			}
-			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
-				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
-				goto err;
+			/* Added a check for parsing mask value of the next_proto_id field. */
+			if (strcmp(name, "next_proto_id") == 0) {
+				uint32_t mask_32b;
+				int ret;
+				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
+				if (ret < 0) {
+					PMD_DRV_LOG(ERR, "Can not parse uint32 'mask'.");
+					goto err;
+				}
+				js_field->fields[i].mask_32b = mask_32b;
+			} else {
+				mask = cpfl_json_t_to_string(object, "mask");
+				if (!mask) {
+					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
+					goto err;
+				}
+				if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
+					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
+					goto err;
+				}
+				rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
 			}
-			strncpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
+
 		} else {
 			uint32_t mask_32b;
 			int ret;
-- 
2.34.1


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

* [PATCH v2] net/cpfl: fix cpfl parser issue
  2024-07-30  5:09 [PATCH v1] net/cpfl: fix cpfl parser issue Praveen Shetty
@ 2024-07-31  7:23 ` Praveen Shetty
  2024-08-22 16:50   ` Bruce Richardson
  2024-08-23 11:14   ` [PATCH v3] " Praveen Shetty
  0 siblings, 2 replies; 6+ messages in thread
From: Praveen Shetty @ 2024-07-31  7:23 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, stable

CPFL parser was incorrectly parsing the mask value of the
next_proto_id field from recipe.json file as a string
instead of unsigned integer.

Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
Cc: stable@dpdk.org

Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>

---
v2:
* Fixed CI issues.
---
 drivers/net/cpfl/cpfl_flow_parser.c | 34 +++++++++++++++++++----------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/net/cpfl/cpfl_flow_parser.c b/drivers/net/cpfl/cpfl_flow_parser.c
index 40569ddc6f..7800ad97ea 100644
--- a/drivers/net/cpfl/cpfl_flow_parser.c
+++ b/drivers/net/cpfl/cpfl_flow_parser.c
@@ -198,6 +198,8 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
 	for (i = 0; i < len; i++) {
 		json_t *object;
 		const char *name, *mask;
+		uint32_t mask_32b = 0;
+		int ret;
 
 		object = json_array_get(ob_fields, i);
 		name = cpfl_json_t_to_string(object, "name");
@@ -213,20 +215,28 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
 
 		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
 		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
-			mask = cpfl_json_t_to_string(object, "mask");
-			if (!mask) {
-				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
-				goto err;
-			}
-			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
-				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
-				goto err;
+			/* Added a check for parsing mask value of the next_proto_id field. */
+			if (strcmp(name, "next_proto_id") == 0) {
+				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
+				if (ret < 0) {
+					PMD_DRV_LOG(ERR, "Cannot parse uint32 'mask'.");
+					goto err;
+				}
+				js_field->fields[i].mask_32b = mask_32b;
+			} else {
+				mask = cpfl_json_t_to_string(object, "mask");
+				if (!mask) {
+					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
+					goto err;
+				}
+				if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
+					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
+					goto err;
+				}
+				rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
 			}
-			strncpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
-		} else {
-			uint32_t mask_32b;
-			int ret;
 
+		} else {
 			ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
 			if (ret < 0) {
 				PMD_DRV_LOG(ERR, "Can not parse uint32 'mask'.");
-- 
2.34.1


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

* Re: [PATCH v2] net/cpfl: fix cpfl parser issue
  2024-07-31  7:23 ` [PATCH v2] " Praveen Shetty
@ 2024-08-22 16:50   ` Bruce Richardson
  2024-08-23  7:28     ` Shetty, Praveen
  2024-08-23 11:14   ` [PATCH v3] " Praveen Shetty
  1 sibling, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2024-08-22 16:50 UTC (permalink / raw)
  To: Praveen Shetty; +Cc: dev, stable

On Wed, Jul 31, 2024 at 07:23:03AM +0000, Praveen Shetty wrote:
> CPFL parser was incorrectly parsing the mask value of the
> next_proto_id field from recipe.json file as a string
> instead of unsigned integer.
> 
> Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
> 
> ---
> v2:
> * Fixed CI issues.
> ---
>  drivers/net/cpfl/cpfl_flow_parser.c | 34 +++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/cpfl/cpfl_flow_parser.c b/drivers/net/cpfl/cpfl_flow_parser.c
> index 40569ddc6f..7800ad97ea 100644
> --- a/drivers/net/cpfl/cpfl_flow_parser.c
> +++ b/drivers/net/cpfl/cpfl_flow_parser.c
> @@ -198,6 +198,8 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
>  	for (i = 0; i < len; i++) {
>  		json_t *object;
>  		const char *name, *mask;
> +		uint32_t mask_32b = 0;
> +		int ret;
>  
>  		object = json_array_get(ob_fields, i);
>  		name = cpfl_json_t_to_string(object, "name");
> @@ -213,20 +215,28 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
>  
>  		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
>  		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
> -			mask = cpfl_json_t_to_string(object, "mask");
> -			if (!mask) {
> -				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
> -				goto err;
> -			}
> -			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
> -				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
> -				goto err;
> +			/* Added a check for parsing mask value of the next_proto_id field. */
> +			if (strcmp(name, "next_proto_id") == 0) {
> +				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
> +				if (ret < 0) {
> +					PMD_DRV_LOG(ERR, "Cannot parse uint32 'mask'.");
> +					goto err;
> +				}
> +				js_field->fields[i].mask_32b = mask_32b;
> +			} else {
> +				mask = cpfl_json_t_to_string(object, "mask");
> +				if (!mask) {
> +					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
> +					goto err;
> +				}
> +				if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
> +					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
> +					goto err;
> +				}
> +				rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);

+1 for replacing strncpy with something safer, since original code is wrong
and can leave a non-null-terminated string, but unfortunately the copy here
isn't quite right. For strlcpy and rte_strscpy, you specify the exact
buffer size, not the size-1.

Also, you don't need to check the length and then do the copy, you might as
well just do the copy using strscpy or strlcpy and check the return value
from it. Saves iterating the string twice (once for length, second time for
copy). For example:

  if (rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE) < 0) {
  	PMD_DRV_LOG(ERR, "The 'mask' is too long.");
  	goto err;
  }

Regards,
/Bruce

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

* RE: [PATCH v2] net/cpfl: fix cpfl parser issue
  2024-08-22 16:50   ` Bruce Richardson
@ 2024-08-23  7:28     ` Shetty, Praveen
  0 siblings, 0 replies; 6+ messages in thread
From: Shetty, Praveen @ 2024-08-23  7:28 UTC (permalink / raw)
  To: Richardson, Bruce; +Cc: dev, stable

> CPFL parser was incorrectly parsing the mask value of the 
> next_proto_id field from recipe.json file as a string instead of 
> unsigned integer.
> 
> Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
> 
> ---
> v2:
> * Fixed CI issues.
> ---
>  drivers/net/cpfl/cpfl_flow_parser.c | 34 
> +++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/cpfl/cpfl_flow_parser.c 
> b/drivers/net/cpfl/cpfl_flow_parser.c
> index 40569ddc6f..7800ad97ea 100644
> --- a/drivers/net/cpfl/cpfl_flow_parser.c
> +++ b/drivers/net/cpfl/cpfl_flow_parser.c
> @@ -198,6 +198,8 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
>  	for (i = 0; i < len; i++) {
>  		json_t *object;
>  		const char *name, *mask;
> +		uint32_t mask_32b = 0;
> +		int ret;
>  
>  		object = json_array_get(ob_fields, i);
>  		name = cpfl_json_t_to_string(object, "name"); @@ -213,20 +215,28 @@ 
> cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
>  
>  		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
>  		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
> -			mask = cpfl_json_t_to_string(object, "mask");
> -			if (!mask) {
> -				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
> -				goto err;
> -			}
> -			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
> -				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
> -				goto err;
> +			/* Added a check for parsing mask value of the next_proto_id field. */
> +			if (strcmp(name, "next_proto_id") == 0) {
> +				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
> +				if (ret < 0) {
> +					PMD_DRV_LOG(ERR, "Cannot parse uint32 'mask'.");
> +					goto err;
> +				}
> +				js_field->fields[i].mask_32b = mask_32b;
> +			} else {
> +				mask = cpfl_json_t_to_string(object, "mask");
> +				if (!mask) {
> +					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
> +					goto err;
> +				}
> +				if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
> +					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
> +					goto err;
> +				}
> +				rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 
> +1);

+1 for replacing strncpy with something safer, since original code is 
+wrong
and can leave a non-null-terminated string, but unfortunately the copy here isn't quite right. For strlcpy and rte_strscpy, you specify the exact buffer size, not the size-1.

Also, you don't need to check the length and then do the copy, you might as well just do the copy using strscpy or strlcpy and check the return value from it. Saves iterating the string twice (once for length, second time for copy). For example:

  if (rte_strscpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE) < 0) {
  	PMD_DRV_LOG(ERR, "The 'mask' is too long.");
  	goto err;
  }

Thanks, will fix this in v3.

Regards,
/Bruce

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

* [PATCH v3] net/cpfl: fix cpfl parser issue
  2024-07-31  7:23 ` [PATCH v2] " Praveen Shetty
  2024-08-22 16:50   ` Bruce Richardson
@ 2024-08-23 11:14   ` Praveen Shetty
  2024-08-26 15:32     ` Bruce Richardson
  1 sibling, 1 reply; 6+ messages in thread
From: Praveen Shetty @ 2024-08-23 11:14 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, stable

CPFL parser was incorrectly parsing the mask value of the
next_proto_id field from recipe.json file as a string
instead of unsigned integer.

Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
Cc: stable@dpdk.org

Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>

---
v2:
* Fixed CI issues.
v3:
* Addressed review comments.
---
 drivers/net/cpfl/cpfl_flow_parser.c | 34 +++++++++++++++++++----------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/net/cpfl/cpfl_flow_parser.c b/drivers/net/cpfl/cpfl_flow_parser.c
index 40569ddc6f..692b208a65 100644
--- a/drivers/net/cpfl/cpfl_flow_parser.c
+++ b/drivers/net/cpfl/cpfl_flow_parser.c
@@ -198,6 +198,8 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
 	for (i = 0; i < len; i++) {
 		json_t *object;
 		const char *name, *mask;
+		uint32_t mask_32b = 0;
+		int ret;
 
 		object = json_array_get(ob_fields, i);
 		name = cpfl_json_t_to_string(object, "name");
@@ -213,20 +215,28 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,
 
 		if (js_field->type == RTE_FLOW_ITEM_TYPE_ETH ||
 		    js_field->type == RTE_FLOW_ITEM_TYPE_IPV4) {
-			mask = cpfl_json_t_to_string(object, "mask");
-			if (!mask) {
-				PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
-				goto err;
-			}
-			if (strlen(mask) > CPFL_JS_STR_SIZE - 1) {
-				PMD_DRV_LOG(ERR, "The 'mask' is too long.");
-				goto err;
+			/* Added a check for parsing mask value of the next_proto_id field. */
+			if (strcmp(name, "next_proto_id") == 0) {
+				ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
+				if (ret < 0) {
+					PMD_DRV_LOG(ERR, "Cannot parse uint32 'mask'.");
+					goto err;
+				}
+				js_field->fields[i].mask_32b = mask_32b;
+			} else {
+				mask = cpfl_json_t_to_string(object, "mask");
+				if (!mask) {
+					PMD_DRV_LOG(ERR, "Can not parse string 'mask'.");
+					goto err;
+				}
+				if (rte_strscpy(js_field->fields[i].mask,
+						mask, CPFL_JS_STR_SIZE) < 0) {
+					PMD_DRV_LOG(ERR, "The 'mask' is too long.");
+					goto err;
+				}
 			}
-			strncpy(js_field->fields[i].mask, mask, CPFL_JS_STR_SIZE - 1);
-		} else {
-			uint32_t mask_32b;
-			int ret;
 
+		} else {
 			ret = cpfl_json_t_to_uint32(object, "mask", &mask_32b);
 			if (ret < 0) {
 				PMD_DRV_LOG(ERR, "Can not parse uint32 'mask'.");
-- 
2.34.1


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

* Re: [PATCH v3] net/cpfl: fix cpfl parser issue
  2024-08-23 11:14   ` [PATCH v3] " Praveen Shetty
@ 2024-08-26 15:32     ` Bruce Richardson
  0 siblings, 0 replies; 6+ messages in thread
From: Bruce Richardson @ 2024-08-26 15:32 UTC (permalink / raw)
  To: Praveen Shetty; +Cc: dev, stable

On Fri, Aug 23, 2024 at 11:14:50AM +0000, Praveen Shetty wrote:
> CPFL parser was incorrectly parsing the mask value of the
> next_proto_id field from recipe.json file as a string
> instead of unsigned integer.
> 
> Fixes: 41f20298ee8c ("net/cpfl: parse flow offloading hint from JSON")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Praveen Shetty <praveen.shetty@intel.com>
> 
> ---
> v2:
> * Fixed CI issues.
> v3:
> * Addressed review comments.
> ---
>  drivers/net/cpfl/cpfl_flow_parser.c | 34 +++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied to dpdk-next-net-intel,

thanks,
/Bruce

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

end of thread, other threads:[~2024-08-26 15:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-30  5:09 [PATCH v1] net/cpfl: fix cpfl parser issue Praveen Shetty
2024-07-31  7:23 ` [PATCH v2] " Praveen Shetty
2024-08-22 16:50   ` Bruce Richardson
2024-08-23  7:28     ` Shetty, Praveen
2024-08-23 11:14   ` [PATCH v3] " Praveen Shetty
2024-08-26 15:32     ` Bruce Richardson

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).