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 61923436DA for ; Wed, 13 Dec 2023 06:22:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 57FC7402B4; Wed, 13 Dec 2023 06:22:59 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by mails.dpdk.org (Postfix) with ESMTP id D75D14026A; Wed, 13 Dec 2023 06:22:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702444978; x=1733980978; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Re+YOCXas2NHBbzGwdPAWekzcBbOOhZAxQ/8089jzL0=; b=WcBSBkivd0gH1pvssfh5EEo9Zj0PATn/ZPXz/w+An7NLZzOBZ1w4uuBi vvPsNIDeY8gTvt3gpakunwg3R+x+qAdBiclK5kD+0tW/9ydcpLfFR9HC8 Jjgj49AV1C8HTaRfauUrckYH8Yhv81UatcBDa6z3kGHcTLqTgbzkfwBA8 9QZRKYf+F67X4TyXYYSh3q6ZLye3o6PDIdzLdIEgMkt3nGIM+JPBtMi/e zrmNKkNStdoXSxfrfXXd9klwMlmzLLofstmpkFThnLZXfO5kcPiKHpxp6 T/vUUpcPzjtsXQ0PXU3sXrKvJHSWU3skQxEJxvG759E0YKhfKzI9kam7K g==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="1727228" X-IronPort-AV: E=Sophos;i="6.04,272,1695711600"; d="scan'208";a="1727228" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 21:22:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,272,1695711600"; d="scan'208";a="21799250" Received: from shwdenpg561.ccr.corp.intel.com (HELO dpdk..) ([10.239.252.3]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 21:22:54 -0800 From: Kaiwen Deng To: dev@dpdk.org Cc: stable@dpdk.org, qiming.yang@intel.com, yidingx.zhou@intel.com, Kaiwen Deng , Xiaoyun Li , Ferruh Yigit , Aman Singh Subject: [PATCH v4] lib/net: fix tcp/udp cksum with padding data Date: Wed, 13 Dec 2023 12:37:32 +0800 Message-Id: <20231213043732.2113867-1-kaiwenx.deng@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212021619.2038881-1-kaiwenx.deng@intel.com> References: <20231212021619.2038881-1-kaiwenx.deng@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org IEEE 802 packets may have a minimum size limit. The data fields should be padded when necessary. In some cases, the padding data is not zero. In 'rte_ipv4_udptcp_cksum_mbuf()', as payload length "mbuf->pkt_len - l4_off" is used, which includes padding and if padding is not zero it will end up producing wrong checksum. This patch will use IP header to get the payload size to calculate tcp/udp checksum. Fixes: d178f693bbfe ("net: add UDP/TCP checksum in mbuf segments") Cc: stable@dpdk.org Signed-off-by: Kaiwen Deng --- lib/net/rte_ip.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h index 6fa98a5a0f..bcdce723a5 100644 --- a/lib/net/rte_ip.h +++ b/lib/net/rte_ip.h @@ -419,11 +419,15 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, { uint16_t raw_cksum; uint32_t cksum; + uint16_t len; - if (l4_off > m->pkt_len) - return 0; + if (unlikely(l4_off > m->pkt_len)) + return 0; /* invalid params, return a dummy value */ + + len = rte_be_to_cpu_16(ipv4_hdr->total_length) - + (uint16_t)rte_ipv4_hdr_len(ipv4_hdr); - if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum)) + if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum)) return 0; cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0); @@ -663,10 +667,11 @@ __rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, uint16_t raw_cksum; uint32_t cksum; - if (l4_off > m->pkt_len) - return 0; + if (unlikely(l4_off > m->pkt_len)) + return 0; /* invalid params, return a dummy value */ - if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum)) + if (rte_raw_cksum_mbuf(m, l4_off, + rte_be_to_cpu_16(ipv6_hdr->payload_len), &raw_cksum)) return 0; cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0); -- 2.34.1