[PATCH 2/2] net/ice: check illegal packets

Kevin Liu kevinx.liu at intel.com
Thu Sep 22 09:04:26 CEST 2022


Some 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 at intel.com>
---
 drivers/net/ice/ice_rxtx.c | 13 +++++++++++++
 drivers/net/ice/ice_rxtx.h |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/drivers/net/ice/ice_rxtx.c b/drivers/net/ice/ice_rxtx.c
index 5af7c0c8f6..0d0b093537 100644
--- a/drivers/net/ice/ice_rxtx.c
+++ b/drivers/net/ice/ice_rxtx.c
@@ -3458,6 +3458,19 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
 			return i;
 		}
 
+		/* check the size of packet */
+		if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG) &&
+			m->pkt_len > ICE_FRAME_SIZE_MAX) {
+			rte_errno = EINVAL;
+			PMD_DRV_LOG(ERR, "INVALID mbuf: bad pkt_len=[%hu]", m->pkt_len);
+			return i;
+		}
+		if (m->pkt_len < ICE_TX_MIN_PKT_LEN) {
+			rte_errno = EINVAL;
+			PMD_DRV_LOG(ERR, "INVALID mbuf: bad pkt_len=[%hu]", m->pkt_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



More information about the dev mailing list