From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2D5464568F; Tue, 23 Jul 2024 10:31:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4A40D40ED6; Tue, 23 Jul 2024 10:31:08 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2074.outbound.protection.outlook.com [40.107.243.74]) by mails.dpdk.org (Postfix) with ESMTP id 3311940A77 for ; Tue, 23 Jul 2024 10:16:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vX6uysEjBnSL1dfT5asEQBf1jFzVGohpNVtFjpm4vTcGkXFdeH57pXw2JbNASSnsESt9dDLc75kjIjdxk0vhXYho73b3NZkxItblIKdwkozs+VZ3kSWj0X9jGdho0DeLzvvH3dKm6BgEWwlgPy3kumdk/8rWWkFp0azSJzS+1VpKNhHojwg1vAkDhwmgjNDEOpPZyWglufBUoXt+DrFhbGjxQFF9CkKyxtz12xr8FBBWBFXn50kqFxe18DxGL9VZuGuGabNavs55TsYggw5WufTpKVPOyYeWZtUXErXSpFUABvH7eRUpvaU61p6QNbGPumeiCpcHiEubxCTpkdQmXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=PKJOa0J4SPzj+3ZtWBELvKv8rcImckPRQDdsx2NXXLs=; b=kI0VULc6PRcceW3IGkjzjCAdSlhmwxVAwsWa+lVSblZdenr9cmPlqIJAoeq4D+8H0GlYI+BmdRDd5E057QLiz1RI90GajS2g8e2lZLSJ4ejP89YD1DV3Pj2Dl/a9eFhQ+FEe8sYDNeLVI8fbVT0LLYBq8zuxfiWCtkBg3g/LvkzEggOddCkpQz8S42e/7AFdUnq6dTF1XeWyEvLGbRIvUQf9fvCKRC6Y2zPG8u/wqAgYI6fsUzTwTCGSo5QTAoTBBOWt2JtkLUVFjdbseMPYww73sd4b77ylYXaAomxygHq7BHcG1g7rl2sRkjLldBU5C5VxjbXWyqmTMaZTzxsnUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=PKJOa0J4SPzj+3ZtWBELvKv8rcImckPRQDdsx2NXXLs=; b=B9kQ5ibPUBcEXfK8+n5rbX+M04x5P+z0LRH2fapbqwsR+nj3Fp6Gc/NYPhd0cfCbjnHr5mq/6yM4TP7P2atysoGfNi/YadAuQVJ7STqzQd2qEt5pHLWH5l6uWe7sa0sHxtEXISmYhZ+kIJnWmxU8RJ0sBcAVBJJS4wVYle5a7+nTZNfabcTyQjseqBHL/DBpOjllxBND37ifQwQkiZNltWliBZ1spcpB0JaQGBZrhQJbO0jx76MOlJdHejwVAsGWFvQ5fG+r93s3MY8nNC0alR0yrIHSBhVJ6XRFThAM+k1U08LR1FINSKNnzBCDb+B9kcnY0DW0kVV0DbxbT80VwA== Received: from DS7PR06CA0041.namprd06.prod.outlook.com (2603:10b6:8:54::10) by DM4PR12MB6543.namprd12.prod.outlook.com (2603:10b6:8:8c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Tue, 23 Jul 2024 08:16:08 +0000 Received: from DS2PEPF0000343D.namprd02.prod.outlook.com (2603:10b6:8:54:cafe::2) by DS7PR06CA0041.outlook.office365.com (2603:10b6:8:54::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16 via Frontend Transport; Tue, 23 Jul 2024 08:16:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DS2PEPF0000343D.mail.protection.outlook.com (10.167.18.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Tue, 23 Jul 2024 08:16:07 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 23 Jul 2024 01:15:53 -0700 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.1544.4; Tue, 23 Jul 2024 01:15:50 -0700 From: Bing Zhao To: , , , CC: , , , "Maayan Kashani" Subject: [PATCH 2/4] net/mlx5: fix releasing order of compatible matcher Date: Tue, 23 Jul 2024 11:15:20 +0300 Message-ID: <20240723081522.1087433-3-bingz@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723081522.1087433-1-bingz@nvidia.com> References: <20240723081522.1087433-1-bingz@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343D:EE_|DM4PR12MB6543:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cdbc2a3-ba76-4043-20a4-08dcaaefb462 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?O3ixoDkVWR6X6z+Oj69v7Y/ar4Lh8XjQzI0MoWu47czGqo4FLaSGDUlUEbir?= =?us-ascii?Q?X4V9dh9FVPoLWDjPja9Hs6TicxCC34X7vjdORPut4oCSnAY74YPOf6p+KMOG?= =?us-ascii?Q?ZCJGemdUzugUqSUBXKW7eH2cAGJfCTlzLa6wEttv5M8+AGu0D5dIkkTdJj7/?= =?us-ascii?Q?HF2TIiOVM6Ac+3sORW00GtS02OhtakUz27qzCR1Ttu3TmVr4lzponAltiUoU?= =?us-ascii?Q?J6iR3ozmdJOHzPBH1+fQD+vfRBQAFWEaD0RG0MS7BCug+k0ycYZ2W22z19Ln?= =?us-ascii?Q?8bw6KNqH94rSeXGpOnkQgGKxI0gu9+dXNYGY3BZeZkVl9FXT7JWHV4mBibpx?= =?us-ascii?Q?tqLGsxoZaVf3SeNM6rkKgs9FR2XOiWgr76FONIJoypsjvX+r+5dUcjS3nR8M?= =?us-ascii?Q?U1h5jHRxsQocWLa2bmSLt7QDf68eo5iE/OpgBGWwA5w4uzoKMmV3mJsJNlXJ?= =?us-ascii?Q?UhwbX7g0elFGKsJsiMCG+Ru+sKIIR9oQeQttqCaeCE6CXFnFpGW2/YH7cr15?= =?us-ascii?Q?8ziTXikcNzIZ1z8jD2+u3qropyIBZIJ1xlsLlvEk7j8DYQ1f9pOx4+mtpvkL?= =?us-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-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2024 08:16:07.7972 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9cdbc2a3-ba76-4043-20a4-08dcaaefb462 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.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF0000343D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6543 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 The matchers are created and organized in groups, and the groups are managed by a hash list in shared object. The creation order: 1. If no group, create the group and register it into the hash list. And create the list to save matchers. 2. If no matcher is found, register the matcher and increase the reference count of group. 3. If the matcher exists and can be reused, increase the reference counts of its group and itself. When dereferencing a matcher, the orders should be reversed. 1. Dereference the matcher and release it when not being used. 2. Dereference the group and release it when not being used. When the last flow rule on some group was trying to be destroyed, the matcher resource would also be freed in group dereference stage. The `group` information should be saved locally to get rid of the UAF issue in both stages. Coverity issue: 426423 Fixes: b2845d51c748 ("net/mlx5: support FDB in non-template flow") Signed-off-by: Maayan Kashani Signed-off-by: Bing Zhao Acked-by: Dariusz Sosnowski --- drivers/net/mlx5/mlx5_flow_hw.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index d243b59b71..470919fe8a 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -13471,22 +13471,16 @@ static int flow_hw_unregister_matcher(struct rte_eth_dev *dev, struct mlx5_flow_dv_matcher *matcher) { - int ret; struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_flow_group *group = matcher->group; + int ret = 0; - if (matcher->matcher_object) { - ret = mlx5_hlist_unregister(priv->sh->groups, &matcher->group->entry); - if (ret) - goto error; - if (matcher->group) { - ret = mlx5_list_unregister(matcher->group->matchers, &matcher->entry); - if (ret) - goto error; - } + if (group) { + if (matcher->matcher_object) + ret |= mlx5_list_unregister(group->matchers, &matcher->entry); + ret |= mlx5_hlist_unregister(priv->sh->groups, &group->entry); } - return 0; -error: - return -EINVAL; + return ret; } static int flow_hw_register_matcher(struct rte_eth_dev *dev, -- 2.34.1