DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mohammad Shuab Siddique <mohammad-shuab.siddique@broadcom.com>
To: dev@dpdk.org
Cc: kishore.padmanabha@broadcom.com,
	Joseph Wong <joseph.wong@broadcom.com>,
	stable@dpdk.org,
	Mohammad Shuab Siddique <mohammad-shuab.siddique@broadcom.com>
Subject: [PATCH 1/5] net/bnxt: add VF ID boundary check before usage
Date: Thu, 17 Sep 2026 21:27:22 -0600	[thread overview]
Message-ID: <20260918032726.763384-2-Mohammad-Shuab.Siddique@broadcom.com> (raw)
In-Reply-To: <20260918032726.763384-1-Mohammad-Shuab.Siddique@broadcom.com>

From: Joseph Wong <joseph.wong@broadcom.com>

bnxt_handle_fwd_req() computed vf_id from an unvalidated,
firmware-controlled source_id and used it to index
bp->pf->vf_info[] before checking that the ID falls within the
active VF range. An out-of-range VF ID could index past
vf_info[] and cause memory corruption.

Move the range check ahead of the vf_id computation and the
vf_info[] lookup. Guard the later fwd_cmd/req_len usage on the
reject path, since they are no longer set when the request is
rejected early. Also guard bnxt_hwrm_reject_fwd_resp()'s memcpy()
against a NULL encaped pointer for the same reason.

Fixes: f2a768d4d186 ("net/bnxt: add completion ring")
Cc: stable@dpdk.org

Signed-off-by: Joseph Wong <joseph.wong@broadcom.com>
Signed-off-by: Mohammad Shuab Siddique <mohammad-shuab.siddique@broadcom.com>
---
 drivers/net/bnxt/bnxt_cpr.c  | 25 ++++++++++++++-----------
 drivers/net/bnxt/bnxt_hwrm.c |  3 ++-
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_cpr.c b/drivers/net/bnxt/bnxt_cpr.c
index 5c255de59e..ac731ea72f 100644
--- a/drivers/net/bnxt/bnxt_cpr.c
+++ b/drivers/net/bnxt/bnxt_cpr.c
@@ -375,16 +375,6 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
 
 	/* Qualify the fwd request */
 	fw_vf_id = rte_le_to_cpu_16(fwd_cmpl->source_id);
-	vf_id = fw_vf_id - bp->pf->first_vf_id;
-
-	req_len = (rte_le_to_cpu_16(fwd_cmpl->req_len_type) &
-		   HWRM_FWD_REQ_CMPL_REQ_LEN_MASK) >>
-		HWRM_FWD_REQ_CMPL_REQ_LEN_SFT;
-	if (req_len > sizeof(fwreq->encap_request))
-		req_len = sizeof(fwreq->encap_request);
-
-	/* Locate VF's forwarded command */
-	fwd_cmd = (struct input *)bp->pf->vf_info[vf_id].req_buf;
 
 	if (fw_vf_id < bp->pf->first_vf_id ||
 	    fw_vf_id >= bp->pf->first_vf_id + bp->pf->active_vfs) {
@@ -393,9 +383,22 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
 			fw_vf_id, bp->pf->first_vf_id,
 			(bp->pf->first_vf_id) + bp->pf->active_vfs - 1,
 			bp->pf->first_vf_id, bp->pf->active_vfs);
+		fwd_cmd = NULL;
+		req_len = 0;
 		goto reject;
 	}
 
+	vf_id = fw_vf_id - bp->pf->first_vf_id;
+
+	req_len = (rte_le_to_cpu_16(fwd_cmpl->req_len_type) &
+		   HWRM_FWD_REQ_CMPL_REQ_LEN_MASK) >>
+		HWRM_FWD_REQ_CMPL_REQ_LEN_SFT;
+	if (req_len > sizeof(fwreq->encap_request))
+		req_len = sizeof(fwreq->encap_request);
+
+	/* Locate VF's forwarded command */
+	fwd_cmd = (struct input *)bp->pf->vf_info[vf_id].req_buf;
+
 	if (bnxt_rcv_msg_from_vf(bp, vf_id, fwd_cmd)) {
 		/*
 		 * In older firmware versions, the MAC had to be all zeros for
@@ -495,7 +498,7 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
 		PMD_DRV_LOG_LINE(ERR,
 			"Failed to send REJECT req VF 0x%x, type 0x%x.",
 			fw_vf_id - bp->pf->first_vf_id,
-			rte_le_to_cpu_16(fwd_cmd->req_type));
+			fwd_cmd ? rte_le_to_cpu_16(fwd_cmd->req_type) : 0xFFFF);
 	}
 
 	return;
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 1615b36aae..aa8152eaa0 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -5520,7 +5520,8 @@ int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
 	HWRM_PREP(&req, HWRM_REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
 
 	req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
-	memcpy(req.encap_request, encaped, ec_size);
+	if (encaped)
+		memcpy(req.encap_request, encaped, ec_size);
 
 	rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
 
-- 
2.47.3


  reply	other threads:[~2026-09-18  3:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  3:27 [PATCH 0/5] net/bnxt: fix VF and firmware-facing bounds/leak issues Mohammad Shuab Siddique
2026-09-18  3:27 ` Mohammad Shuab Siddique [this message]
2026-09-18  3:27 ` [PATCH 2/5] net/bnxt: fix bounds on firmware-reported resource counts Mohammad Shuab Siddique
2026-09-18  3:27 ` [PATCH 3/5] net/bnxt: fix use-after-free in VNIC filter cleanup Mohammad Shuab Siddique
2026-09-18  3:27 ` [PATCH 4/5] net/bnxt: fix memory leak in VF VNIC query error path Mohammad Shuab Siddique
2026-09-18  3:27 ` [PATCH 5/5] net/bnxt: fix VF info alloc error path memory leak Mohammad Shuab Siddique
2026-09-21  2:19 ` [PATCH v2 0/5] net/bnxt: fix VF and firmware-facing bounds/leak issues Mohammad Shuab Siddique
2026-09-21  2:19   ` [PATCH v2 1/5] net/bnxt: add VF ID boundary check before usage Mohammad Shuab Siddique
2026-09-21  2:19   ` [PATCH v2 2/5] net/bnxt: fix bounds on firmware-reported resource counts Mohammad Shuab Siddique
2026-09-21 15:47     ` Stephen Hemminger
2026-09-21  2:20   ` [PATCH v2 3/5] net/bnxt: fix use-after-free in VNIC filter cleanup Mohammad Shuab Siddique
2026-09-21 15:48     ` Stephen Hemminger
2026-09-21  2:20   ` [PATCH v2 4/5] net/bnxt: fix memory leak in VF VNIC query error path Mohammad Shuab Siddique
2026-09-21  2:20   ` [PATCH v2 5/5] net/bnxt: fix VF info alloc error path memory leak Mohammad Shuab Siddique
2026-09-29  0:24 ` [PATCH v3 0/5] net/bnxt: fix VF and firmware-facing bounds/leak issues Mohammad Shuab Siddique
2026-09-29  0:24   ` [PATCH v3 1/5] net/bnxt: add VF ID boundary check before usage Mohammad Shuab Siddique
2026-09-29  0:24   ` [PATCH v3 2/5] net/bnxt: fix bounds on firmware-reported resource counts Mohammad Shuab Siddique
2026-09-29  0:24   ` [PATCH v3 3/5] net/bnxt: fix VNIC filter list walk stopping early Mohammad Shuab Siddique
2026-09-29  0:24   ` [PATCH v3 4/5] net/bnxt: fix memory leak in VF VNIC query error path Mohammad Shuab Siddique
2026-09-29  0:24   ` [PATCH v3 5/5] net/bnxt: fix VF info alloc error path memory leak Mohammad Shuab Siddique

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=20260918032726.763384-2-Mohammad-Shuab.Siddique@broadcom.com \
    --to=mohammad-shuab.siddique@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=joseph.wong@broadcom.com \
    --cc=kishore.padmanabha@broadcom.com \
    --cc=stable@dpdk.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