Skip to contentSkip to conversation

net/mlx5e: IPsec, Fix RX mapped ID leak when adding a rule fails

PATCH In review Changyul Lee 3 participants 3 messages Nov 20 – Nov 24

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/mlx5e: IPsec, Fix RX mapped ID leak when adding a rule fails

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.

Release the ID on the error path under the same condition that maps it. This label is reached only after the mapping succeeded and stored the new ID in rx_mapped_id, so the copy that mlx5e_accel_ipsec_fs_modify() passes in never loses the ID of the original SA.

Fixes 91bafc638ed4 ("net/mlx5e: Handle IPsec offload for RX datapath in switchdev mode")

---
Changes in v2:
- Release the ID under the same condition that maps it, as suggested by Jianbo.

v1: https://lore.kernel.org/all/[email protected]/

Found with a static analysis tool we are developing.

Jianbo tested the same change 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:
https://lore.kernel.org/all/[email protected]/

On our side it is 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 | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +2 -0
index 5c69e89b13a7..1f0ed8ab75d5 100644
@@ -2163,6 +2163,8 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
 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:
 	kvfree(spec);
 err_alloc:

base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5

Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

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.

Quoted 7 lines

Release the ID on the error path under the same condition that maps it. This label is reached only after the mapping succeeded and stored the new ID in rx_mapped_id, so the copy that mlx5e_accel_ipsec_fs_modify() passes in never loses the ID of the original SA.

Fixes 91bafc638ed4 ("net/mlx5e: Handle IPsec offload for RX datapath in switchdev mode")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Changyul Lee
Quoted 49 lines · 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.

Release the ID on the error path under the same condition that maps it. This label is reached only after the mapping succeeded and stored the new ID in rx_mapped_id, so the copy that mlx5e_accel_ipsec_fs_modify() passes in never loses the ID of the original SA.

Fixes 91bafc638ed4 ("net/mlx5e: Handle IPsec offload for RX datapath in switchdev mode")

---
Changes in v2:
- Release the ID under the same condition that maps it, as suggested by Jianbo.

v1: https://lore.kernel.org/all/[email protected]/

Found with a static analysis tool we are developing.

Jianbo tested the same change 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:
https://lore.kernel.org/all/[email protected]/

On our side it is 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 | 2 ++
  1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +2 -0
index 5c69e89b13a7..1f0ed8ab75d5 100644
@@ -2163,6 +2163,8 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
  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:
  	kvfree(spec);
  err_alloc:
Quoted 1 line

base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5