Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4373733imw; Tue, 19 Jul 2022 05:34:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u6U7tlF4K/9+a/6Xs40U9uy5Bj2MBXgzgcFy826NL0Einz9Y1IN8PnrgUE1Ds19Gyi0D7a X-Received: by 2002:a17:906:76c9:b0:726:f0f2:6504 with SMTP id q9-20020a17090676c900b00726f0f26504mr29009666ejn.213.1658234073299; Tue, 19 Jul 2022 05:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658234073; cv=none; d=google.com; s=arc-20160816; b=NWt/jG/vTNPRWQFVThjubmziymX95++bGvMGmlPtomtaGBIxCjfBAbU+6XGb4CcGiY knDfnZT7CH444zOtGfiL4jkNZxGlefrILji0hRd6Z6x7hKZ8wdBTn/JuRky2lSM7iDMP YecXQ1TRQo1ee/TNQo390C9LaQDLyLCvyiOV8/GWNeCfyjVaEVmuSmERqOQJEKEwM3Yh o8uck/lPULzaY3H/VbwgijcKGAipjaWETWbhsc7tTtBMABuOUWQ1pEk5lpQGY2pNGDvX IUvJaqc/SDr9FyYUMzZ2PsOeYVZyWUIx0EjyvvlYG4k+YasNlqJEqBJY+PYl6Pa/5KIG 586A== 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=eFDplQAn5BVz1XoXRKKiqGzqVVh0ulgXAW9dfFJi3Ck=; b=s1JX5TVIf9UN1twO8AnG9jF3WT17shddPZzpv2ravD/R+Rd32wVABMJzy7JxpYqTUU 8vwBKkoj6ITOvfPvA/oXwJBhJw7jGhAMI9wQM8KS5H149Nwkt6hq3VFzz2Qfmp9I7kLe mUhpZ0/BIj71B6U+It+nFf4tSTKcPYcZv8AbzTEKiU8epfnfklz0cF2+A1LTkk8hVpHE yYTyZM2GYijdROZba11xZ1gpONpiZhYBYYidvyvvm/cNptxNwWp1gThGyYW3wRGevGks SZLBBs6oXKIiUVOswcTdzFACMwFVH8yEOZIlR+VlgHhlpoDBlWQ2Hd5UGi1klv6hPZ2y nZxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xl5+ixcT; 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 h10-20020aa7cdca000000b0043a96be1dc0si16952826edw.111.2022.07.19.05.34.07; Tue, 19 Jul 2022 05:34:33 -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=Xl5+ixcT; 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 S239995AbiGSM0k (ORCPT + 99 others); Tue, 19 Jul 2022 08:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239688AbiGSMYL (ORCPT ); Tue, 19 Jul 2022 08:24:11 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 753A94F6B4; Tue, 19 Jul 2022 05:08:59 -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 sin.source.kernel.org (Postfix) with ESMTPS id 23404CE1BE4; Tue, 19 Jul 2022 12:07:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28253C341C6; Tue, 19 Jul 2022 12:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232467; bh=EagEinv4UePaI3RSHvxrisUpYgtR4TzqlnWpdLHNqgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xl5+ixcTwD2cnvLiDuvxOmvCHWIh7w861IPHltSo2q2HU5nKXTu/geluH7PFhgmFk MEvw3qQpQC2EuBh4OlVY/ySeEUrtSXKuN8wDx07yyRXmtXZpxqgExyO6Jf52ggAfn7 Rq0U1kG67dzar2DCYZO6GrlzNl00CphRnzcDmkbo= 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 5.10 068/112] seg6: fix skb checksum evaluation in SRH encapsulation/insertion Date: Tue, 19 Jul 2022 13:54:01 +0200 Message-Id: <20220719114633.088779949@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@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 4d4399c5c5ea..40ac23242c37 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -188,6 +188,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; @@ -240,6 +242,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; @@ -301,7 +305,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