Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4447643imw; Tue, 19 Jul 2022 06:50:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1strI0tC1Ch8gogMyBWjIXRI3kVnERWHc7n/ia9hdVRtdZDUtXkCrHWQMpPbLyPf28MePYl X-Received: by 2002:a17:907:1def:b0:72b:33e6:46d6 with SMTP id og47-20020a1709071def00b0072b33e646d6mr30041332ejc.414.1658238624541; Tue, 19 Jul 2022 06:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238624; cv=none; d=google.com; s=arc-20160816; b=HfWZtKvRK+7nfTLzdgGLF0D2/qBhj28ffAKVUdP6Knw2UlIW91yFMPZNeCw1HeUcT0 RCkb81gdhJTb5uFnw0pNB8YaX6YUa6mg97DUcVYv72ngrjqhthzXGI6yUAUqdJHfHIg5 HrrApzCbaM+L/QW8sYgHBvn4p/CeHjivl0mcpIdDDyUblulFTMdFxnGLSmD6Z5EVbOyW lnVgJSk/FNR1UTN/KjGXYPeaDhQLPAyMP3wDC2iz3QNMGp1uy34o+YhJ5yYh8HnK2wiR jSd8NfW8LlozCV+AJJoGf3H2dRzodxQkvdCP6lKgLMRZbwH9RhUBpgoZJC1XxHdvhbJI 8sqg== 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=HX5ewVC6fOipFC4QayqZQ4+BjkFCdBJJYyMkuZEwiuo=; b=oUZsZK3Qd6wRu3kZ3dFV7789HWd+oAi8y9tmStW8DMVn3CngbD+yqYvtQHTLo+E/sJ 7zZnO06stTeo1vp5chSpXF1iHWjGruhmSVbqWbiF0u7PsUYvVXA3YbH+b5px3arctVlv 1YwD05z5XrAdBYISMfy52D+GWnhNb0EB2WlhuyojL9hXsiybZqX4sDbxKCBwhUXf1FKI CZZt22hoRoPnSua28k8OssNdIp9jeotD3OIxCNAZT1cwUsEYNwm04nYxC4MpIhmTqAf7 1Nl16YDouIboBq9imktxw2xQ7OR8CM1uv1ERcKiV7Fwv1po1sPA5RUxCiJUjqdvLnpHg ubgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=flwQ4okA; 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 dx20-20020a170906a85400b0072b3b4f015csi16657742ejb.311.2022.07.19.06.49.59; Tue, 19 Jul 2022 06:50:24 -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=flwQ4okA; 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 S241127AbiGSMi4 (ORCPT + 99 others); Tue, 19 Jul 2022 08:38:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240886AbiGSMiR (ORCPT ); Tue, 19 Jul 2022 08:38:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA19A47BB6; Tue, 19 Jul 2022 05:14:49 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E195361632; Tue, 19 Jul 2022 12:14:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECBCC341CB; Tue, 19 Jul 2022 12:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232888; bh=T0O0KgkJt/ofJDvterLLW1GOiWLpCRtQ9l7LyqAHt2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=flwQ4okAf2GhaqLW6QDTmzkn3JpQANn6GzY3gcsLk1CuPf7cz8xJsktzX2ZPTW0SS kj0Hb9/vNvj6wODUDz0I9BQuB5lERk2DH8KhamvD388XSjtDXDBr41L3V79YFGuri6 5m3rX7o6dCjn9dWSojoIG85MRYXlyDx7YzS72Elw= 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.15 101/167] seg6: fix skb checksum evaluation in SRH encapsulation/insertion Date: Tue, 19 Jul 2022 13:53:53 +0200 Message-Id: <20220719114706.195980043@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@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=unavailable 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 d64855010948..e756ba705fd9 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -189,6 +189,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; @@ -241,6 +243,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; @@ -302,7 +306,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)); nf_reset_ct(skb); -- 2.35.1