Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4371059imw; Tue, 19 Jul 2022 05:31:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sHFkHcA/hgcUp+om3uYCpMHwjbEvdGLGVDnfpdfamBIaI5be16Bmqf2RWq8SpwwQ5e6Rr4 X-Received: by 2002:a17:90a:d506:b0:1f0:74ba:9775 with SMTP id t6-20020a17090ad50600b001f074ba9775mr38725491pju.151.1658233902348; Tue, 19 Jul 2022 05:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233902; cv=none; d=google.com; s=arc-20160816; b=gktHmObNi6pyFKhodQ76MXfTG6tHrGO/4zUZTchbURe3piUoOLJmFklYFQ2Hx/UT8G kCnKmW2CyvJtfZo/6fnE7jiyYANilecI9UEZlHi6gMlY7eJ1qXqCeixHivjTC8WcI0rb cibEYQN1ledMKWW8SsjmOYN57KUkmDPUP/rCFASYkVRkbSSMwYRdzY5WP8sNhmbIxmKS fk7/8S9WCGGw98nALYtYvpoVuOXhYxMFhzWZxDJRuHY09DzZ4drNs+3slwHezkmJxd7k vDfk9DBWxyNUkKvn9+GMzsUWkmREXmsduC2Y2nzg0kXQ+naq21sw3Q8plMAoQHt5bilo Me2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gty+dA94HUwMHSATrThPRakK0ss17NUQm6BaUhM5Ph8=; b=jMNzNOkdwourAnXAHWtNx0+EJ+2m82vM3cQ5YVNab2LIWvqSnwwTnn4oeM03BW0e1v nNatSG2DpdmWpf1GrDz2xCodD4wVKjqv6tT7bsBBe06OFuQgI3QV+oBRuHqnOJrRuukN drvd9cHSVSFsPVc7/3wBv1u+ZCbKp45xEDbb6djI/W8z9vbsHiRIpCvrKr+xMtud2tjv XsBEfAFEQD4/nDrBX3g7Sf9F/Iofo0u+nL5X7psQGABw9w9M8fKKN8jNQHLDosDj28PK PWpjMMR3hu9adjZfv+ldYR5uPe/ZkEWa43chgYa/2dfZg2/i83ITv2913Keq09tYXM6Z UsYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yGxiaExJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x186-20020a6386c3000000b00411f3d72b41si3620212pgd.506.2022.07.19.05.31.27; Tue, 19 Jul 2022 05:31:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yGxiaExJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238314AbiGSMGX (ORCPT + 99 others); Tue, 19 Jul 2022 08:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238146AbiGSMEF (ORCPT ); Tue, 19 Jul 2022 08:04:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 854DD45061; Tue, 19 Jul 2022 04:59:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 38EABB81A2E; Tue, 19 Jul 2022 11:59:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BFF6C341C6; Tue, 19 Jul 2022 11:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231990; bh=BJnVW9DMZ3+Wr45rya5ls9wYILTenORCBLHoOxaRQ8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yGxiaExJIf29+p9cTgSPxkcjwZ9ayOB/qHJS23tpWZ7hJDBtAM/EklpgeUJRmj6QH OWSp0w+uxzRmzO7177uPBAXosaTv0yMcXsxJrCalM/xjYMvIU7/IzRG2BYIw5h/NS3 fPfk/jw/r4iwR4VizBSuVatzN2ky0FfZRfpqtKL8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Abeni , Andrea Mayer , Sasha Levin Subject: [PATCH 4.19 23/48] seg6: fix skb checksum evaluation in SRH encapsulation/insertion Date: Tue, 19 Jul 2022 13:54:00 +0200 Message-Id: <20220719114521.922560725@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114518.915546280@linuxfoundation.org> References: <20220719114518.915546280@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrea Mayer [ Upstream commit df8386d13ea280d55beee1b95f61a59234a3798b ] Support for SRH encapsulation and insertion was introduced with commit 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels"), through the seg6_do_srh_encap() and seg6_do_srh_inline() functions, respectively. The former encapsulates the packet in an outer IPv6 header along with the SRH, while the latter inserts the SRH between the IPv6 header and the payload. Then, the headers are initialized/updated according to the operating mode (i.e., encap/inline). Finally, the skb checksum is calculated to reflect the changes applied to the headers. The IPv6 payload length ('payload_len') is not initialized within seg6_do_srh_{inline,encap}() but is deferred in seg6_do_srh(), i.e. the caller of seg6_do_srh_{inline,encap}(). However, this operation invalidates the skb checksum, since the 'payload_len' is updated only after the checksum is evaluated. To solve this issue, the initialization of the IPv6 payload length is moved from seg6_do_srh() directly into the seg6_do_srh_{inline,encap}() functions and before the skb checksum update takes place. Fixes: 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels") Reported-by: Paolo Abeni Link: https://lore.kernel.org/all/20220705190727.69d532417be7438b15404ee1@uniroma2.it Signed-off-by: Andrea Mayer Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/ipv6/seg6_iptunnel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 26882fd9323a..2e90672852c8 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -176,6 +176,8 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) } #endif + hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); + skb_postpush_rcsum(skb, hdr, tot_len); return 0; @@ -228,6 +230,8 @@ int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh) } #endif + hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); + skb_postpush_rcsum(skb, hdr, sizeof(struct ipv6hdr) + hdrlen); return 0; @@ -289,7 +293,6 @@ static int seg6_do_srh(struct sk_buff *skb) break; } - ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); skb_set_transport_header(skb, sizeof(struct ipv6hdr)); return 0; -- 2.35.1