From: Yanglong Wu Date: Wed, 20 Jun 2018 02:12:47 +0000 (+0800) Subject: net/i40e: check illegal packets X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=bfeed0262b0c2f1f7b73645dcd17b436f4f5ed5b;p=dpdk.git net/i40e: check illegal packets 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. Signed-off-by: Yanglong Wu Acked-by: Konstantin Ananyev --- diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c index 6032d55416..e7916f99c2 100644 --- a/drivers/net/i40e/i40e_rxtx.c +++ b/drivers/net/i40e/i40e_rxtx.c @@ -1439,13 +1439,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, /* Check for m->nb_segs to not exceed the limits. */ if (!(ol_flags & PKT_TX_TCP_SEG)) { - if (m->nb_segs > I40E_TX_MAX_SEG || - m->nb_segs > I40E_TX_MAX_MTU_SEG) { + if (m->nb_segs > I40E_TX_MAX_MTU_SEG) { rte_errno = -EINVAL; return i; } - } else if ((m->tso_segsz < I40E_MIN_TSO_MSS) || - (m->tso_segsz > I40E_MAX_TSO_MSS)) { + } else if (m->nb_segs > I40E_TX_MAX_SEG || + m->tso_segsz < I40E_MIN_TSO_MSS || + m->tso_segsz > I40E_MAX_TSO_MSS) { /* MSS outside the range (256B - 9674B) are considered * malicious */ @@ -1458,6 +1458,13 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, return i; } + /* check the size of packet */ + if (m->pkt_len > I40E_FRAME_SIZE_MAX || + m->pkt_len < I40E_TX_MIN_PKT_LEN) { + rte_errno = -EINVAL; + return i; + } + #ifdef RTE_LIBRTE_ETHDEV_DEBUG ret = rte_validate_tx_offload(m); if (ret != 0) { diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h index ea73a8a1bf..3fc619af90 100644 --- a/drivers/net/i40e/i40e_rxtx.h +++ b/drivers/net/i40e/i40e_rxtx.h @@ -30,6 +30,8 @@ #define I40E_TX_MAX_SEG UINT8_MAX #define I40E_TX_MAX_MTU_SEG 8 +#define I40E_TX_MIN_PKT_LEN 17 + #undef container_of #define container_of(ptr, type, member) ({ \ typeof(((type *)0)->member)(*__mptr) = (ptr); \