Skip to content

Commit 6f9b1a0

Browse files
Dust Likuba-moo
authored andcommitted
net/mlx5e: fix double free of encap_header
When mlx5_packet_reformat_alloc() fails, the encap_header allocated in mlx5e_tc_tun_create_header_ipv4{6} will be released within it. However, e->encap_header is already set to the previously freed encap_header before mlx5_packet_reformat_alloc(). As a result, the later mlx5e_encap_put() will free e->encap_header again, causing a double free issue. mlx5e_encap_put() --> mlx5e_encap_dealloc() --> kfree(e->encap_header) This happens when cmd: MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT fail. This patch fix it by not setting e->encap_header until mlx5_packet_reformat_alloc() success. Fixes: d589e78 ("net/mlx5e: Allow concurrent creation of encap entries") Reported-by: Cruz Zhao <cruzzhao@linux.alibaba.com> Reported-by: Tianchen Ding <dtcccc@linux.alibaba.com> Signed-off-by: Dust Li <dust.li@linux.alibaba.com> Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent fd64fd1 commit 6f9b1a0

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

  • drivers/net/ethernet/mellanox/mlx5/core/en

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
300300
if (err)
301301
goto destroy_neigh_entry;
302302

303-
e->encap_size = ipv4_encap_size;
304-
e->encap_header = encap_header;
305-
306303
if (!(nud_state & NUD_VALID)) {
307304
neigh_event_send(attr.n, NULL);
308305
/* the encap entry will be made valid on neigh update event
@@ -322,6 +319,8 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
322319
goto destroy_neigh_entry;
323320
}
324321

322+
e->encap_size = ipv4_encap_size;
323+
e->encap_header = encap_header;
325324
e->flags |= MLX5_ENCAP_ENTRY_VALID;
326325
mlx5e_rep_queue_neigh_stats_work(netdev_priv(attr.out_dev));
327326
mlx5e_route_lookup_ipv4_put(&attr);
@@ -568,9 +567,6 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
568567
if (err)
569568
goto destroy_neigh_entry;
570569

571-
e->encap_size = ipv6_encap_size;
572-
e->encap_header = encap_header;
573-
574570
if (!(nud_state & NUD_VALID)) {
575571
neigh_event_send(attr.n, NULL);
576572
/* the encap entry will be made valid on neigh update event
@@ -590,6 +586,8 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
590586
goto destroy_neigh_entry;
591587
}
592588

589+
e->encap_size = ipv6_encap_size;
590+
e->encap_header = encap_header;
593591
e->flags |= MLX5_ENCAP_ENTRY_VALID;
594592
mlx5e_rep_queue_neigh_stats_work(netdev_priv(attr.out_dev));
595593
mlx5e_route_lookup_ipv6_put(&attr);

0 commit comments

Comments
 (0)