DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kevin Liu <kevinx.liu@intel.com>
To: dev@dpdk.org
Cc: qiming.yang@intel.com, qi.z.zhang@intel.com,
	stevex.yang@intel.com, beilei.xing@intel.com,
	jingjing.wu@intel.com, Kevin Liu <kevinx.liu@intel.com>
Subject: [PATCH v2 1/2] net/iavf: check illegal packets
Date: Tue, 27 Sep 2022 07:15:21 +0000	[thread overview]
Message-ID: <20220927071522.3656059-2-kevinx.liu@intel.com> (raw)
In-Reply-To: <20220927071522.3656059-1-kevinx.liu@intel.com>

If the length of data_len in mbuf is less than 17 or
greater than the maximum frame size, it is illegal.

These illegal packets will lead to TX/RX hang and
can't recover automatically.

This patch check those illegal packets and protect
TX/RX from hanging.

Fixes: a2b29a7733ef ("net/avf: enable basic Rx Tx")
Signed-off-by: Kevin Liu <kevinx.liu@intel.com>
---
 drivers/net/iavf/iavf_rxtx.c | 9 +++++++++
 drivers/net/iavf/iavf_rxtx.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c
index 3deabe1d7e..be34d6210b 100644
--- a/drivers/net/iavf/iavf_rxtx.c
+++ b/drivers/net/iavf/iavf_rxtx.c
@@ -2865,6 +2865,7 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 	struct rte_mbuf *m;
 	struct iavf_tx_queue *txq = tx_queue;
 	struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id];
+	uint16_t max_frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct iavf_adapter *adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
 
@@ -2893,6 +2894,14 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the data_len in mbuf */
+		if (m->data_len < IAVF_TX_MIN_PKT_LEN ||
+			m->data_len > max_frame_size) {
+			rte_errno = EINVAL;
+			PMD_DRV_LOG(ERR, "INVALID mbuf: bad data_len=[%hu]", m->data_len);
+			return i;
+		}
+
 #ifdef RTE_ETHDEV_DEBUG_TX
 		ret = rte_validate_tx_offload(m);
 		if (ret != 0) {
diff --git a/drivers/net/iavf/iavf_rxtx.h b/drivers/net/iavf/iavf_rxtx.h
index 1695e43cd5..bb9083c699 100644
--- a/drivers/net/iavf/iavf_rxtx.h
+++ b/drivers/net/iavf/iavf_rxtx.h
@@ -53,6 +53,8 @@
 #define IAVF_TSO_MAX_SEG          UINT8_MAX
 #define IAVF_TX_MAX_MTU_SEG       8
 
+#define IAVF_TX_MIN_PKT_LEN 17
+
 #define IAVF_TX_CKSUM_OFFLOAD_MASK (		 \
 		RTE_MBUF_F_TX_IP_CKSUM |		 \
 		RTE_MBUF_F_TX_L4_MASK |		 \
-- 
2.25.1


  reply	other threads:[~2022-09-27  7:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22  7:04 [PATCH 0/2] " Kevin Liu
2022-09-22  7:04 ` [PATCH 1/2] net/iavf: " Kevin Liu
2022-09-23  0:46   ` Zhang, Qi Z
2022-09-22  7:04 ` [PATCH 2/2] net/ice: " Kevin Liu
2022-09-27  7:15 ` [PATCH v2 0/2] " Kevin Liu
2022-09-27  7:15   ` Kevin Liu [this message]
2022-09-27  7:15   ` [PATCH v2 2/2] net/ice: " Kevin Liu
2022-09-30  0:21   ` [PATCH v2 0/2] " Zhang, Qi Z
2023-09-18 14:42   ` David Marchand
2023-09-18 14:51     ` Kevin Traynor

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=20220927071522.3656059-2-kevinx.liu@intel.com \
    --to=kevinx.liu@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=stevex.yang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).