Skip to content

Commit cefc235

Browse files
maorgottliebSaeed Mahameed
authored and
Saeed Mahameed
committed
net/mlx5: Fix FTE cleanup
Currently, when an FTE is allocated, its refcount is decreased to 0 with the purpose it will not be a stand alone steering object and every rule (destination) of the FTE would increase the refcount. When mlx5_cleanup_fs is called while not all rules were deleted by the steering users, it hit refcount underflow on the FTE once clean_tree calls to tree_remove_node after the deleted rules already decreased the refcount to 0. FTE is no longer destroyed implicitly when the last rule (destination) is deleted. mlx5_del_flow_rules avoids it by increasing the refcount on the FTE and destroy it explicitly after all rules were deleted. So we can avoid the refcount underflow by making FTE as stand alone object. In addition need to set del_hw_func to FTE so the HW object will be destroyed when the FTE is deleted from the cleanup_tree flow. refcount_t: underflow; use-after-free. WARNING: CPU: 2 PID: 15715 at lib/refcount.c:28 refcount_warn_saturate+0xd9/0xe0 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Call Trace: tree_put_node+0xf2/0x140 [mlx5_core] clean_tree+0x4e/0xf0 [mlx5_core] clean_tree+0x4e/0xf0 [mlx5_core] clean_tree+0x4e/0xf0 [mlx5_core] clean_tree+0x5f/0xf0 [mlx5_core] clean_tree+0x4e/0xf0 [mlx5_core] clean_tree+0x5f/0xf0 [mlx5_core] mlx5_cleanup_fs+0x26/0x270 [mlx5_core] mlx5_unload+0x2e/0xa0 [mlx5_core] mlx5_unload_one+0x51/0x120 [mlx5_core] mlx5_devlink_reload_down+0x51/0x90 [mlx5_core] devlink_reload+0x39/0x120 ? devlink_nl_cmd_reload+0x43/0x220 genl_rcv_msg+0x1e4/0x420 ? genl_family_rcv_msg_attrs_parse+0x100/0x100 netlink_rcv_skb+0x47/0x110 genl_rcv+0x24/0x40 netlink_unicast+0x217/0x2f0 netlink_sendmsg+0x30f/0x430 sock_sendmsg+0x30/0x40 __sys_sendto+0x10e/0x140 ? handle_mm_fault+0xc4/0x1f0 ? do_page_fault+0x33f/0x630 __x64_sys_sendto+0x24/0x30 do_syscall_64+0x48/0x130 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 718ce4d ("net/mlx5: Consolidate update FTE for all removal changes") Fixes: bd71b08 ("net/mlx5: Support multiple updates of steering rules in parallel") Signed-off-by: Maor Gottlieb <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 5f6857e commit cefc235

File tree

1 file changed

+4
-4
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+4
-4
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static struct fs_fte *alloc_fte(struct mlx5_flow_table *ft,
654654
fte->action = *flow_act;
655655
fte->flow_context = spec->flow_context;
656656

657-
tree_init_node(&fte->node, NULL, del_sw_fte);
657+
tree_init_node(&fte->node, del_hw_fte, del_sw_fte);
658658

659659
return fte;
660660
}
@@ -1792,7 +1792,6 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
17921792
up_write_ref_node(&g->node, false);
17931793
rule = add_rule_fg(g, spec, flow_act, dest, dest_num, fte);
17941794
up_write_ref_node(&fte->node, false);
1795-
tree_put_node(&fte->node, false);
17961795
return rule;
17971796
}
17981797
rule = ERR_PTR(-ENOENT);
@@ -1891,7 +1890,6 @@ _mlx5_add_flow_rules(struct mlx5_flow_table *ft,
18911890
up_write_ref_node(&g->node, false);
18921891
rule = add_rule_fg(g, spec, flow_act, dest, dest_num, fte);
18931892
up_write_ref_node(&fte->node, false);
1894-
tree_put_node(&fte->node, false);
18951893
tree_put_node(&g->node, false);
18961894
return rule;
18971895

@@ -2001,7 +1999,9 @@ void mlx5_del_flow_rules(struct mlx5_flow_handle *handle)
20011999
up_write_ref_node(&fte->node, false);
20022000
} else {
20032001
del_hw_fte(&fte->node);
2004-
up_write(&fte->node.lock);
2002+
/* Avoid double call to del_hw_fte */
2003+
fte->node.del_hw_func = NULL;
2004+
up_write_ref_node(&fte->node, false);
20052005
tree_put_node(&fte->node, false);
20062006
}
20072007
kfree(handle);

0 commit comments

Comments
 (0)