All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ajit Khaparde <ajit.khaparde@broadcom.com>
To: dev@dpdk.org
Cc: Somnath Kotur <somnath.kotur@broadcom.com>
Subject: [PATCH 04/13] net/bnxt: add check for number of segs
Date: Fri, 25 Oct 2024 10:57:29 -0700	[thread overview]
Message-ID: <20241025175738.99564-5-ajit.khaparde@broadcom.com> (raw)
In-Reply-To: <20241025175738.99564-1-ajit.khaparde@broadcom.com>

From: Somnath Kotur <somnath.kotur@broadcom.com>

If the application passes incorrect number of segs for a Tx pkt i.e.
sets it to 5 while actually sending down only a single mbuf, this could
escape all the existing driver checks and driver could end up sending
down garbage TX BDs to the HW. This in turn could lead to a Tx pipeline
stall.
Fix it by validating the number of segs passed for the Tx pkt against
what is actually set by the application to prevent this.

Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_txr.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/net/bnxt/bnxt_txr.c b/drivers/net/bnxt/bnxt_txr.c
index 6d7e9962ce..51d3689e9c 100644
--- a/drivers/net/bnxt/bnxt_txr.c
+++ b/drivers/net/bnxt/bnxt_txr.c
@@ -194,6 +194,21 @@ bnxt_check_pkt_needs_ts(struct rte_mbuf *m)
 	return false;
 }
 
+static bool
+bnxt_invalid_nb_segs(struct rte_mbuf *tx_pkt)
+{
+	uint16_t nb_segs = 1;
+	struct rte_mbuf *m_seg;
+
+	m_seg = tx_pkt->next;
+	while (m_seg) {
+		nb_segs++;
+		m_seg = m_seg->next;
+	}
+
+	return (nb_segs != tx_pkt->nb_segs);
+}
+
 static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt,
 				struct bnxt_tx_queue *txq,
 				uint16_t *coal_pkts,
@@ -221,6 +236,9 @@ static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt,
 	if (unlikely(is_bnxt_in_error(txq->bp)))
 		return -EIO;
 
+	if (unlikely(bnxt_invalid_nb_segs(tx_pkt)))
+		return -EINVAL;
+
 	long_bd = bnxt_xmit_need_long_bd(tx_pkt, txq);
 	nr_bds = long_bd + tx_pkt->nb_segs;
 
-- 
2.39.5 (Apple Git-154)


  parent reply	other threads:[~2024-10-25 17:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 17:57 [PATCH 00/13] patchset for bnxt PMD Ajit Khaparde
2024-10-25 17:57 ` [PATCH 01/13] net/bnxt: fix TCP and UDP checksum flags Ajit Khaparde
2024-10-25 17:57 ` [PATCH 02/13] net/bnxt: fix bad action offset in Tx bd Ajit Khaparde
2024-10-25 17:57 ` [PATCH 03/13] net/bnxt: add check to validate TSO segment size Ajit Khaparde
2024-10-25 17:57 ` Ajit Khaparde [this message]
2024-10-25 17:57 ` [PATCH 05/13] net/bnxt: add check for invalid mbuf passed by application Ajit Khaparde
2024-10-25 17:57 ` [PATCH 06/13] net/bnxt: free and account a bad Tx mbuf Ajit Khaparde
2024-10-25 17:57 ` [PATCH 07/13] net/bnxt: register for and handle RSS change event Ajit Khaparde
2024-10-25 17:57 ` [PATCH 08/13] net/bnxt: fix LRO offload capability Ajit Khaparde
2024-10-25 17:57 ` [PATCH 09/13] net/bnxt: disable VLAN filter when TF is enabled Ajit Khaparde
2024-10-25 17:57 ` [PATCH 10/13] net/bnxt: remove the VNIC async event handler Ajit Khaparde
2024-10-25 17:57 ` [PATCH 11/13] net/bnxt: remove some unnecessary logs Ajit Khaparde
2024-10-25 17:57 ` [PATCH 12/13] net/bnxt: add support for buffer split Rx offload Ajit Khaparde
2024-10-25 17:57 ` [PATCH 13/13] net/bnxt: remove unnecessary ifdef Ajit Khaparde

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=20241025175738.99564-5-ajit.khaparde@broadcom.com \
    --to=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=somnath.kotur@broadcom.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.