[PATCH v1 2/2] net/zxdh: avoid leaking flow entry on validation
Junlong Wang
wang.junlong1 at zte.com.cn
Sat Nov 28 05:04:58 CET 2026
zxdh_flow_validate() reuses the pattern and action parsers of
zxdh_flow_create(), but passes dh_flow as NULL; both parsers then
rte_zmalloc() a struct zxdh_flow_info to parse into.
Neither parser releases that allocation on the validation path.
fd_flow_parse_pattern() has no cleanup at all, so the memory leaks on
its success return and on all ten of its early returns.
fd_flow_parse_action() only frees through its free_flow label, so its
success return and the four checks made after the action loop leak as
well. Each validate therefore leaks 368 bytes of the rte_malloc heap,
and rte_flow_validate() is a side-effect free API that an application
may call as often as it wants.
Keep the parse code shared, but make it fall back to a zeroed local
struct zxdh_flow_info when dh_flow is NULL instead of allocating one.
The memory then goes away with the stack frame, no return path needs
cleanup, and the free_flow label of fd_flow_parse_action() has nothing
left to do.
The local struct is zeroed exactly like rte_zmalloc() was, it never
escapes the parser, and the create path keeps parsing into dh_flow
unchanged. Stack use grows by 184 bytes per parser.
Fixes: d0af48c1b952 ("net/zxdh: support flow API")
Cc: stable at dpdk.org
Signed-off-by: Junlong Wang <wang.junlong1 at zte.com.cn>
---
drivers/net/zxdh/zxdh_flow.c | 58 ++++++++++--------------------------
1 file changed, 16 insertions(+), 42 deletions(-)
diff --git a/drivers/net/zxdh/zxdh_flow.c b/drivers/net/zxdh/zxdh_flow.c
index a51ce9ef77..776c02117f 100644
--- a/drivers/net/zxdh/zxdh_flow.c
+++ b/drivers/net/zxdh/zxdh_flow.c
@@ -1238,7 +1238,8 @@ static int fd_flow_parse_pattern(struct rte_eth_dev *dev, const struct rte_flow_
struct rte_flow_error *error, struct zxdh_flow *dh_flow)
{
struct zxdh_hw *priv = dev->data->dev_private;
- struct zxdh_flow_info *flow = NULL;
+ struct zxdh_flow_info local_flow = {0};
+ struct zxdh_flow_info *flow = dh_flow ? &dh_flow->flowentry : &local_flow;
const struct rte_flow_item *item;
const struct rte_flow_item_eth *eth_spec, *eth_mask;
const struct rte_flow_item_vlan *vlan_spec, *vlan_mask;
@@ -1250,18 +1251,6 @@ static int fd_flow_parse_pattern(struct rte_eth_dev *dev, const struct rte_flow_
const struct rte_flow_item_vxlan *vxlan_spec, *vxlan_mask;
struct fd_flow_key *key, *key_mask;
- if (dh_flow) {
- flow = &dh_flow->flowentry;
- } else {
- flow = rte_zmalloc("dh_flow", sizeof(*flow), 0);
- if (flow == NULL) {
- rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
- "Failed to allocate memory ");
- return -rte_errno;
- }
- }
-
key = &flow->fd_flow.key;
key_mask = &flow->fd_flow.key_mask;
key->vfid = rte_cpu_to_be_16(priv->vfid);
@@ -1648,7 +1637,8 @@ static int
fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *actions,
struct rte_flow_error *error, struct zxdh_flow *dh_flow)
{
- struct zxdh_flow_info *flow = NULL;
+ struct zxdh_flow_info local_flow = {0};
+ struct zxdh_flow_info *flow = dh_flow ? &dh_flow->flowentry : &local_flow;
struct fd_flow_result *result = NULL;
const struct rte_flow_item *enc_item = NULL;
uint8_t action_bitmap = 0;
@@ -1658,17 +1648,6 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
int ret;
rte_errno = 0;
- if (dh_flow) {
- flow = &dh_flow->flowentry;
- } else {
- flow = rte_zmalloc("dh_flow", sizeof(*flow), 0);
- if (flow == NULL) {
- rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
- "Failed to allocate memory ");
- return -rte_errno;
- }
- }
result = &flow->fd_flow.result;
action_bitmap = result->action_idx;
@@ -1681,11 +1660,11 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"rss action does no support.");
- goto free_flow;
+ return -rte_errno;
}
ret = validate_action_rss(dev, actions, error);
if (ret)
- goto free_flow;
+ return -rte_errno;
action_bitmap |= (1 << FD_ACTION_RSS_BIT);
break;
}
@@ -1696,7 +1675,7 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"multi mark action no support.");
- goto free_flow;
+ return -rte_errno;
}
const struct rte_flow_action_mark *act_mark = actions->conf;
result->mark_fd_id = rte_cpu_to_le_32(act_mark->id);
@@ -1710,14 +1689,14 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"multi count action no support.");
- goto free_flow;
+ return -rte_errno;
}
const struct rte_flow_action_count *act_count = actions->conf;
if (act_count->id > MAX_FLOW_COUNT_NUM) {
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"count action id no support.");
- goto free_flow;
+ return -rte_errno;
};
result->countid = act_count->id;
action_bitmap |= (1 << FD_ACTION_COUNT_BIT);
@@ -1730,7 +1709,7 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"multi queue action no support.");
- goto free_flow;
+ return -rte_errno;
}
const struct rte_flow_action_queue *act_q;
act_q = actions->conf;
@@ -1738,14 +1717,14 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"Invalid queue ID");
- goto free_flow;
+ return -rte_errno;
}
ret = zxdh_hw_qid_to_logic_qid(dev, act_q->index << 1);
if (ret < 0) {
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"Invalid phy queue ID .");
- goto free_flow;
+ return -rte_errno;
}
result->qid = rte_cpu_to_le_16(ret);
action_bitmap |= (1 << FD_ACTION_QUEUE_BIT);
@@ -1760,7 +1739,7 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"multi drop action no support.");
- goto free_flow;
+ return -rte_errno;
}
action_bitmap |= (1 << FD_ACTION_DROP_BIT);
break;
@@ -1772,7 +1751,7 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"multi drop action no support.");
- goto free_flow;
+ return -rte_errno;
}
action_bitmap |= (1 << FD_ACTION_VXLAN_DECAP);
break;
@@ -1787,7 +1766,7 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"multi drop action no support.");
- goto free_flow;
+ return -rte_errno;
}
action_bitmap |= (1 << FD_ACTION_VXLAN_ENCAP);
break;
@@ -1795,7 +1774,7 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"Invalid action.");
- goto free_flow;
+ return -rte_errno;
}
}
@@ -1829,11 +1808,6 @@ fd_flow_parse_action(struct rte_eth_dev *dev, const struct rte_flow_action *acti
result->action_idx = action_bitmap;
return 0;
-
-free_flow:
- if (!dh_flow)
- rte_free(flow);
- return -rte_errno;
}
static int
--
2.27.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mails.dpdk.org/archives/stable/attachments/20261128/06acc7e2/attachment.htm>
More information about the stable
mailing list