DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <dsosnowski@nvidia.com>, <viacheslavo@nvidia.com>, <dev@dpdk.org>,
	<rasland@nvidia.com>
Cc: <orika@nvidia.com>, <suanmingm@nvidia.com>, <matan@nvidia.com>,
	"Maayan Kashani" <mkashani@nvidia.com>
Subject: [PATCH 2/4] net/mlx5: fix releasing order of compatible matcher
Date: Tue, 23 Jul 2024 11:15:20 +0300	[thread overview]
Message-ID: <20240723081522.1087433-3-bingz@nvidia.com> (raw)
In-Reply-To: <20240723081522.1087433-1-bingz@nvidia.com>

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 <mkashani@nvidia.com>
Signed-off-by: Bing Zhao <bingz@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
 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


  parent reply	other threads:[~2024-07-23  8:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23  8:15 [PATCH 0/4] non-template fixes set Bing Zhao
2024-07-23  8:15 ` [PATCH 1/4] net/mlx5/hws: fix state detection of queue full in polling Bing Zhao
2024-07-23  8:15 ` Bing Zhao [this message]
2024-07-23  8:15 ` [PATCH 3/4] net/mlx5: fix matcher mask translation Bing Zhao
2024-07-23  8:15 ` [PATCH 4/4] net/mlx5: fix log error on non-template rule destroy Bing Zhao
2024-08-29  8:59 ` [PATCH 0/4] non-template fixes set Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240723081522.1087433-3-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=mkashani@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).