From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A2D04A0543; Thu, 22 Sep 2022 09:13:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 96A02410E8; Thu, 22 Sep 2022 09:13:59 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id B7413400D7 for ; Thu, 22 Sep 2022 09:13:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663830838; x=1695366838; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ww/vUj2Nn3HT9JoUJhHuYJBpNrAm58sptV5rTs9+KbE=; b=iQn7nA9BMqVSz7akBnuydjHXvszV3nXo8uBl+8elFTHzx/8U+I5oLRsF t0aqjGoOiu5seMqyUyuKcFh60fvzRuo1c6wB1PBfAQm8/DgCsAt2O2SPa nGaOREnAmZ8jPe5U4w3Whbr7y2ueHo4b+WdaAtcJG1lqAcjvK1FtKgw+M YfdZLo/usNOqO5FGEtlafQo37Mrfy8RM6kgJcpUtF1vXxKR7FETmHqmN/ O+L1BRRMXLF3fbIVXFdO2m3I7uy8VnuxJMUkAswwq494qDMGot7LqBQCi cgkzptprS/DTuATaFeZVsEO9VuLDCwQ+QVtGjPCl0c6KZBs3OuRsWno6F w==; X-IronPort-AV: E=McAfee;i="6500,9779,10477"; a="301066702" X-IronPort-AV: E=Sophos;i="5.93,335,1654585200"; d="scan'208";a="301066702" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 00:13:48 -0700 X-IronPort-AV: E=Sophos;i="5.93,335,1654585200"; d="scan'208";a="864746698" Received: from intel-cd-odc-robin.cd.intel.com ([10.240.178.136]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 00:13:46 -0700 From: Kevin Liu 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 Subject: [PATCH 1/2] net/iavf: check illegal packets Date: Thu, 22 Sep 2022 07:04:25 +0000 Message-Id: <20220922070426.788643-2-kevinx.liu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220922070426.788643-1-kevinx.liu@intel.com> References: <20220922070426.788643-1-kevinx.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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: a2b29a7733ef ("net/avf: enable basic Rx Tx") Signed-off-by: Kevin Liu --- 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