Unverified Commit fe72026b authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!6284 net/mlx5e: CT, Fix multiple allocations and memleak of mod acts

parents fecdf43c 26ccd27b
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -1310,9 +1310,13 @@ mlx5_tc_ct_match_add(struct mlx5_tc_ct_priv *priv,
int
mlx5_tc_ct_parse_action(struct mlx5_tc_ct_priv *priv,
			struct mlx5_flow_attr *attr,
			struct mlx5e_tc_mod_hdr_acts *mod_acts,
			const struct flow_action_entry *act,
			struct netlink_ext_ack *extack)
{
	bool clear_action = act->ct.action & TCA_CT_ACT_CLEAR;
	int err;

	if (!priv) {
		NL_SET_ERR_MSG_MOD(extack,
				   "offload of ct action isn't available");
@@ -1323,6 +1327,17 @@ mlx5_tc_ct_parse_action(struct mlx5_tc_ct_priv *priv,
	attr->ct_attr.ct_action = act->ct.action;
	attr->ct_attr.nf_ft = act->ct.flow_table;

	if (!clear_action)
		goto out;

	err = mlx5_tc_ct_entry_set_registers(priv, mod_acts, 0, 0, 0, 0);
	if (err) {
		NL_SET_ERR_MSG_MOD(extack, "Failed to set registers for ct clear");
		return err;
	}
	attr->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;

out:
	return 0;
}

@@ -1890,24 +1905,17 @@ __mlx5_tc_ct_flow_offload_clear(struct mlx5_tc_ct_priv *ct_priv,

	memcpy(pre_ct_attr, attr, attr_sz);

	err = mlx5_tc_ct_entry_set_registers(ct_priv, mod_acts, 0, 0, 0, 0);
	if (err) {
		ct_dbg("Failed to set register for ct clear");
		goto err_set_registers;
	}

	mod_hdr = mlx5_modify_header_alloc(priv->mdev, ct_priv->ns_type,
					   mod_acts->num_actions,
					   mod_acts->actions);
	if (IS_ERR(mod_hdr)) {
		err = PTR_ERR(mod_hdr);
		ct_dbg("Failed to add create ct clear mod hdr");
		goto err_set_registers;
		goto err_mod_hdr;
	}

	dealloc_mod_hdr_actions(mod_acts);
	pre_ct_attr->modify_hdr = mod_hdr;
	pre_ct_attr->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;

	rule = mlx5_tc_rule_insert(priv, orig_spec, pre_ct_attr);
	if (IS_ERR(rule)) {
@@ -1923,7 +1931,7 @@ __mlx5_tc_ct_flow_offload_clear(struct mlx5_tc_ct_priv *ct_priv,

err_insert:
	mlx5_modify_header_dealloc(priv->mdev, mod_hdr);
err_set_registers:
err_mod_hdr:
	netdev_warn(priv->netdev,
		    "Failed to offload ct clear flow, err %d\n", err);
	kfree(pre_ct_attr);
+2 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ int mlx5_tc_ct_add_no_trk_match(struct mlx5_flow_spec *spec);
int
mlx5_tc_ct_parse_action(struct mlx5_tc_ct_priv *priv,
			struct mlx5_flow_attr *attr,
			struct mlx5e_tc_mod_hdr_acts *mod_acts,
			const struct flow_action_entry *act,
			struct netlink_ext_ack *extack);

@@ -173,6 +174,7 @@ mlx5_tc_ct_add_no_trk_match(struct mlx5_flow_spec *spec)
static inline int
mlx5_tc_ct_parse_action(struct mlx5_tc_ct_priv *priv,
			struct mlx5_flow_attr *attr,
			struct mlx5e_tc_mod_hdr_acts *mod_acts,
			const struct flow_action_entry *act,
			struct netlink_ext_ack *extack)
{
+6 −2
Original line number Diff line number Diff line
@@ -3617,7 +3617,9 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv,
			attr->dest_chain = act->chain_index;
			break;
		case FLOW_ACTION_CT:
			err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr, act, extack);
			err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr,
						      &parse_attr->mod_hdr_acts,
						      act, extack);
			if (err)
				return err;

@@ -4457,7 +4459,9 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
			attr->dest_chain = act->chain_index;
			break;
		case FLOW_ACTION_CT:
			err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr, act, extack);
			err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr,
							&parse_attr->mod_hdr_acts,
							act, extack);
			if (err)
				return err;