From patchwork Tue Sep 27 07:15:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Liu X-Patchwork-Id: 116935 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 24024A00C2; Tue, 27 Sep 2022 09:24:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6089342685; Tue, 27 Sep 2022 09:24:41 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 8B99041143 for ; Tue, 27 Sep 2022 09:24:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664263479; x=1695799479; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2vCaK3VQWa304UjT/gom+Nk6JQC1BF9liDMrHcgpHK0=; b=cpNZQL8MviEv79d23yvxGmNIp50+ptS5Mo/OKLyLnrG8JcrRVBJ/v7e4 t9pcGhOXfFg33JAO4e2m3YgcHEDX6puk2pRmfDWOpKJhLUvihZ1XSe0NT 6SBsRgkvKAt8sbPIk+LvJxfZU4sLWYTXmCChOB8oTvoZ2wleoRx7xUiXN lCTdVXVVGrKVKJaIQFKt8w6R+aEYQZcAAoBPywV6MjRKLL+KY5Pl3MisC d9At8h9HjsDTdRjtVrEVYr1NT/aeGuR2T54xOfSd4LFHgSgnqJGTj8nAh giqGQLdfJZHqETSh9EXf6xbxbOYTK68ho6x6371RiJ7IZx8386mJZ2a1Y g==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="288395306" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="288395306" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 00:24:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652182572" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652182572" Received: from intel-cd-odc-robin.cd.intel.com ([10.240.178.136]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 00:24:36 -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 v2 1/2] net/iavf: check illegal packets Date: Tue, 27 Sep 2022 07:15:21 +0000 Message-Id: <20220927071522.3656059-2-kevinx.liu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220927071522.3656059-1-kevinx.liu@intel.com> References: <20220922070426.788643-1-kevinx.liu@intel.com> <20220927071522.3656059-1-kevinx.liu@intel.com> MIME-Version: 1.0 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 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: a2b29a7733ef ("net/avf: enable basic Rx Tx") Signed-off-by: Kevin Liu --- drivers/net/iavf/iavf_rxtx.c | 9 +++++++++ drivers/net/iavf/iavf_rxtx.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c index 3deabe1d7e..be34d6210b 100644 --- a/drivers/net/iavf/iavf_rxtx.c +++ b/drivers/net/iavf/iavf_rxtx.c @@ -2865,6 +2865,7 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, struct rte_mbuf *m; struct iavf_tx_queue *txq = tx_queue; struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id]; + uint16_t max_frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD; struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private); struct iavf_adapter *adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private); @@ -2893,6 +2894,14 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, return i; } + /* check the data_len in mbuf */ + if (m->data_len < IAVF_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/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 | \ From patchwork Tue Sep 27 07:15:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Liu X-Patchwork-Id: 116936 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 798C1A00C2; Tue, 27 Sep 2022 09:24:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F647427F1; Tue, 27 Sep 2022 09:24:45 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 33586427F0 for ; Tue, 27 Sep 2022 09:24:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664263482; x=1695799482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3YkQft0uN7ZgmOeR+6QBYidB6hYJQbgSgGnj6HOEEo8=; b=KPMAoacX4TJNfk30lYXiF6VZ0/v0CNw2ghajak3akD3HH+1E4ZkMD1lt 45Zxkmti4/3O7FgPViZjPZHdfK2v6R8QYnH1fS2H2UqzjRsS2tPb+L5io FEY9XUCI0W0WlijhPR4n3Vxwf4FADzf9IPpplM3Mv5gXKODlkV1nFWZTa gUnadD1suRmX8XKltkgVGVFylyW+uk5UQI6F+kdsBG64C9n9vj9NXX8jy khf0vs2FTYFZ7V4wgj1XSBaBTHz17jTDoL/UVQhTw36CLFE2161C2jLpL J4uZsxaHxAw05qlBlQ3GLUBM1DO4TUX1oCkW8ILwgB23KsbsVgmcm3SoS w==; X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="288395313" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="288395313" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 00:24:41 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10482"; a="652182582" X-IronPort-AV: E=Sophos;i="5.93,348,1654585200"; d="scan'208";a="652182582" Received: from intel-cd-odc-robin.cd.intel.com ([10.240.178.136]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 00:24:39 -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 v2 2/2] net/ice: check illegal packets Date: Tue, 27 Sep 2022 07:15:22 +0000 Message-Id: <20220927071522.3656059-3-kevinx.liu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220927071522.3656059-1-kevinx.liu@intel.com> References: <20220922070426.788643-1-kevinx.liu@intel.com> <20220927071522.3656059-1-kevinx.liu@intel.com> MIME-Version: 1.0 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 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 --- 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;