* [PATCH v1 1/2] net/zxdh: bound resource table reply length before copying
2026-11-28 4:04 [PATCH v1 0/2] net/zxdh: fix issues reported by GCC analyzer Junlong Wang
@ 2026-11-28 4:04 ` Junlong Wang
2026-12-01 0:26 ` Stephen Hemminger
2026-11-28 4:04 ` [PATCH v1 2/2] net/zxdh: avoid leaking flow entry on validation Junlong Wang
2026-12-01 0:33 ` [PATCH v1 0/2] net/zxdh: fix issues reported by GCC analyzer Stephen Hemminger
2 siblings, 1 reply; 5+ messages in thread
From: Junlong Wang @ 2026-11-28 4:04 UTC (permalink / raw)
To: stephen; +Cc: dev, Junlong Wang, stable
[-- Attachment #1.1.1: Type: text/plain, Size: 3623 bytes --]
zxdh_get_res_info() copies a device-supplied reply length into the
caller's buffer without knowing that buffer's size. Both callers pass
the address of a uint8_t local, so a reply longer than one byte
overwrites the caller's stack. Nothing bounds the length either: it
sits in a nested TBL reply header, which
zxdh_bar_chan_sync_msg_send() does not look at, and a value above
ZXDH_RSC_TBL_CONTENT_LEN_MAX also overruns recv_buf.
Pass the destination capacity to the function and reject a reply that
exceeds it or the recv_buf size, rather than truncating a malformed
length into a wrong panel or hash id.
While here, report a reply whose status byte is not the success code
as ZXDH_BAR_MSG_ERR_REPLY and log that byte: such a reply was returned
to the caller as success. Copy with memcpy() rather than rte_memcpy():
the length is already checked, and the inlined body makes gcc
-fanalyzer report a false out-of-bounds write on the caller's
one-byte object.
Fixes: 6310e3976b ("net/zxdh: get device backend infos")
Cc: stable@dpdk.org
Signed-off-by: Junlong Wang <wang.junlong1@zte.com.cn>
---
drivers/net/zxdh/zxdh_common.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/net/zxdh/zxdh_common.c b/drivers/net/zxdh/zxdh_common.c
index 2b821b1dc8..22cdfbacc4 100644
--- a/drivers/net/zxdh/zxdh_common.c
+++ b/drivers/net/zxdh/zxdh_common.c
@@ -183,13 +183,14 @@ zxdh_fill_res_para(struct rte_eth_dev *dev, struct zxdh_res_para *param)
}
static int
-zxdh_get_res_info(struct zxdh_res_para *dev, uint8_t field, uint8_t *res, uint16_t *len)
+zxdh_get_res_info(struct zxdh_res_para *dev, uint8_t field,
+ uint8_t *res, uint16_t max_len, uint16_t *len)
{
struct zxdh_pci_bar_msg in = {0};
uint8_t recv_buf[ZXDH_RSC_TBL_CONTENT_LEN_MAX + 8] = {0};
int ret = 0;
- if (!res || !dev)
+ if (!res || !dev || !len)
return ZXDH_BAR_MSG_ERR_NULL;
struct zxdh_tbl_msg_header tbl_msg = {
@@ -224,11 +225,18 @@ zxdh_get_res_info(struct zxdh_res_para *dev, uint8_t field, uint8_t *res, uint16
if (tbl_reps->check != ZXDH_TBL_MSG_PRO_SUCCESS) {
PMD_DRV_LOG(ERR,
- "get resource_field failed. pcieid: 0x%x, ret: %d", dev->pcie_id, ret);
- return ret;
+ "get resource_field failed. pcieid: 0x%x, check: %u",
+ dev->pcie_id, tbl_reps->check);
+ return ZXDH_BAR_MSG_ERR_REPLY;
+ }
+ if (tbl_reps->len > max_len || tbl_reps->len > ZXDH_RSC_TBL_CONTENT_LEN_MAX) {
+ PMD_DRV_LOG(ERR,
+ "invalid resource_field len: %u (max: %u). pcieid: 0x%x",
+ tbl_reps->len, max_len, dev->pcie_id);
+ return -EINVAL;
}
*len = tbl_reps->len;
- rte_memcpy(res, (recv_buf + ZXDH_REPS_HEADER_OFFSET +
+ memcpy(res, (recv_buf + ZXDH_REPS_HEADER_OFFSET +
sizeof(struct zxdh_tbl_msg_reps_header)), *len);
return ret;
}
@@ -239,7 +247,8 @@ zxdh_get_res_panel_id(struct zxdh_res_para *in, uint8_t *panel_id)
uint8_t reps = 0;
uint16_t reps_len = 0;
- if (zxdh_get_res_info(in, ZXDH_TBL_FIELD_PNLID, &reps, &reps_len) != ZXDH_BAR_MSG_OK)
+ if (zxdh_get_res_info(in, ZXDH_TBL_FIELD_PNLID, &reps, sizeof(reps),
+ &reps_len) != ZXDH_BAR_MSG_OK)
return -1;
*panel_id = reps;
@@ -262,7 +271,8 @@ zxdh_get_res_hash_id(struct zxdh_res_para *in, uint8_t *hash_id)
uint8_t reps = 0;
uint16_t reps_len = 0;
- if (zxdh_get_res_info(in, ZXDH_TBL_FIELD_HASHID, &reps, &reps_len) != ZXDH_BAR_MSG_OK)
+ if (zxdh_get_res_info(in, ZXDH_TBL_FIELD_HASHID, &reps, sizeof(reps),
+ &reps_len) != ZXDH_BAR_MSG_OK)
return -1;
*hash_id = reps;
--
2.27.0
[-- Attachment #1.1.2: Type: text/html , Size: 7539 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 2/2] net/zxdh: avoid leaking flow entry on validation
2026-11-28 4:04 [PATCH v1 0/2] net/zxdh: fix issues reported by GCC analyzer Junlong Wang
2026-11-28 4:04 ` [PATCH v1 1/2] net/zxdh: bound resource table reply length before copying Junlong Wang
@ 2026-11-28 4:04 ` Junlong Wang
2026-12-01 0:33 ` [PATCH v1 0/2] net/zxdh: fix issues reported by GCC analyzer Stephen Hemminger
2 siblings, 0 replies; 5+ messages in thread
From: Junlong Wang @ 2026-11-28 4:04 UTC (permalink / raw)
To: stephen; +Cc: dev, Junlong Wang, stable
[-- Attachment #1.1.1: Type: text/plain, Size: 7873 bytes --]
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@dpdk.org
Signed-off-by: Junlong Wang <wang.junlong1@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
[-- Attachment #1.1.2: Type: text/html , Size: 23209 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread