From patchwork Tue Feb 27 13:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dariusz Sosnowski X-Patchwork-Id: 137355 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D955543C06; Tue, 27 Feb 2024 14:58:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6671740295; Tue, 27 Feb 2024 14:58:55 +0100 (CET) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2072.outbound.protection.outlook.com [40.107.101.72]) by mails.dpdk.org (Postfix) with ESMTP id 687D24027D; Tue, 27 Feb 2024 14:58:53 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B8XMu1zEZKOYpSVfbcWq1VQ/WmypN5if78DEo5GJqQWTdEDe0C9tMPzHuBYgm6RbQV0cLWYqV15aI1oX3HCs9poAmu+H3TTNmPBmbzyyPuTC5K9Y70AVJ/aMbt3C974xU8GJuWMpA+7CsuuKWGkXUrArgOkEunbK1uPG56tQJXO5AOQsZ5jKiCkDUSitjuZguTnA4+gnRwqCCH5zNXRZlLiyJsD5T65szhf96xC5Y2wq9G6ziX5kQn2xq1EM06Y/owT7irC873+lvJ3wlR8gnPLrS39yci788EHx+t6fxbqWrv9C+wZnwikStAcstKPSvkYPyzpdXqzdVweLxt4gXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L4YxEO8TA20NxuWgeL+EKfjTCS51qril5pBb9c3WTes=; b=CAlV3syWzR/MTKKukQslqGu9KjR3FIbBX1tHVlTGxeIiBsnNzrxw7EjoCI5PApKLPpqRXEF8kQUhor1TyNBCxCAhfOiHFC4RwkaF1IqVEP+gW2J8VmFPQJznopSdFz1xApILxolg2cYbUvPqToHxDJSMxVGkvE9xbziEX0tcf9eqRwEdCh7ft5iRTNWR6TNmifNRA/8ygRobXB2HJKfzj+OsEBmhZ2vRHugCGYd9fBrIuzV3CO3vO0kK/HROMARnQl/ECJdlJCyQJcWFPawydd1tE/P4Xkhwi6SsPOWvp5tTzXJYskfhT/TbkxE+MgkIvlw5m4Rrm1o8yasZUypjJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L4YxEO8TA20NxuWgeL+EKfjTCS51qril5pBb9c3WTes=; b=B8xuqDil0jbvJjDtbnJKMJHa6amki5BOMEYNPyvHpIL8tAKn+7B3buU7WhELQH+Zi6CXuw7Bb+bum4Ll2kjSLgubQ3tT7pINPE65pF3psqeDDzNgR6JuK4ymdlyXU56qyJ9y3iXnZ8Ni7ahCi9/AibGMdJ6XPOBEvbb10cxjITJLdC+6dp+DHrCtVIoik6OVgckJAm4ZZ7Q6yyWIGUwFr9B4SnDJlCU9tseSwsXuSY9hnu9WQD98PS4NQO7lbiDW+/nmOXjcXhcC2X32IzFHgwM75NGs/aZ5yNLzhUwKigOlME6dM+LPGQHC/gAHXBLsl2A9UGxOPaAkyebL41zcPg== Received: from MW4PR03CA0147.namprd03.prod.outlook.com (2603:10b6:303:8c::32) by BL1PR12MB5174.namprd12.prod.outlook.com (2603:10b6:208:31c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Tue, 27 Feb 2024 13:58:50 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:303:8c:cafe::41) by MW4PR03CA0147.outlook.office365.com (2603:10b6:303:8c::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.50 via Frontend Transport; Tue, 27 Feb 2024 13:58:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 27 Feb 2024 13:58:50 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 27 Feb 2024 05:58:31 -0800 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Tue, 27 Feb 2024 05:58:28 -0800 From: Dariusz Sosnowski To: Viacheslav Ovsiienko , Ori Kam , Suanming Mou , Matan Azrad CC: , Subject: [PATCH v2] net/mlx5: fix VLAN handling in meter split Date: Tue, 27 Feb 2024 14:58:15 +0100 Message-ID: <20240227135816.135279-1-dsosnowski@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240227111848.123687-1-dsosnowski@nvidia.com> References: <20240227111848.123687-1-dsosnowski@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F5:EE_|BL1PR12MB5174:EE_ X-MS-Office365-Filtering-Correlation-Id: df96c527-23d8-425f-151a-08dc379c39c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m5msI0joUbryqDAwOnlOY4t/q2K5AjOseA2ts6N0iU+oa5qxsxEjx0cYPxWWG+WBNhOcDJFzgZ+Ckvk+sLmZWddn+1ZQhttthYGKyWBrROPTi3f/gQuUxitVGtIDmIT+3LN8DfQK9+/d+qR2cFdne6IJOvK5dSACg9lFw/FUP18hKEbKQ+4ujtHpP7tGPt7WlJkZ4zdRs+Na9QjyhHFahj/jDh6Kaiygq2tgB455s1Jvh9EsJ9zZDmYNX2XbsdJQEinhMjS77fW5MeVD48NuPNTCawrS4I1mTcNCPX9ZepeqA0g35hSHFOoqIuHZnO9BBu/GhiXHwO7qhn0sQKs9fGo5QcAmhiGlpkYl3muant4fQsNBvEV1/YcV/lr6NxN9wAp6WFtp/BAHM0N+noQzWdNfcqEIu1imu0I15QfGQBRHBXKKmshmSBnCuy0t3zLmzkwns4EPiBDJgtvlF/JOqQ+96nO+bln4VdWAwFyYe4nrFtp4r2OZc9L4dPGt/sAOwi+Rv8PJ7XDMIprHLO02/BDhdcQ6OurRRxWvsWIL+rD/9yHZPetT7IH9WhdR7T3RD3VnXl8myljHasg+rSIlow52PWTroUS0VLOIMobfiDnL5lceWuWJ9vVSdo49t+Q9h3c89+6iuZPOhL8emSipmBcHWIXjvhbV/LTyEv7BS7Z+0eqoMn+/d3WVg83za+BfeZL/S9jB8mjUqhgzQOmPjf8y5MyPQdkaaxo+bop9cAJmfh/eU6v4BudrY6LMZK3B X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(82310400014)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2024 13:58:50.1183 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df96c527-23d8-425f-151a-08dc379c39c2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5174 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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") Cc: suanmingm@nvidia.com Cc: stable@dpdk.org Signed-off-by: Dariusz Sosnowski Acked-by: Suanming Mou --- v2: - Rebased. drivers/net/mlx5/mlx5_flow.c | 60 +++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 21 deletions(-) -- 2.39.2 diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 3e179110a0..cdf413541e 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -5707,8 +5707,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, struct mlx5_rte_flow_item_tag *tag_item_spec; 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; struct rte_flow_action *action_pre_head = NULL; @@ -5725,6 +5725,7 @@ 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; @@ -5747,10 +5748,13 @@ flow_meter_split_prep(struct rte_eth_dev *dev, sfx_items++; 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: break; @@ -5767,6 +5771,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, tag_action = actions_pre++; } /* 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; @@ -5797,16 +5802,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev, break; 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: if (fm->def_policy) @@ -5821,6 +5817,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev, actions_sfx++ : actions_pre++; 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; if (priv->sh->meter_aso_en) { @@ -5910,8 +5914,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev, tag_action->type = (enum rte_flow_action_type) 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; tag_item->mask = tag_item_mask; @@ -6739,6 +6741,19 @@ flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev, &drop_split_info, error); } +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. * @@ -6794,6 +6809,7 @@ flow_create_split_meter(struct rte_eth_dev *dev, size_t act_size; size_t item_size; int actions_n = 0; + int vlan_items_n = 0; int ret = 0; if (priv->mtr_en) @@ -6853,9 +6869,11 @@ flow_create_split_meter(struct rte_eth_dev *dev, act_size = (sizeof(struct rte_flow_action) * (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), 0, SOCKET_ID_ANY);