DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx5: fix use of uninitialized array
@ 2020-02-05  6:42 Dekel Peled
  2020-02-05  7:28 ` Slava Ovsiienko
  2020-02-05  9:50 ` Raslan Darawsheh
  0 siblings, 2 replies; 3+ messages in thread
From: Dekel Peled @ 2020-02-05  6:42 UTC (permalink / raw)
  To: matan, viacheslavo, rasland; +Cc: dev, bingz

Previous patch changed the format of struct
mlx5_flow_dv_modify_hdr_resource, to use a flexible array for
modification actions.
In __flow_dv_translate() a union was defined with item of this struct,
and an array of maximal possible size.
Aray elements are filled in several functions.
In function flow_dv_convert_action_set_reg(), array element is filled
partially, while the other fields of this array element are left
uninitialized.
This may cause failure of flow_dv_modify_hdr_resource_register()
when calling driver function with the 'dirty' array.

This patch updates flow_dv_convert_action_set_reg(), setting the
selected array element fields while clearing the other fields.
Other functions that fill the same array elements are also updated
for clarity and proofing future use.

Fixes: 024e957 ("net/mlx5: fix modify actions support limitation")
Cc: bingz@mellanox.com

Signed-off-by: Dekel Peled <dekelp@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow_dv.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 2878393..3daabd3 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -385,10 +385,12 @@ struct field_modify_info modify_tcp[] = {
 			 off_b - __builtin_clz(mask);
 		MLX5_ASSERT(size_b);
 		size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
-		actions[i].action_type = type;
-		actions[i].field = field->id;
-		actions[i].offset = off_b;
-		actions[i].length = size_b;
+		actions[i] = (struct mlx5_modification_cmd) {
+			.action_type = type,
+			.field = field->id,
+			.offset = off_b,
+			.length = size_b,
+		};
 		/* Convert entire record to expected big-endian format. */
 		actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
 		if (type == MLX5_MODIFICATION_TYPE_COPY) {
@@ -578,10 +580,12 @@ struct field_modify_info modify_tcp[] = {
 		return rte_flow_error_set(error, EINVAL,
 			 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
 			 "too many items to modify");
-	actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
-	actions[i].field = field->id;
-	actions[i].length = field->size;
-	actions[i].offset = field->offset;
+	actions[i] = (struct mlx5_modification_cmd) {
+		.action_type = MLX5_MODIFICATION_TYPE_SET,
+		.field = field->id,
+		.length = field->size,
+		.offset = field->offset,
+	};
 	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
 	actions[i].data1 = conf->vlan_vid;
 	actions[i].data1 = actions[i].data1 << 16;
@@ -913,8 +917,10 @@ struct field_modify_info modify_tcp[] = {
 					  "too many items to modify");
 	MLX5_ASSERT(conf->id != REG_NONE);
 	MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
-	actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
-	actions[i].field = reg_to_field[conf->id];
+	actions[i] = (struct mlx5_modification_cmd) {
+		.action_type = MLX5_MODIFICATION_TYPE_SET,
+		.field = reg_to_field[conf->id],
+	};
 	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
 	actions[i].data1 = rte_cpu_to_be_32(conf->data);
 	++i;
-- 
1.8.3.1


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

* Re: [dpdk-dev] [PATCH] net/mlx5: fix use of uninitialized array
  2020-02-05  6:42 [dpdk-dev] [PATCH] net/mlx5: fix use of uninitialized array Dekel Peled
@ 2020-02-05  7:28 ` Slava Ovsiienko
  2020-02-05  9:50 ` Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Slava Ovsiienko @ 2020-02-05  7:28 UTC (permalink / raw)
  To: Dekel Peled, Matan Azrad, Raslan Darawsheh; +Cc: dev, Bing Zhao

Very nice, Dekel, we found the root cause of the failure.

Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

> -----Original Message-----
> From: Dekel Peled <dekelp@mellanox.com>
> Sent: Wednesday, February 5, 2020 8:42
> To: Matan Azrad <matan@mellanox.com>; Slava Ovsiienko
> <viacheslavo@mellanox.com>; Raslan Darawsheh <rasland@mellanox.com>
> Cc: dev@dpdk.org; Bing Zhao <bingz@mellanox.com>
> Subject: [PATCH] net/mlx5: fix use of uninitialized array
> 
> Previous patch changed the format of struct
> mlx5_flow_dv_modify_hdr_resource, to use a flexible array for modification
> actions.
> In __flow_dv_translate() a union was defined with item of this struct, and an
> array of maximal possible size.
> Aray elements are filled in several functions.
> In function flow_dv_convert_action_set_reg(), array element is filled partially,
> while the other fields of this array element are left uninitialized.
> This may cause failure of flow_dv_modify_hdr_resource_register()
> when calling driver function with the 'dirty' array.
> 
> This patch updates flow_dv_convert_action_set_reg(), setting the selected
> array element fields while clearing the other fields.
> Other functions that fill the same array elements are also updated for clarity
> and proofing future use.
> 
> Fixes: 024e957 ("net/mlx5: fix modify actions support limitation")	
> Cc: bingz@mellanox.com
> 
> Signed-off-by: Dekel Peled <dekelp@mellanox.com>
> Acked-by: Matan Azrad <matan@mellanox.com>
> ---
>  drivers/net/mlx5/mlx5_flow_dv.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow_dv.c
> b/drivers/net/mlx5/mlx5_flow_dv.c index 2878393..3daabd3 100644
> --- a/drivers/net/mlx5/mlx5_flow_dv.c
> +++ b/drivers/net/mlx5/mlx5_flow_dv.c
> @@ -385,10 +385,12 @@ struct field_modify_info modify_tcp[] = {
>  			 off_b - __builtin_clz(mask);
>  		MLX5_ASSERT(size_b);
>  		size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
> -		actions[i].action_type = type;
> -		actions[i].field = field->id;
> -		actions[i].offset = off_b;
> -		actions[i].length = size_b;
> +		actions[i] = (struct mlx5_modification_cmd) {
> +			.action_type = type,
> +			.field = field->id,
> +			.offset = off_b,
> +			.length = size_b,
> +		};
>  		/* Convert entire record to expected big-endian format. */
>  		actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
>  		if (type == MLX5_MODIFICATION_TYPE_COPY) { @@ -578,10
> +580,12 @@ struct field_modify_info modify_tcp[] = {
>  		return rte_flow_error_set(error, EINVAL,
>  			 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
>  			 "too many items to modify");
> -	actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
> -	actions[i].field = field->id;
> -	actions[i].length = field->size;
> -	actions[i].offset = field->offset;
> +	actions[i] = (struct mlx5_modification_cmd) {
> +		.action_type = MLX5_MODIFICATION_TYPE_SET,
> +		.field = field->id,
> +		.length = field->size,
> +		.offset = field->offset,
> +	};
>  	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
>  	actions[i].data1 = conf->vlan_vid;
>  	actions[i].data1 = actions[i].data1 << 16; @@ -913,8 +917,10 @@
> struct field_modify_info modify_tcp[] = {
>  					  "too many items to modify");
>  	MLX5_ASSERT(conf->id != REG_NONE);
>  	MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
> -	actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
> -	actions[i].field = reg_to_field[conf->id];
> +	actions[i] = (struct mlx5_modification_cmd) {
> +		.action_type = MLX5_MODIFICATION_TYPE_SET,
> +		.field = reg_to_field[conf->id],
> +	};
>  	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
>  	actions[i].data1 = rte_cpu_to_be_32(conf->data);
>  	++i;
> --
> 1.8.3.1


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

* Re: [dpdk-dev] [PATCH] net/mlx5: fix use of uninitialized array
  2020-02-05  6:42 [dpdk-dev] [PATCH] net/mlx5: fix use of uninitialized array Dekel Peled
  2020-02-05  7:28 ` Slava Ovsiienko
@ 2020-02-05  9:50 ` Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Raslan Darawsheh @ 2020-02-05  9:50 UTC (permalink / raw)
  To: Dekel Peled, Matan Azrad, Slava Ovsiienko; +Cc: dev, Bing Zhao

Hi,

> -----Original Message-----
> From: Dekel Peled <dekelp@mellanox.com>
> Sent: Wednesday, February 5, 2020 8:42 AM
> To: Matan Azrad <matan@mellanox.com>; Slava Ovsiienko
> <viacheslavo@mellanox.com>; Raslan Darawsheh <rasland@mellanox.com>
> Cc: dev@dpdk.org; Bing Zhao <bingz@mellanox.com>
> Subject: [PATCH] net/mlx5: fix use of uninitialized array
> 
> Previous patch changed the format of struct
> mlx5_flow_dv_modify_hdr_resource, to use a flexible array for
> modification actions.
> In __flow_dv_translate() a union was defined with item of this struct,
> and an array of maximal possible size.
> Aray elements are filled in several functions.
> In function flow_dv_convert_action_set_reg(), array element is filled
> partially, while the other fields of this array element are left
> uninitialized.
> This may cause failure of flow_dv_modify_hdr_resource_register()
> when calling driver function with the 'dirty' array.
> 
> This patch updates flow_dv_convert_action_set_reg(), setting the
> selected array element fields while clearing the other fields.
> Other functions that fill the same array elements are also updated
> for clarity and proofing future use.
> 
> Fixes: 024e957 ("net/mlx5: fix modify actions support limitation")
> Cc: bingz@mellanox.com
> 
> Signed-off-by: Dekel Peled <dekelp@mellanox.com>
> Acked-by: Matan Azrad <matan@mellanox.com>
> ---
>  drivers/net/mlx5/mlx5_flow_dv.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow_dv.c
> b/drivers/net/mlx5/mlx5_flow_dv.c
> index 2878393..3daabd3 100644
> --- a/drivers/net/mlx5/mlx5_flow_dv.c
> +++ b/drivers/net/mlx5/mlx5_flow_dv.c
> @@ -385,10 +385,12 @@ struct field_modify_info modify_tcp[] = {
>  			 off_b - __builtin_clz(mask);
>  		MLX5_ASSERT(size_b);
>  		size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
> -		actions[i].action_type = type;
> -		actions[i].field = field->id;
> -		actions[i].offset = off_b;
> -		actions[i].length = size_b;
> +		actions[i] = (struct mlx5_modification_cmd) {
> +			.action_type = type,
> +			.field = field->id,
> +			.offset = off_b,
> +			.length = size_b,
> +		};
>  		/* Convert entire record to expected big-endian format. */
>  		actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
>  		if (type == MLX5_MODIFICATION_TYPE_COPY) {
> @@ -578,10 +580,12 @@ struct field_modify_info modify_tcp[] = {
>  		return rte_flow_error_set(error, EINVAL,
>  			 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
>  			 "too many items to modify");
> -	actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
> -	actions[i].field = field->id;
> -	actions[i].length = field->size;
> -	actions[i].offset = field->offset;
> +	actions[i] = (struct mlx5_modification_cmd) {
> +		.action_type = MLX5_MODIFICATION_TYPE_SET,
> +		.field = field->id,
> +		.length = field->size,
> +		.offset = field->offset,
> +	};
>  	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
>  	actions[i].data1 = conf->vlan_vid;
>  	actions[i].data1 = actions[i].data1 << 16;
> @@ -913,8 +917,10 @@ struct field_modify_info modify_tcp[] = {
>  					  "too many items to modify");
>  	MLX5_ASSERT(conf->id != REG_NONE);
>  	MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
> -	actions[i].action_type = MLX5_MODIFICATION_TYPE_SET;
> -	actions[i].field = reg_to_field[conf->id];
> +	actions[i] = (struct mlx5_modification_cmd) {
> +		.action_type = MLX5_MODIFICATION_TYPE_SET,
> +		.field = reg_to_field[conf->id],
> +	};
>  	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
>  	actions[i].data1 = rte_cpu_to_be_32(conf->data);
>  	++i;
> --
> 1.8.3.1


Added Cc: stable@dpdk.org

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

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

end of thread, other threads:[~2020-02-05  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05  6:42 [dpdk-dev] [PATCH] net/mlx5: fix use of uninitialized array Dekel Peled
2020-02-05  7:28 ` Slava Ovsiienko
2020-02-05  9:50 ` Raslan Darawsheh

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