From: Junlong Wang <wang.junlong1@zte.com.cn>
To: stephen@networkplumber.org
Cc: dev@dpdk.org, Junlong Wang <wang.junlong1@zte.com.cn>, stable@dpdk.org
Subject: [PATCH v1 1/2] net/zxdh: bound resource table reply length before copying
Date: Sat, 28 Nov 2026 12:04:57 +0800 [thread overview]
Message-ID: <20261128040458.3967016-2-wang.junlong1@zte.com.cn> (raw)
In-Reply-To: <20261128040458.3967016-1-wang.junlong1@zte.com.cn>
[-- 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 --]
next prev parent reply other threads:[~2026-11-28 4:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-01 0:26 ` [PATCH v1 1/2] net/zxdh: bound resource table reply length before copying 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128040458.3967016-2-wang.junlong1@zte.com.cn \
--to=wang.junlong1@zte.com.cn \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox