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 2/2] net/ice: check illegal packets
Date: Tue, 27 Sep 2022 07:15:22 +0000 [thread overview]
Message-ID: <20220927071522.3656059-3-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: 17c7d0f9d6a4 ("net/ice: support basic Rx/Tx")
Signed-off-by: Kevin Liu <kevinx.liu@intel.com>
---
drivers/net/ice/ice_rxtx.c | 11 +++++++++++
drivers/net/ice/ice_rxtx.h | 2 ++
2 files changed, 13 insertions(+)
diff --git a/drivers/net/ice/ice_rxtx.c b/drivers/net/ice/ice_rxtx.c
index 5af7c0c8f6..d1e1fadf9d 100644
--- a/drivers/net/ice/ice_rxtx.c
+++ b/drivers/net/ice/ice_rxtx.c
@@ -3442,6 +3442,9 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
int i, ret;
uint64_t ol_flags;
struct rte_mbuf *m;
+ struct ice_tx_queue *txq = tx_queue;
+ struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id];
+ uint16_t max_frame_size = dev->data->mtu + ICE_ETH_OVERHEAD;
for (i = 0; i < nb_pkts; i++) {
m = tx_pkts[i];
@@ -3458,6 +3461,14 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
return i;
}
+ /* check the data_len in mbuf */
+ if (m->data_len < ICE_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/ice/ice_rxtx.h b/drivers/net/ice/ice_rxtx.h
index 6c08c175dc..e1d4fe8e47 100644
--- a/drivers/net/ice/ice_rxtx.h
+++ b/drivers/net/ice/ice_rxtx.h
@@ -40,6 +40,8 @@
#define ICE_RXDID_COMMS_OVS 22
+#define ICE_TX_MIN_PKT_LEN 17
+
extern uint64_t ice_timestamp_dynflag;
extern int ice_timestamp_dynfield_offset;
--
2.25.1
next prev parent 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 ` [PATCH v2 1/2] net/iavf: " Kevin Liu
2022-09-27 7:15 ` Kevin Liu [this message]
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-3-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).