All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Dewar <alex.dewar90@gmail.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Alex Dewar <alex.dewar90@gmail.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Roi Dayan <roid@mellanox.com>,
	Oz Shlomo <ozsh@mellanox.com>, Paul Blakey <paulb@mellanox.com>,
	Eli Britstein <elibr@mellanox.com>,
	Ariel Levkovich <lariel@nvidia.com>,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] net/mlx5e: Fix use of freed pointer
Date: Tue, 29 Sep 2020 11:15:49 +0100	[thread overview]
Message-ID: <20200929101554.8963-1-alex.dewar90@gmail.com> (raw)
In-Reply-To: <20200928074301.GC3094@unreal>

If the call to mlx5_fc_create() fails, then shared_counter will be freed
before its member, shared_counter->counter, is accessed to retrieve the
error code. Fix by using an intermediate variable.

Addresses-Coverity: CID 1497153: Memory - illegal accesses (USE_AFTER_FREE)
Fixes: 1edae2335adf ("net/mlx5e: CT: Use the same counter for both directions")
Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
v2:
	- Add Fixes tag (Leon)
	- Use ERR_CAST (Leon)

Hi Leon,

I've made the suggested changes. Let me know if there's anything else
you need :)

There is also this patch in the series which doesn't seem to have been
reviewed yet: https://lore.kernel.org/lkml/20200927113254.362480-4-alex.dewar90@gmail.com/

Best,
Alex


 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
index b5f8ed30047b..1e80e7669995 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
@@ -738,6 +738,7 @@ mlx5_tc_ct_shared_counter_get(struct mlx5_tc_ct_priv *ct_priv,
 	struct mlx5_ct_shared_counter *shared_counter;
 	struct mlx5_core_dev *dev = ct_priv->dev;
 	struct mlx5_ct_entry *rev_entry;
+	struct mlx5_fc *counter;
 	__be16 tmp_port;
 
 	/* get the reversed tuple */
@@ -775,12 +776,13 @@ mlx5_tc_ct_shared_counter_get(struct mlx5_tc_ct_priv *ct_priv,
 	if (!shared_counter)
 		return ERR_PTR(-ENOMEM);
 
-	shared_counter->counter = mlx5_fc_create(dev, true);
-	if (IS_ERR(shared_counter->counter)) {
+	counter = mlx5_fc_create(dev, true);
+	if (IS_ERR(counter)) {
 		ct_dbg("Failed to create counter for ct entry");
 		kfree(shared_counter);
-		return ERR_PTR(PTR_ERR(shared_counter->counter));
+		return ERR_CAST(counter);
 	}
+	shared_counter->counter = counter;
 
 	refcount_set(&shared_counter->refcount, 1);
 	return shared_counter;
-- 
2.28.0


  reply	other threads:[~2020-09-29 10:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-27 11:32 [PATCH 0/3] net/mlx5e: Fix some static analysis warnings Alex Dewar
2020-09-27 11:32 ` [PATCH 2/3] net/mlx5e: Clean up error handling in mlx5e_alloc_flow() Alex Dewar
2020-09-28  7:39   ` Leon Romanovsky
2020-09-27 11:32 ` [PATCH 3/3] net/mlx5e: Fix use of freed pointer Alex Dewar
2020-09-28  7:43   ` Leon Romanovsky
2020-09-29 10:15     ` Alex Dewar [this message]
2020-09-29 12:37       ` [PATCH v2] " Leon Romanovsky
2020-09-27 11:32 ` [PATCH 1/3] net/mlx5e: Fix possible null pointer dereference Alex Dewar

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=20200929101554.8963-1-alex.dewar90@gmail.com \
    --to=alex.dewar90@gmail.com \
    --cc=davem@davemloft.net \
    --cc=elibr@mellanox.com \
    --cc=kuba@kernel.org \
    --cc=lariel@nvidia.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ozsh@mellanox.com \
    --cc=paulb@mellanox.com \
    --cc=roid@mellanox.com \
    --cc=saeedm@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.