patch 'net/bnxt: harden sprintf bounds for device memory names' has been queued to stable release 24.11.9
luca.boccassi at gmail.com
luca.boccassi at gmail.com
Tue Oct 27 12:50:52 CET 2026
Hi,
FYI, your patch has been queued to stable release 24.11.9
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 10/29/26. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.
Queued patches are on a temporary branch at:
https://github.com/bluca/dpdk-stable
This queued commit can be viewed at:
https://github.com/bluca/dpdk-stable/commit/265ca5d4b8b0e016cc9859b4c6216f72053569be
Thanks.
Luca Boccassi
---
>From 265ca5d4b8b0e016cc9859b4c6216f72053569be Mon Sep 17 00:00:00 2001
From: Keegan Freyhof <keegan.freyhof at broadcom.com>
Date: Tue, 29 Sep 2026 12:03:46 -0600
Subject: [PATCH] net/bnxt: harden sprintf bounds for device memory names
[ upstream commit 2d9cb324a0bf9ea9b70407c254ea20cd277db5af ]
sprintf() into fixed-size stack buffers such as
char type[RTE_MEMZONE_NAMESIZE] does not bound the write to the
buffer. bnxt_hwrm_ver_get()'s "bnxt_hwrm_short_" PCI_PRI_FMT label
overflows a 32-byte RTE_MEMZONE_NAMESIZE buffer once the PCI domain
needs more than 4 hex digits: rte_pci_addr.domain is a uint32_t, and
PCI_PRI_FMT's %.4x is a minimum width, not a maximum, so an 8-digit
domain plus the 16-character prefix plus the rest of the PCI address
string plus the terminating NUL is 33 bytes into 32.
Convert this and the other sprintf() calls building memzone/malloc
names and HWRM CFA pair_name request fields to snprintf(), which
bounds the write and truncates instead of overflowing. The return
value is not checked: none of these format strings involve locale or
multibyte conversion, so a negative return is not reachable, and a
truncated debug label or pair_name is not itself a memory-safety
concern -- a truncated pair_name simply fails to match at the
firmware side, handled the same way as any other not-found pair.
Also write the per-flow xstat names directly into
xstats_names[count].name via snprintf() instead of through an
intermediate buf plus strlcpy(), since the destination is already
exactly sized for that format string.
Fixes: 79cc1efd99c6 ("net/bnxt: support extended HWRM request sizes")
Signed-off-by: Keegan Freyhof <keegan.freyhof at broadcom.com>
Signed-off-by: Mohammad Shuab Siddique <mohammad-shuab.siddique at broadcom.com>
---
drivers/net/bnxt/bnxt_ethdev.c | 14 +++++++-------
drivers/net/bnxt/bnxt_hwrm.c | 10 +++++-----
drivers/net/bnxt/bnxt_stats.c | 15 ++++++---------
3 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 9547c5cd548..0657ac4f7f6 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -646,12 +646,12 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
{
struct rte_pci_device *pdev = bp->pdev;
char type[RTE_MEMZONE_NAMESIZE];
+ int rc = 0;
uint16_t max_fc;
- int rc = 0;
max_fc = bp->flow_stat->max_fc;
- sprintf(type, "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
+ snprintf(type, sizeof(type), "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
/* 4 bytes for each counter-id */
rc = bnxt_alloc_ctx_mem_buf(bp, type,
@@ -660,7 +660,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
if (rc)
return rc;
- sprintf(type, "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
+ snprintf(type, sizeof(type), "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
/* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
rc = bnxt_alloc_ctx_mem_buf(bp, type,
@@ -669,7 +669,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
if (rc)
return rc;
- sprintf(type, "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
+ snprintf(type, sizeof(type), "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
/* 4 bytes for each counter-id */
rc = bnxt_alloc_ctx_mem_buf(bp, type,
@@ -678,7 +678,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
if (rc)
return rc;
- sprintf(type, "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
+ snprintf(type, sizeof(type), "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
/* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
rc = bnxt_alloc_ctx_mem_buf(bp, type,
@@ -5158,8 +5158,8 @@ int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
{
struct bnxt_ctx_mem_info *ctx = bp->ctx;
struct bnxt_ctx_mem *ctx2;
- uint16_t type;
int rc = 0;
+ uint16_t type;
ctx2 = &ctx->ctx_arr[0];
for (type = 0; type < ctx->types && rc == 0; type++) {
@@ -5180,7 +5180,7 @@ int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
for (i = 0; i < w && rc == 0; i++) {
char name[RTE_MEMZONE_NAMESIZE] = {0};
- sprintf(name, "_%d_%d", i, type);
+ snprintf(name, sizeof(name), "_%d_%d", i, type);
if (ctxm->entry_multiple)
entries = bnxt_roundup(ctxm->max_entries,
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 8559158bb56..96d114babd6 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -1580,12 +1580,12 @@ int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
{
- int rc = 0;
struct hwrm_ver_get_input req = {.req_type = 0 };
struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
uint32_t fw_version;
uint16_t max_resp_len;
char type[RTE_MEMZONE_NAMESIZE];
+ int rc = 0;
uint32_t dev_caps_cfg;
bp->max_req_len = HWRM_MAX_REQ_LEN;
@@ -1666,10 +1666,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
(dev_caps_cfg &
HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
- sprintf(type, "bnxt_hwrm_short_" PCI_PRI_FMT,
+ snprintf(type, sizeof(type), "bnxt_hwrm_short_" PCI_PRI_FMT,
bp->pdev->addr.domain, bp->pdev->addr.bus,
bp->pdev->addr.devid, bp->pdev->addr.function);
-
rte_free(bp->hwrm_short_cmd_req_addr);
bp->hwrm_short_cmd_req_addr =
@@ -3558,7 +3557,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp)
struct rte_pci_device *pdev = bp->pdev;
char type[RTE_MEMZONE_NAMESIZE];
- sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
+ snprintf(type, sizeof(type), "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
bp->max_resp_len = BNXT_PAGE_SIZE;
bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
@@ -6775,7 +6774,7 @@ static int bnxt_alloc_all_ctx_pg_info(struct bnxt *bp)
if (ctxm->instance_bmap)
n = hweight32(ctxm->instance_bmap);
- sprintf(name, "bnxt_ctx_pgmem_%d_%d",
+ snprintf(name, sizeof(name), "bnxt_ctx_pgmem_%d_%d",
bp->eth_dev->data->port_id, type);
ctxm->pg_info = rte_malloc(name, sizeof(*ctxm->pg_info) * n,
RTE_CACHE_LINE_SIZE);
@@ -7819,6 +7818,7 @@ int bnxt_hwrm_cfa_pair_free(struct bnxt *bp, struct bnxt_representor *rep_bp)
HWRM_PREP(&req, HWRM_CFA_PAIR_FREE, BNXT_USE_CHIMP_MB);
snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
bp->eth_dev->data->name, rep_bp->vf_id);
+
req.pf_b_id = rep_bp->parent_pf_idx;
req.pair_mode = HWRM_CFA_PAIR_FREE_INPUT_PAIR_MODE_REP2FN_TRUFLOW;
req.vf_id = BNXT_REP_PF(rep_bp) ? rte_cpu_to_le_16(((uint16_t)-1)) :
diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c
index 987cb2aeb0b..17439d4dc62 100644
--- a/drivers/net/bnxt/bnxt_stats.c
+++ b/drivers/net/bnxt/bnxt_stats.c
@@ -1161,17 +1161,14 @@ skip_func_stats:
bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_MGMT &&
BNXT_FLOW_XSTATS_EN(bp)) {
for (i = 0; i < bp->max_l2_ctx; i++) {
- char buf[RTE_ETH_XSTATS_NAME_SIZE];
-
- sprintf(buf, "flow_%d_bytes", i);
- strlcpy(xstats_names[count].name, buf,
- sizeof(xstats_names[count].name));
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name),
+ "flow_%d_bytes", i);
count++;
- sprintf(buf, "flow_%d_packets", i);
- strlcpy(xstats_names[count].name, buf,
- sizeof(xstats_names[count].name));
-
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name),
+ "flow_%d_packets", i);
count++;
}
}
--
2.47.3
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2026-10-27 11:43:59.784505370 +0000
+++ 0158-net-bnxt-harden-sprintf-bounds-for-device-memory-nam.patch 2026-10-27 11:43:53.714065639 +0000
@@ -1 +1 @@
-From 2d9cb324a0bf9ea9b70407c254ea20cd277db5af Mon Sep 17 00:00:00 2001
+From 265ca5d4b8b0e016cc9859b4c6216f72053569be Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 2d9cb324a0bf9ea9b70407c254ea20cd277db5af ]
+
@@ -30 +31,0 @@
-Cc: stable at dpdk.org
@@ -41 +42 @@
-index 4d4349457c..11e8f7908d 100644
+index 9547c5cd548..0657ac4f7f6 100644
@@ -44 +45 @@
-@@ -647,12 +647,12 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
+@@ -646,12 +646,12 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
@@ -59 +60 @@
-@@ -661,7 +661,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
+@@ -660,7 +660,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
@@ -68 +69 @@
-@@ -670,7 +670,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
+@@ -669,7 +669,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
@@ -77 +78 @@
-@@ -679,7 +679,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
+@@ -678,7 +678,7 @@ static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
@@ -86 +87 @@
-@@ -5232,8 +5232,8 @@ int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
+@@ -5158,8 +5158,8 @@ int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
@@ -96 +97 @@
-@@ -5254,7 +5254,7 @@ int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
+@@ -5180,7 +5180,7 @@ int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
@@ -106 +107 @@
-index 1615b36aae..361402b36f 100644
+index 8559158bb56..96d114babd6 100644
@@ -109 +110 @@
-@@ -1583,12 +1583,12 @@ int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
+@@ -1580,12 +1580,12 @@ int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
@@ -123 +124 @@
-@@ -1669,10 +1669,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
+@@ -1666,10 +1666,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
@@ -135 +136 @@
-@@ -3542,7 +3541,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp)
+@@ -3558,7 +3557,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp)
@@ -144 +145 @@
-@@ -6792,7 +6791,7 @@ static int bnxt_alloc_all_ctx_pg_info(struct bnxt *bp)
+@@ -6775,7 +6774,7 @@ static int bnxt_alloc_all_ctx_pg_info(struct bnxt *bp)
@@ -153 +154 @@
-@@ -7836,6 +7835,7 @@ int bnxt_hwrm_cfa_pair_free(struct bnxt *bp, struct bnxt_representor *rep_bp)
+@@ -7819,6 +7818,7 @@ int bnxt_hwrm_cfa_pair_free(struct bnxt *bp, struct bnxt_representor *rep_bp)
@@ -162 +163 @@
-index 4074613eb0..05e8944f47 100644
+index 987cb2aeb0b..17439d4dc62 100644
@@ -165 +166 @@
-@@ -1165,17 +1165,14 @@ skip_func_stats:
+@@ -1161,17 +1161,14 @@ skip_func_stats:
More information about the stable
mailing list