> -----Original Message-----
> From: Liu, KevinX <kevinx....@intel.com>
> Sent: Thursday, September 22, 2022 3:04 PM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.y...@intel.com>; Zhang, Qi Z
> <qi.z.zh...@intel.com>; Yang, SteveX <stevex.y...@intel.com>; Xing, Beilei
> <beilei.x...@intel.com>; Wu, Jingjing <jingjing...@intel.com>; Liu, KevinX
> <kevinx....@intel.com>
> Subject: [PATCH 1/2] net/iavf: 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.
Better to describe precisely what kind of illegal packets you are going to
prevent.
>
> Fixes: a2b29a7733ef ("net/avf: enable basic Rx Tx")
> Signed-off-by: Kevin Liu <kevinx....@intel.com>
> ---
> drivers/net/iavf/iavf_rxtx.c | 10 +++++++++- drivers/net/iavf/iavf_rxtx.h |
> 2
> ++
> 2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c index
> 3deabe1d7e..8ddd809f94 100644
> --- a/drivers/net/iavf/iavf_rxtx.c
> +++ b/drivers/net/iavf/iavf_rxtx.c
> @@ -2877,7 +2877,8 @@ iavf_prep_pkts(__rte_unused void *tx_queue,
> struct rte_mbuf **tx_pkts,
>
> /* Check condition for nb_segs > IAVF_TX_MAX_MTU_SEG.
> */
> if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
> - if (m->nb_segs > IAVF_TX_MAX_MTU_SEG) {
> + if (m->nb_segs > IAVF_TX_MAX_MTU_SEG ||
> + m->pkt_len > IAVF_FRAME_SIZE_MAX) {
> rte_errno = EINVAL;
> return i;
> }
> @@ -2893,6 +2894,13 @@ iavf_prep_pkts(__rte_unused void *tx_queue,
> struct rte_mbuf **tx_pkts,
> return i;
> }
>
> + /* check the size of packet */
> + if (m->pkt_len < IAVF_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/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