Skip to content

Commit 3e45dd1

Browse files
Jianbo Liugregkh
authored andcommitted
net/mlx5e: Skip restore TC rules for vport rep without loaded flag
[ Upstream commit 5a03b36 ] During driver unload, unregister_netdev is called after unloading vport rep. So, the mlx5e_rep_priv is already freed while trying to get rpriv->netdev, or walk rpriv->tc_ht, which results in use-after-free. So add the checking to make sure access the data of vport rep which is still loaded. Fixes: d156953 ("net/mlx5e: Modify and restore TC rules for IPSec TX rules") Signed-off-by: Jianbo Liu <jianbol@nvidia.com> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20241220081505.1286093-4-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e66a99b commit 3e45dd1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ void mlx5_esw_ipsec_restore_dest_uplink(struct mlx5_core_dev *mdev)
150150
unsigned long i;
151151
int err;
152152

153-
xa_for_each(&esw->offloads.vport_reps, i, rep) {
154-
rpriv = rep->rep_data[REP_ETH].priv;
155-
if (!rpriv || !rpriv->netdev)
153+
mlx5_esw_for_each_rep(esw, i, rep) {
154+
if (atomic_read(&rep->rep_data[REP_ETH].state) != REP_LOADED)
156155
continue;
157156

157+
rpriv = rep->rep_data[REP_ETH].priv;
158158
rhashtable_walk_enter(&rpriv->tc_ht, &iter);
159159
rhashtable_walk_start(&iter);
160160
while ((flow = rhashtable_walk_next(&iter)) != NULL) {

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
713713
MLX5_CAP_GEN_2((esw->dev), ec_vf_vport_base) +\
714714
(last) - 1)
715715

716+
#define mlx5_esw_for_each_rep(esw, i, rep) \
717+
xa_for_each(&((esw)->offloads.vport_reps), i, rep)
718+
716719
struct mlx5_eswitch *__must_check
717720
mlx5_devlink_eswitch_get(struct devlink *devlink);
718721

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
#include "lag/lag.h"
5353
#include "en/tc/post_meter.h"
5454

55-
#define mlx5_esw_for_each_rep(esw, i, rep) \
56-
xa_for_each(&((esw)->offloads.vport_reps), i, rep)
57-
5855
/* There are two match-all miss flows, one for unicast dst mac and
5956
* one for multicast.
6057
*/

0 commit comments

Comments
 (0)