net/mlx5e: fix double free of encap_header
Subsystems (4)
PATCH 1/1 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.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +4 -6
@@ -300,9 +300,6 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,if (err) goto destroy_neigh_entry; - e->encap_size = ipv4_encap_size; - e->encap_header = encap_header; -if (!(nud_state &NUD_VALID )) {neigh_event_send (attr.n,NULL );/* 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, goto destroy_neigh_entry; } + e->encap_size = ipv4_encap_size; + e->encap_header = encap_header; e->flags |=MLX5_ENCAP_ENTRY_VALID ;mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev));mlx5e_route_lookup_ipv4_put (&attr);
@@ -568,9 +567,6 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,if (err) goto destroy_neigh_entry; - e->encap_size = ipv6_encap_size; - e->encap_header = encap_header; -if (!(nud_state &NUD_VALID )) {neigh_event_send (attr.n,NULL );/* 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, goto destroy_neigh_entry; } + e->encap_size = ipv6_encap_size; + e->encap_header = encap_header; e->flags |=MLX5_ENCAP_ENTRY_VALID ;mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev));mlx5e_route_lookup_ipv6_put (&attr);
Signature · 1 line
2.19.1.6.gb485710b
Quoted 10 lines · Dust Li
When
mlx5_packet_reformat_alloc()fails, theencap_headerallocated in mlx5e_tc_tun_create_header_ipv4{6} will be released within it. However,e->encap_headeris already set to the previously freedencap_headerbeforemlx5_packet_reformat_alloc(). As a result, the latermlx5e_encap_put()will freee->encap_headeragain, causing a double free issue.
mlx5e_encap_put()--> mlx5e_encap_dealloc() --> kfree(e->encap_header)
nit: I think it should mlx5e_encap_put_locked not mlx5e_encap_put to be precise.
Quoted 11 lines
This happens when cmd:
MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXTfail.This patch fix it by not setting
e->encap_headeruntilmlx5_packet_reformat_alloc()success.Fixes d589e785baf5e("net/mlx5e: Allow concurrent creation of encap entries")Reported-by Cruz Zhao <[email protected]>Reported-by Tianchen Ding <[email protected]>Signed-off-by Dust Li <[email protected]>---
Quoted 45 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +4
-6@@ -300,9 +300,6 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,if (err) goto destroy_neigh_entry; - e->encap_size = ipv4_encap_size; - e->encap_header = encap_header; -if (!(nud_state &NUD_VALID )) {neigh_event_send (attr.n,NULL );/* 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, goto destroy_neigh_entry; } + e->encap_size = ipv4_encap_size; + e->encap_header = encap_header; e->flags |=MLX5_ENCAP_ENTRY_VALID ;mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev));mlx5e_route_lookup_ipv4_put (&attr);@@ -568,9 +567,6 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,if (err) goto destroy_neigh_entry; - e->encap_size = ipv6_encap_size; - e->encap_header = encap_header; -if (!(nud_state &NUD_VALID )) {neigh_event_send (attr.n,NULL );/* 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, goto destroy_neigh_entry; } + e->encap_size = ipv6_encap_size; + e->encap_header = encap_header; e->flags |=MLX5_ENCAP_ENTRY_VALID ;mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev));mlx5e_route_lookup_ipv6_put (&attr);
Quoted 10 lines · Wojciech Drewek
Quoted 7 lines · Dust Li
When
mlx5_packet_reformat_alloc()fails, theencap_headerallocated in mlx5e_tc_tun_create_header_ipv4{6} will be released within it. However,e->encap_headeris already set to the previously freedencap_headerbeforemlx5_packet_reformat_alloc(). As a result, the latermlx5e_encap_put()will freee->encap_headeragain, causing a double free issue.
Quoted 5 lines
Quoted 3 lines
mlx5e_encap_put()--> mlx5e_encap_dealloc() --> kfree(e->encap_header)nit: I think it should
mlx5e_encap_put_lockednotmlx5e_encap_putto be precise.
You are right.
The original version is mlx5e_encap_put, I mistakenly used the name of the old version when doing git blame.
Best regards,
Dust
Quoted 60 lines
Quoted 4 lines
This happens when cmd:
MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXTfail.Quoted 8 lines
This patch fix it by not setting
e->encap_headeruntilmlx5_packet_reformat_alloc()success.Fixes d589e785baf5e("net/mlx5e: Allow concurrent creation of encap entries")Reported-by Cruz Zhao <[email protected]>Reported-by Tianchen Ding <[email protected]>Signed-off-by Dust Li <[email protected]>---
Reviewed-by Wojciech Drewek <[email protected]>Quoted 45 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +4
-6@@ -300,9 +300,6 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,if (err) goto destroy_neigh_entry; - e->encap_size = ipv4_encap_size; - e->encap_header = encap_header; -if (!(nud_state &NUD_VALID )) {neigh_event_send (attr.n,NULL );/* 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, goto destroy_neigh_entry; } + e->encap_size = ipv4_encap_size; + e->encap_header = encap_header; e->flags |=MLX5_ENCAP_ENTRY_VALID ;mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev));mlx5e_route_lookup_ipv4_put (&attr);@@ -568,9 +567,6 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,if (err) goto destroy_neigh_entry; - e->encap_size = ipv6_encap_size; - e->encap_header = encap_header; -if (!(nud_state &NUD_VALID )) {neigh_event_send (attr.n,NULL );/* 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, goto destroy_neigh_entry; } + e->encap_size = ipv6_encap_size; + e->encap_header = encap_header; e->flags |=MLX5_ENCAP_ENTRY_VALID ;mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev));mlx5e_route_lookup_ipv6_put (&attr);
Saeed Mahameed
AppliedQuoted 13 lines · Dust Li
When
mlx5_packet_reformat_alloc()fails, theencap_headerallocated in mlx5e_tc_tun_create_header_ipv4{6} will be released within it. However,e->encap_headeris already set to the previously freedencap_headerbeforemlx5_packet_reformat_alloc(). As a result, the latermlx5e_encap_put()will freee->encap_headeragain, 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_CONTEXTfail.
Quoted 7 lines
This patch fix it by not setting
e->encap_headeruntilmlx5_packet_reformat_alloc()success.Fixes d589e785baf5e("net/mlx5e: Allow concurrent creation of encap entries")Reported-by Cruz Zhao <[email protected]>Reported-by Tianchen Ding <[email protected]>Signed-off-by Dust Li <[email protected]>
Applied to net-mlx5