Skip to contentSkip to conversation

RDMA/mlx5: Guard steering anchor resource destruction on create error

PATCH Applied lirongqing 3 participants 3 messages Sep 17 – Sep 23

Subsystems (2)
lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 RDMA/mlx5: Guard steering anchor resource destruction on create error

From: Li RongQing <[email protected]>

The steering anchor resources are shared between anchors with the same priority and are protected by rule_goto_table_ref.

When steering anchor creation succeeds but uverbs_copy_to() fails, the error path drops the reference acquired for the new anchor. However, it unconditionally calls mlx5_steering_anchor_destroy_res(), even when other anchors are still using the shared resources.

This can destroy the shared flow table, flow groups, and rules while existing anchors still hold references to them, resulting in a use-after-free when those anchors are subsequently cleaned up.

Only destroy the shared resources when dropping the reference makes rule_goto_table_ref zero, consistent with the existing cleanup path.

Fixes e1f4a52ac171 ("RDMA/mlx5: Create an indirect flow table for steering anchor")
---
 drivers/infiniband/hw/mlx5/fs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/fs.c +2 -2
index e27826c..034ab55 100644
@@ -3056,8 +3056,8 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_STEERING_ANCHOR_CREATE)(
 	return 0;
 
 destroy_res:
-	--ft_prio->anchor.rule_goto_table_ref;
-	mlx5_steering_anchor_destroy_res(ft_prio);
+	if (!--ft_prio->anchor.rule_goto_table_ref)
+		mlx5_steering_anchor_destroy_res(ft_prio);
 put_flow_table:
 	put_flow_table(dev, ft_prio, true);
 free_obj:
Signature · 1 line
2.9.4
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

From: Li RongQing <[email protected]>

The steering anchor resources are shared between anchors with the same priority and are protected by rule_goto_table_ref.

When steering anchor creation succeeds but uverbs_copy_to() fails, the error path drops the reference acquired for the new anchor. However, it unconditionally calls mlx5_steering_anchor_destroy_res(), even when other anchors are still using the shared resources.

This can destroy the shared flow table, flow groups, and rules while existing anchors still hold references to them, resulting in a use-after-free when those anchors are subsequently cleaned up.

Quoted 5 lines

Only destroy the shared resources when dropping the reference makes rule_goto_table_ref zero, consistent with the existing cleanup path.

Fixes e1f4a52ac171 ("RDMA/mlx5: Create an indirect flow table for steering anchor")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to lirongqing
Quoted 9 lines · lirongqing

The steering anchor resources are shared between anchors with the same priority and are protected by rule_goto_table_ref.

When steering anchor creation succeeds but uverbs_copy_to() fails, the error path drops the reference acquired for the new anchor. However, it unconditionally calls mlx5_steering_anchor_destroy_res(), even when other anchors are still using the shared resources.

[...]

Applied, thanks!

[1/1] RDMA/mlx5: Guard steering anchor resource destruction on create error

      https://git.kernel.org/rdma/rdma/c/193aaf5b57f05d

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>