mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tariq Toukan <ttoukan.linux@gmail.com>
To: "Charles Han(韩春超)" <hanchunchao@inspur.com>,
	"przemyslaw.kitszel@intel.com" <przemyslaw.kitszel@intel.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"saeedm@nvidia.com" <saeedm@nvidia.com>,
	"leon@kernel.org" <leon@kernel.org>,
	"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"markzhang@nvidia.com" <markzhang@nvidia.com>,
	"mbloch@nvidia.com" <mbloch@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>
Subject: Re: [PATCH] net/mlx5: fix potential null dereference when enable shared FDB
Date: Thu, 3 Apr 2025 17:03:04 +0300	[thread overview]
Message-ID: <a23ccc3b-bb4d-4352-bd7e-ab0f3ef82585@gmail.com> (raw)
In-Reply-To: <526e6240c8964fefa80b4bc759c44c04@inspur.com>



On 03/04/2025 12:52, Charles Han(韩春超) wrote:
> -ENXIO indicates "No such device or address". I've found that in mlx5/core, if mlx5_get_flow_namespace() returns null, it basically returns -EOPNOTSUPP.
> 

Please do not top-post.

+1.
If namespace is not found it's due to lack of support.


> -----邮件原件-----
> 发件人: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> 发送时间: 2025年4月2日 19:02
> 收件人: Charles Han(韩春超) <hanchunchao@inspur.com>
> 抄送: netdev@vger.kernel.org; linux-rdma@vger.kernel.org; linux-kernel@vger.kernel.org; saeedm@nvidia.com; leon@kernel.org; tariqt@nvidia.com; andrew+netdev@lunn.ch; davem@davemloft.net; edumazet@google.com; kuba@kernel.org; pabeni@redhat.com; markzhang@nvidia.com; mbloch@nvidia.com
> 主题: Re: [PATCH] net/mlx5: fix potential null dereference when enable shared FDB
> 
> On 4/2/25 11:43, Charles Han wrote:
>> mlx5_get_flow_namespace() may return a NULL pointer, dereferencing it
>> without NULL check may lead to NULL dereference.
>> Add a NULL check for ns.
>>
>> Fixes: db202995f503 ("net/mlx5: E-Switch, add logic to enable shared
>> FDB")
>> Signed-off-by: Charles Han <hanchunchao@inspur.com>

Acked-by: Tariq Toukan <tariqt@nvidia.com>

>> ---
>>    .../net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 10 ++++++++++
>>    drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c       |  5 +++++
>>    2 files changed, 15 insertions(+)
>>
>> diff --git
>> a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>> b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>> index a6a8eea5980c..dc58e4c2d786 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>> @@ -2667,6 +2667,11 @@ static int esw_set_slave_root_fdb(struct mlx5_core_dev *master,
>>    	if (master) {
>>    		ns = mlx5_get_flow_namespace(master,
>>    					     MLX5_FLOW_NAMESPACE_FDB);
>> +		if (!ns) {
>> +			mlx5_core_warn(master, "Failed to get flow namespace\n");
>> +			return -EOPNOTSUPP;
> 
> I would return -ENXIO in such cases, you were searching and not found that.
> 
> IOW it is obvious that dereferencing a null ptr is not supported.
> 
> If you agree, please apply the same comment for your other patch:
> https://lore.kernel.org/netdev/20250402093221.3253-1-hanchunchao@inspur.com/T/#u
> 
>> +		}
>> +
>>    		root = find_root(&ns->node);
>>    		mutex_lock(&root->chain_lock);
>>    		MLX5_SET(set_flow_table_root_in, in, @@ -2679,6 +2684,11 @@ static
>> int esw_set_slave_root_fdb(struct mlx5_core_dev *master,
>>    	} else {
>>    		ns = mlx5_get_flow_namespace(slave,
>>    					     MLX5_FLOW_NAMESPACE_FDB);
>> +		if (!ns) {
>> +			mlx5_core_warn(slave, "Failed to get flow namespace\n");
>> +			return -EOPNOTSUPP;
>> +		}
>> +
>>    		root = find_root(&ns->node);
>>    		mutex_lock(&root->chain_lock);
>>    		MLX5_SET(set_flow_table_root_in, in, table_id, diff --git
>> a/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
>> b/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
>> index a47c29571f64..18e59f6a0f2d 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
>> @@ -186,6 +186,11 @@ static int mlx5_cmd_set_slave_root_fdb(struct mlx5_core_dev *master,
>>    	} else {
>>    		ns = mlx5_get_flow_namespace(slave,
>>    					     MLX5_FLOW_NAMESPACE_FDB);
>> +		if (!ns) {
>> +			mlx5_core_warn(slave, "Failed to get flow namespace\n");
>> +			return -EOPNOTSUPP;
>> +		}
>> +
>>    		root = find_root(&ns->node);
>>    		MLX5_SET(set_flow_table_root_in, in, table_id,
>>    			 root->root_ft->id);
> 


  reply	other threads:[~2025-04-03 14:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03  9:52 Charles Han(韩春超)
2025-04-03 14:03 ` Tariq Toukan [this message]
2025-04-03 18:32   ` Tariq Toukan
2025-04-07  6:47     ` [PATCH V2] " Charles Han
2025-04-07  9:28       ` Tariq Toukan
  -- strict thread matches above, loose matches on Subject: below --
2025-04-02  9:43 [PATCH] " Charles Han
2025-04-02 11:01 ` Przemek Kitszel

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=a23ccc3b-bb4d-4352-bd7e-ab0f3ef82585@gmail.com \
    --to=ttoukan.linux@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hanchunchao@inspur.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=markzhang@nvidia.com \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@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

all inboxes | Powered by JetHome®