patch 'net/mlx5: fix VLAN handling in meter split' has been queued to stable release 21.11.7

Kevin Traynor ktraynor at redhat.com
Fri Mar 8 15:28:14 CET 2024


Hi,

FYI, your patch has been queued to stable release 21.11.7

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 03/13/24. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/03c7f0a177554bf65966aa0bcd88295f3ad915e2

Thanks.

Kevin

---
>From 03c7f0a177554bf65966aa0bcd88295f3ad915e2 Mon Sep 17 00:00:00 2001
From: Dariusz Sosnowski <dsosnowski at nvidia.com>
Date: Tue, 27 Feb 2024 14:58:15 +0100
Subject: [PATCH] net/mlx5: fix VLAN handling in meter split

[ upstream commit 5d2301a222d77e7bac3a085aa17f8ef7a3af7ffe ]

On the attempt to create a flow rule with:

- matching on REPRESENTED_PORT,
- matching on outer VLAN tag,
- matching on inner VLAN tag,
- METER action,

flow splitting mechanism for handling metering flows was causing
memory corruption. It was assumed that suffix flow will have a single
VLAN item (used for translation of OF_PUSH_VLAN/OF_SET_VLAN_VID
actions), however during flow_meter_split_prep() 2 VLAN items were
parsed. This caused the buffer overflow on allocated
suffix flow item buffer.

This patch fixes this overflow, by account for number of VLAN items
in flow rule pattern when allocating items for suffix flow.

Fixes: 50f576d657d7 ("net/mlx5: fix VLAN actions in meter")

Signed-off-by: Dariusz Sosnowski <dsosnowski at nvidia.com>
Acked-by: Suanming Mou <suanmingm at nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c | 60 +++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 5d489c7f92..6399d93b93 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -5083,6 +5083,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	struct mlx5_rte_flow_item_tag *tag_item_mask;
 	uint32_t tag_id = 0;
-	struct rte_flow_item *vlan_item_dst = NULL;
-	const struct rte_flow_item *vlan_item_src = NULL;
+	bool vlan_actions;
+	struct rte_flow_item *orig_sfx_items = sfx_items;
 	const struct rte_flow_item *orig_items = items;
 	struct rte_flow_action *hw_mtr_action;
@@ -5101,4 +5101,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
+	tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
 		int item_type = items->type;
@@ -5121,8 +5122,11 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 			break;
 		case RTE_FLOW_ITEM_TYPE_VLAN:
-			/* Determine if copy vlan item below. */
-			vlan_item_src = items;
-			vlan_item_dst = sfx_items++;
-			vlan_item_dst->type = RTE_FLOW_ITEM_TYPE_VOID;
+			/*
+			 * Copy VLAN items in case VLAN actions are performed.
+			 * If there are no VLAN actions, these items will be VOID.
+			 */
+			memcpy(sfx_items, items, sizeof(*sfx_items));
+			sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
+			sfx_items++;
 			break;
 		default:
@@ -5141,4 +5145,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	}
 	/* Prepare the actions for prefix and suffix flow. */
+	vlan_actions = false;
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
 		struct rte_flow_action *action_cur = NULL;
@@ -5171,14 +5176,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
 		case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
-			if (vlan_item_dst && vlan_item_src) {
-				memcpy(vlan_item_dst, vlan_item_src,
-					sizeof(*vlan_item_dst));
-				/*
-				 * Convert to internal match item, it is used
-				 * for vlan push and set vid.
-				 */
-				vlan_item_dst->type = (enum rte_flow_item_type)
-						MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
-			}
+			vlan_actions = true;
 			break;
 		case RTE_FLOW_ACTION_TYPE_COUNT:
@@ -5195,4 +5191,12 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		memcpy(action_cur, actions, sizeof(struct rte_flow_action));
 	}
+	/* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
+	if (!vlan_actions) {
+		struct rte_flow_item *it = orig_sfx_items;
+
+		for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
+			if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
+				it->type = RTE_FLOW_ITEM_TYPE_VOID;
+	}
 	/* Add end action to the actions. */
 	actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
@@ -5284,6 +5288,4 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 				MLX5_RTE_FLOW_ACTION_TYPE_TAG;
 	tag_action->conf = set_tag;
-	tag_item->type = (enum rte_flow_item_type)
-				MLX5_RTE_FLOW_ITEM_TYPE_TAG;
 	tag_item->spec = tag_item_spec;
 	tag_item->last = NULL;
@@ -6112,4 +6114,17 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
 }
 
+static int
+flow_count_vlan_items(const struct rte_flow_item items[])
+{
+	int items_n = 0;
+
+	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
+		if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
+		    items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
+			items_n++;
+	}
+	return items_n;
+}
+
 /**
  * The splitting for meter feature.
@@ -6167,4 +6182,5 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 	size_t item_size;
 	int actions_n = 0;
+	int vlan_items_n = 0;
 	int ret = 0;
 
@@ -6228,7 +6244,9 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 			    (actions_n + METER_PREFIX_ACTION)) +
 			   sizeof(struct mlx5_rte_flow_action_set_tag);
-		/* Suffix items: tag, vlan, port id, end. */
-#define METER_SUFFIX_ITEM 4
-		item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
+		/* Flow can have multiple VLAN items. Account for them in suffix items. */
+		vlan_items_n = flow_count_vlan_items(items);
+		/* Suffix items: tag, [vlans], port id, end. */
+#define METER_SUFFIX_ITEM 3
+		item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
 			    sizeof(struct mlx5_rte_flow_item_tag) * 2;
 		sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
-- 
2.43.2

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2024-03-08 13:47:49.795374787 +0000
+++ 0026-net-mlx5-fix-VLAN-handling-in-meter-split.patch	2024-03-08 13:47:49.032686705 +0000
@@ -1 +1 @@
-From 5d2301a222d77e7bac3a085aa17f8ef7a3af7ffe Mon Sep 17 00:00:00 2001
+From 03c7f0a177554bf65966aa0bcd88295f3ad915e2 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 5d2301a222d77e7bac3a085aa17f8ef7a3af7ffe ]
+
@@ -24 +25,0 @@
-Cc: stable at dpdk.org
@@ -33 +34 @@
-index c7d70b8c7b..f8943a60be 100644
+index 5d489c7f92..6399d93b93 100644
@@ -36 +37 @@
-@@ -5708,6 +5708,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5083,6 +5083,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -45 +46 @@
-@@ -5726,4 +5726,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5101,4 +5101,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -51 +52 @@
-@@ -5748,8 +5749,11 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5121,8 +5122,11 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -67 +68 @@
-@@ -5768,4 +5772,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5141,4 +5145,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -73 +74 @@
-@@ -5798,14 +5803,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5171,14 +5176,5 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -89 +90 @@
-@@ -5822,4 +5818,12 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5195,4 +5191,12 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -102 +103 @@
-@@ -5911,6 +5915,4 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
+@@ -5284,6 +5288,4 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
@@ -109 +110 @@
-@@ -6740,4 +6742,17 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
+@@ -6112,4 +6114,17 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
@@ -127 +128 @@
-@@ -6795,4 +6810,5 @@ flow_create_split_meter(struct rte_eth_dev *dev,
+@@ -6167,4 +6182,5 @@ flow_create_split_meter(struct rte_eth_dev *dev,
@@ -133 +134 @@
-@@ -6854,7 +6870,9 @@ flow_create_split_meter(struct rte_eth_dev *dev,
+@@ -6228,7 +6244,9 @@ flow_create_split_meter(struct rte_eth_dev *dev,



More information about the stable mailing list