* [PATCH net] net/mlx5e: IPsec, Fix RX mapped ID leak when adding a rule fails
@ 2026-11-18 5:12 Changyul Lee
2026-11-18 9:49 ` Jianbo Liu
0 siblings, 1 reply; 2+ messages in thread
From: Changyul Lee @ 2026-11-18 5:12 UTC (permalink / raw)
To: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Jianbo Liu, netdev, linux-rdma, linux-kernel,
Changyul Lee
In switchdev mode, rx_add_rule() calls
mlx5_esw_ipsec_rx_setup_modify_header(), which allocates a mapped ID for
the SA in ipsec->ipsec_obj_id_map. If a later step fails, the error path
frees the modify header but leaves the ID in the XArray, and
mlx5e_xfrm_add_state() then frees the SA entry. Each failed inbound
packet offload SA leaks one of the 2047 IDs. Once they are used up, no
new inbound SA can be offloaded until the IPsec context is cleaned up.
Remove the mapping where the modify header is freed, as
mlx5e_accel_ipsec_fs_del_rule() does. The modify header is set only after
a new ID was allocated, so the copy that mlx5e_accel_ipsec_fs_modify()
passes in never loses the ID of the original SA. Outside switchdev mode
rx_mapped_id is 0 and the call does nothing.
Fixes: 91bafc638ed4 ("net/mlx5e: Handle IPsec offload for RX datapath in switchdev mode")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus MLX5_CORE_EN, MLX5_ESWITCH,
MLX5_EN_IPSEC and W=1.
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
index 5c69e89b13a7..ef858374ae11 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
@@ -2161,8 +2161,10 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
if (flow_act.pkt_reformat)
mlx5_packet_reformat_dealloc(mdev, flow_act.pkt_reformat);
err_pkt_reformat:
- if (flow_act.modify_hdr)
+ if (flow_act.modify_hdr) {
mlx5_modify_header_dealloc(mdev, flow_act.modify_hdr);
+ mlx5_esw_ipsec_rx_id_mapping_remove(sa_entry);
+ }
err_mod_header:
kvfree(spec);
err_alloc:
base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH net] net/mlx5e: IPsec, Fix RX mapped ID leak when adding a rule fails
2026-11-18 5:12 [PATCH net] net/mlx5e: IPsec, Fix RX mapped ID leak when adding a rule fails Changyul Lee
@ 2026-11-18 9:49 ` Jianbo Liu
0 siblings, 0 replies; 2+ messages in thread
From: Jianbo Liu @ 2026-11-18 9:49 UTC (permalink / raw)
To: Changyul Lee, Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-rdma, linux-kernel
On 11/18/2026 1:12 PM, Changyul Lee wrote:
> In switchdev mode, rx_add_rule() calls
> mlx5_esw_ipsec_rx_setup_modify_header(), which allocates a mapped ID for
> the SA in ipsec->ipsec_obj_id_map. If a later step fails, the error path
> frees the modify header but leaves the ID in the XArray, and
> mlx5e_xfrm_add_state() then frees the SA entry. Each failed inbound
> packet offload SA leaks one of the 2047 IDs. Once they are used up, no
> new inbound SA can be offloaded until the IPsec context is cleaned up.
Thanks for the patch. The leak is real.
[...]
> @@ -2161,8 +2161,10 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
> if (flow_act.pkt_reformat)
> mlx5_packet_reformat_dealloc(mdev, flow_act.pkt_reformat);
> err_pkt_reformat:
> - if (flow_act.modify_hdr)
> + if (flow_act.modify_hdr) {
> mlx5_modify_header_dealloc(mdev, flow_act.modify_hdr);
> + mlx5_esw_ipsec_rx_id_mapping_remove(sa_entry);
> + }
> err_mod_header:
We have a fix for this in our queue. It releases the ID under the same
condition that maps it, so the eswitch helper is only called for an SA
on the eswitch tables:
err_pkt_reformat:
if (flow_act.modify_hdr)
mlx5_modify_header_dealloc(mdev, flow_act.modify_hdr);
+ if (!attrs->drop && rx == ipsec->rx_esw)
+ mlx5_esw_ipsec_rx_id_mapping_remove(sa_entry);
err_mod_header:
I prefer this form. Do you want to send a v2 with it? Then I will add
my Reviewed-by. If not, we will send our patch ourselves.
We tested it on ConnectX-7 in switchdev mode with fault injection on
one RX SA add: 46 of the 2047 IDs were lost without the fix, none with
it.
Thanks,
Jianbo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 9:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 5:12 [PATCH net] net/mlx5e: IPsec, Fix RX mapped ID leak when adding a rule fails Changyul Lee
2026-11-18 9:49 ` Jianbo Liu
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®