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 76D1DA0556; Sun, 16 Oct 2022 16:43:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1B7DB40143; Sun, 16 Oct 2022 16:43:18 +0200 (CEST) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mails.dpdk.org (Postfix) with ESMTP id B40D3400D4; Sun, 16 Oct 2022 16:43:16 +0200 (CEST) Received: by mail-pj1-f48.google.com with SMTP id o17-20020a17090aac1100b0020d98b0c0f4so10682150pjq.4; Sun, 16 Oct 2022 07:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TnY7uRSn9+iuplb5CoITNoZr8okE8WLWTuu5m1o2w+M=; b=ZXDrroqU4uRKA7cpaARbhS8jVzyQwa8snNEqQuKYtex4HJYThklL3DYzu6WWAbgNjW DTv4xaT1ug8TBZlWTIuG/NZwT5/bdx9b7fNvzSi8KysIkg4tYT0E0YPtOGrGY96sjXFi haeMtxXp5zpjWD7MSA5DpC13z1Y46gh0B68CmVLE4h4O+ZfKPlfAXwCyCZw82FzVtoSI GfBIDVMC04SOt3VedLV1JEiY2PSaaqSo5axy89js2al/e9HMvcnF81ShB1AErXnwEX5m +IDtaSXjPmyF1242qUJ+KXSsJNq4SPChk6T2Ho6EPgAk3TW9Evl9GWySUqcRkRrFH5gG uuyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TnY7uRSn9+iuplb5CoITNoZr8okE8WLWTuu5m1o2w+M=; b=4dyKTSIg4+v/x9k8sQmmOzL2vfy73lEptFdCjfyOhIkEIzcNLQp+gZCZ4cdr8t1VXl XJkD+mEqa56J8O+OQmkcNXV3vVrGggvLFXSfBaLBKdeDYWXPtkyK+aV8R6IxiTjn5efo /rYxwTOOZMEqLuB2OpXDPmERs2NOnqLNxM+oq0oTMHrW9czEOczzpKJ8CJS5viv6M6HQ 7GoBUOZPjrFJPQ2YuSJhnuvSYkZ2978co9bW7aY2vlMT8oLp6dNXtx85Bof090Ndyid6 Yt0zRpyzm1cJLMfZ7znYHRDa5fvLV5tBzivH89bAIQG8zt+9ubZ6OkCyQBr2bF0ExLU4 Ffhg== X-Gm-Message-State: ACrzQf2OObbRx7XFf4dn2+aMd1QcUVig9rrwzjEdmfRP9OchSQQZ3PL7 enSmTDA89izIxPdzNnZt4EM= X-Google-Smtp-Source: AMsMyM5C+GDe7Xm1TTjF4KGZ2zh49Bjxz7tkHG0lmzFw4vlAjf0w/+yX0rCMwKqoT+hDKF2uSie/Rg== X-Received: by 2002:a17:902:d2cc:b0:182:d901:5d28 with SMTP id n12-20020a170902d2cc00b00182d9015d28mr7601723plc.142.1665931395674; Sun, 16 Oct 2022 07:43:15 -0700 (PDT) Received: from kparameshwa-a02.vmware.com.com ([103.113.190.40]) by smtp.gmail.com with ESMTPSA id o7-20020a17090ac08700b0020d2170b3fcsm4588845pjs.9.2022.10.16.07.43.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 16 Oct 2022 07:43:14 -0700 (PDT) From: Kumara Parameshwaran X-Google-Original-From: Kumara Parameshwaran To: jiayu.hu@intel.com Cc: dev@dpdk.org, Kumara Parameshwaran , stable@dpdk.org Subject: [PATCH v2] gro : check for payload length after the trim Date: Sun, 16 Oct 2022 20:13:05 +0530 Message-Id: <20221016144305.19249-1-kumaraparmesh92@gmail.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20221010175109.44282-1-kumaraparmesh92@gmail.com> References: <20221010175109.44282-1-kumaraparmesh92@gmail.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 From: Kumara Parameshwaran When packet is padded with extra bytes the the validation of the payload length should be done after the trim operation Fixes: b8a55871d5af ("gro: trim tail padding bytes") Cc: stable@dpdk.org Signed-off-by: Kumara Parameshwaran --- v1: If there is padding to the ethernet frame cases where timestamp is disabled the packet length should be validated with the total ip length as packet length is used in the GRO merging logic v2: Trim the packet length and then check for the protocol payload validation lib/gro/gro_tcp4.c | 11 ++++++----- lib/gro/gro_udp4.c | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/gro/gro_tcp4.c b/lib/gro/gro_tcp4.c index 8f5e800250..0014096e63 100644 --- a/lib/gro/gro_tcp4.c +++ b/lib/gro/gro_tcp4.c @@ -225,6 +225,12 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt, */ if (tcp_hdr->tcp_flags != RTE_TCP_ACK_FLAG) return -1; + + /* trim the tail padding bytes */ + ip_tlen = rte_be_to_cpu_16(ipv4_hdr->total_length); + if (pkt->pkt_len > (uint32_t)(ip_tlen + pkt->l2_len)) + rte_pktmbuf_trim(pkt, pkt->pkt_len - ip_tlen - pkt->l2_len); + /* * Don't process the packet whose payload length is less than or * equal to 0. @@ -233,11 +239,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt, if (tcp_dl <= 0) return -1; - /* trim the tail padding bytes */ - ip_tlen = rte_be_to_cpu_16(ipv4_hdr->total_length); - if (pkt->pkt_len > (uint32_t)(ip_tlen + pkt->l2_len)) - rte_pktmbuf_trim(pkt, pkt->pkt_len - ip_tlen - pkt->l2_len); - /* * Save IPv4 ID for the packet whose DF bit is 0. For the packet * whose DF bit is 1, IPv4 ID is ignored. diff --git a/lib/gro/gro_udp4.c b/lib/gro/gro_udp4.c index 839f9748b7..42596d33b6 100644 --- a/lib/gro/gro_udp4.c +++ b/lib/gro/gro_udp4.c @@ -220,6 +220,11 @@ gro_udp4_reassemble(struct rte_mbuf *pkt, if (!is_ipv4_fragment(ipv4_hdr)) return -1; + ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length); + /* trim the tail padding bytes */ + if (pkt->pkt_len > (uint32_t)(ip_dl + pkt->l2_len)) + rte_pktmbuf_trim(pkt, pkt->pkt_len - ip_dl - pkt->l2_len); + /* * Don't process the packet whose payload length is less than or * equal to 0. @@ -227,14 +232,9 @@ gro_udp4_reassemble(struct rte_mbuf *pkt, if (pkt->pkt_len <= hdr_len) return -1; - ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length); if (ip_dl <= pkt->l3_len) return -1; - /* trim the tail padding bytes */ - if (pkt->pkt_len > (uint32_t)(ip_dl + pkt->l2_len)) - rte_pktmbuf_trim(pkt, pkt->pkt_len - ip_dl - pkt->l2_len); - ip_dl -= pkt->l3_len; ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id); frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset); -- 2.25.1