From patchwork Tue Mar 26 11:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 13603960 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 136146BFB3 for ; Tue, 26 Mar 2024 11:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452850; cv=none; b=IA5IU0UWl23gAlVlKdMcjL9oJmpVUatM/wzcy4g05iBSdNNTMQggL+e8hXNeT+rZlnp5tEUglq1RsJ6gs0Lsc2BnlyGxo3Pw0wEBA3yejLCEElHc/ZKiO9a4JDXK9a8Ht91HqEK7nHIm0vGNWp3ipc1i6XpY/MkE2HhsFouUv4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452850; c=relaxed/simple; bh=x4YH3OhXZnwtL2VG55Qju0hX04ZVvudFCYZzBZkH1gg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kF8Cztfn5GFucGYa8zxCzQdEE336WIM3LpNpWbS4Byr2aaYciTNW7ktVHvZZaUP8fsK67nXG+OZ0xsNwFWaR5WO14b8O0mpYf0WGPHc5yzRKHmTGvJhCXmaREeAab2MZAc0z8g9znS388oD4U861d8PUIyf5uLkkaDuKHboDjlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SSmF2G9B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SSmF2G9B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 430F3C433C7; Tue, 26 Mar 2024 11:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711452849; bh=x4YH3OhXZnwtL2VG55Qju0hX04ZVvudFCYZzBZkH1gg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SSmF2G9BiP3gm9s5gd5uarc6RKYeVhUflhmouk90mL2o9zW9QOSjlsDrSK1+P99W+ oqTf5xZVZfAlbWyucLUM6gDfMLnPXSczI3ajettxxt1q52Fy43I2aR45MrrG8ye46u h32L8gF5dnRzT7lrbV6e123HkvT7Czi3G+0HO9GXV+2be+yGt4gN4KUDpeabpDtyzC tHSrCOfke7mA5ljrBhi/igKSEUielV7SYMeVF6koTVZepsmZ2NTqlXUDkRxtwvi1Mx RTMWjT/6U/dkTDGhdt1rnLbgfgu/KgYYe/MCPLmFOhc45yOK5HTzL5iZm9NjxXFIs9 I8ztLxE82dWzg== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com Cc: Antoine Tenart , steffen.klassert@secunet.com, willemdebruijn.kernel@gmail.com, netdev@vger.kernel.org, Willem de Bruijn Subject: [PATCH net v4 1/5] udp: do not accept non-tunnel GSO skbs landing in a tunnel Date: Tue, 26 Mar 2024 12:33:58 +0100 Message-ID: <20240326113403.397786-2-atenart@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326113403.397786-1-atenart@kernel.org> References: <20240326113403.397786-1-atenart@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When rx-udp-gro-forwarding is enabled UDP packets might be GROed when being forwarded. If such packets might land in a tunnel this can cause various issues and udp_gro_receive makes sure this isn't the case by looking for a matching socket. This is performed in udp4/6_gro_lookup_skb but only in the current netns. This is an issue with tunneled packets when the endpoint is in another netns. In such cases the packets will be GROed at the UDP level, which leads to various issues later on. The same thing can happen with rx-gro-list. We saw this with geneve packets being GROed at the UDP level. In such case gso_size is set; later the packet goes through the geneve rx path, the geneve header is pulled, the offset are adjusted and frag_list skbs are not adjusted with regard to geneve. When those skbs hit skb_fragment, it will misbehave. Different outcomes are possible depending on what the GROed skbs look like; from corrupted packets to kernel crashes. One example is a BUG_ON[1] triggered in skb_segment while processing the frag_list. Because gso_size is wrong (geneve header was pulled) skb_segment thinks there is "geneve header size" of data in frag_list, although it's in fact the next packet. The BUG_ON itself has nothing to do with the issue. This is only one of the potential issues. Looking up for a matching socket in udp_gro_receive is fragile: the lookup could be extended to all netns (not speaking about performances) but nothing prevents those packets from being modified in between and we could still not find a matching socket. It's OK to keep the current logic there as it should cover most cases but we also need to make sure we handle tunnel packets being GROed too early. This is done by extending the checks in udp_unexpected_gso: GSO packets lacking the SKB_GSO_UDP_TUNNEL/_CSUM bits and landing in a tunnel must be segmented. [1] kernel BUG at net/core/skbuff.c:4408! RIP: 0010:skb_segment+0xd2a/0xf70 __udp_gso_segment+0xaa/0x560 Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.") Fixes: 36707061d6ba ("udp: allow forwarding of plain (non-fraglisted) UDP GRO packets") Signed-off-by: Antoine Tenart Reviewed-by: Willem de Bruijn --- include/linux/udp.h | 28 ++++++++++++++++++++++++++++ net/ipv4/udp.c | 7 +++++++ net/ipv4/udp_offload.c | 6 ++++-- net/ipv6/udp.c | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/linux/udp.h b/include/linux/udp.h index 3748e82b627b..17539d089666 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h @@ -150,6 +150,24 @@ static inline void udp_cmsg_recv(struct msghdr *msg, struct sock *sk, } } +DECLARE_STATIC_KEY_FALSE(udp_encap_needed_key); +#if IS_ENABLED(CONFIG_IPV6) +DECLARE_STATIC_KEY_FALSE(udpv6_encap_needed_key); +#endif + +static inline bool udp_encap_needed(void) +{ + if (static_branch_unlikely(&udp_encap_needed_key)) + return true; + +#if IS_ENABLED(CONFIG_IPV6) + if (static_branch_unlikely(&udpv6_encap_needed_key)) + return true; +#endif + + return false; +} + static inline bool udp_unexpected_gso(struct sock *sk, struct sk_buff *skb) { if (!skb_is_gso(skb)) @@ -163,6 +181,16 @@ static inline bool udp_unexpected_gso(struct sock *sk, struct sk_buff *skb) !udp_test_bit(ACCEPT_FRAGLIST, sk)) return true; + /* GSO packets lacking the SKB_GSO_UDP_TUNNEL/_CSUM bits might still + * land in a tunnel as the socket check in udp_gro_receive cannot be + * foolproof. + */ + if (udp_encap_needed() && + READ_ONCE(udp_sk(sk)->encap_rcv) && + !(skb_shinfo(skb)->gso_type & + (SKB_GSO_UDP_TUNNEL | SKB_GSO_UDP_TUNNEL_CSUM))) + return true; + return false; } diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 661d0e0d273f..c02bf011d4a6 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -582,6 +582,13 @@ static inline bool __udp_is_mcast_sock(struct net *net, const struct sock *sk, } DEFINE_STATIC_KEY_FALSE(udp_encap_needed_key); +EXPORT_SYMBOL(udp_encap_needed_key); + +#if IS_ENABLED(CONFIG_IPV6) +DEFINE_STATIC_KEY_FALSE(udpv6_encap_needed_key); +EXPORT_SYMBOL(udpv6_encap_needed_key); +#endif + void udp_encap_enable(void) { static_branch_inc(&udp_encap_needed_key); diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index b9880743765c..e9719afe91cf 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -551,8 +551,10 @@ struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, unsigned int off = skb_gro_offset(skb); int flush = 1; - /* we can do L4 aggregation only if the packet can't land in a tunnel - * otherwise we could corrupt the inner stream + /* We can do L4 aggregation only if the packet can't land in a tunnel + * otherwise we could corrupt the inner stream. Detecting such packets + * cannot be foolproof and the aggregation might still happen in some + * cases. Such packets should be caught in udp_unexpected_gso later. */ NAPI_GRO_CB(skb)->is_flist = 0; if (!sk || !udp_sk(sk)->gro_receive) { diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 7c1e6469d091..8b1dd7f51249 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -447,7 +447,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, goto try_again; } -DEFINE_STATIC_KEY_FALSE(udpv6_encap_needed_key); +DECLARE_STATIC_KEY_FALSE(udpv6_encap_needed_key); void udpv6_encap_enable(void) { static_branch_inc(&udpv6_encap_needed_key); From patchwork Tue Mar 26 11:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 13603961 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD5E056452 for ; Tue, 26 Mar 2024 11:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452852; cv=none; b=tJlvp/+3le1DeZU58cJanZSL4GAOs3qaSg21doc+ZMDZHxkLioE9EG9v5vk4PvLKqwrUmEKIQnQAM3wDjztaSFB/GW09ZRigQV+YNKKvc/ZXrYcf9tApe3biyPd8VnDy9M7JNzjBUtJSndSQ8hPnyTzDFWE2Ap5HW12vTKHRhiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452852; c=relaxed/simple; bh=9AGZg+Pbqwe5RkEz1eQH+VUG1GXVEpPCjOgQ8W1uVY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gLGuowG5VxqUPUgN7rtQaVNm5b0unRFNRLUSzUmXcB71vhaVco2/2rVgoo1Rmq2AGBYFF2fiM3yZRb+HXWNkh3zQglCmC/KyFzfAJqfa5AZV++afV1HugbOnypQn/n4h2swvjND9kaBafZr3pDy8EGhrihkNi07bhev2P5iTfCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c5airom1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c5airom1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2D74C433C7; Tue, 26 Mar 2024 11:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711452852; bh=9AGZg+Pbqwe5RkEz1eQH+VUG1GXVEpPCjOgQ8W1uVY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c5airom1AIzxqXyoNJv3CWbN28BpUAQMTE3KwKnF8byzRkm9/R6OQ5dfAQ7bYiOjy amnGX15vn5zocJE3RUCHK1qORYcAlHHl3vAbtvgmewRtF5geEmeFWMaBq5BVhirE+O zgo2dqnQnaovggrhS9kEiJLsGyl5+t88FMDzr6MJ/Urc/4iKhe8PbyhA6ozqGNEmJX YCYlMg9vPQ2znQDokVkO3CP56ZyUG8s1KLN+3pv6OslmwDGIsxaNFM3VsfaiVqP5Lc Rs9hqnPVpep+X31yyRl5Y3CdGqbAU03uk02gc/dSf8iLKW4r9Op41gf0uW28LEVNGc ymbpFAug1leVw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com Cc: Antoine Tenart , steffen.klassert@secunet.com, willemdebruijn.kernel@gmail.com, netdev@vger.kernel.org, Willem de Bruijn Subject: [PATCH net v4 2/5] gro: fix ownership transfer Date: Tue, 26 Mar 2024 12:33:59 +0100 Message-ID: <20240326113403.397786-3-atenart@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326113403.397786-1-atenart@kernel.org> References: <20240326113403.397786-1-atenart@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org If packets are GROed with fraglist they might be segmented later on and continue their journey in the stack. In skb_segment_list those skbs can be reused as-is. This is an issue as their destructor was removed in skb_gro_receive_list but not the reference to their socket, and then they can't be orphaned. Fix this by also removing the reference to the socket. For example this could be observed, kernel BUG at include/linux/skbuff.h:3131! (skb_orphan) RIP: 0010:ip6_rcv_core+0x11bc/0x19a0 Call Trace: ipv6_list_rcv+0x250/0x3f0 __netif_receive_skb_list_core+0x49d/0x8f0 netif_receive_skb_list_internal+0x634/0xd40 napi_complete_done+0x1d2/0x7d0 gro_cell_poll+0x118/0x1f0 A similar construction is found in skb_gro_receive, apply the same change there. Fixes: 5e10da5385d2 ("skbuff: allow 'slow_gro' for skb carring sock reference") Signed-off-by: Antoine Tenart Reviewed-by: Willem de Bruijn --- net/core/gro.c | 3 ++- net/ipv4/udp_offload.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/net/core/gro.c b/net/core/gro.c index ee30d4f0c038..83f35d99a682 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -192,8 +192,9 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) } merge: - /* sk owenrship - if any - completely transferred to the aggregated packet */ + /* sk ownership - if any - completely transferred to the aggregated packet */ skb->destructor = NULL; + skb->sk = NULL; delta_truesize = skb->truesize; if (offset > headlen) { unsigned int eat = offset - headlen; diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index e9719afe91cf..3bb69464930b 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -449,8 +449,9 @@ static int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb) NAPI_GRO_CB(p)->count++; p->data_len += skb->len; - /* sk owenrship - if any - completely transferred to the aggregated packet */ + /* sk ownership - if any - completely transferred to the aggregated packet */ skb->destructor = NULL; + skb->sk = NULL; p->truesize += skb->truesize; p->len += skb->len; From patchwork Tue Mar 26 11:34:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 13603962 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A45237641C for ; Tue, 26 Mar 2024 11:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452855; cv=none; b=CTEmh59Bk2nKi0KlHTHQyUa7ARTZtIncGfObL5kweMBTSQbPn+LBEpIWPnfgnv4XSlmaLDD72o+rSCbOwrnfVVKpoPuNQKoKIQORem7v+p1u2mGGZIFB2uyopxBWcif63BxamtkutaSse6nRQMNQ4dpVzijXJaiXh4w065NJc8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452855; c=relaxed/simple; bh=olpSxbuDYHiKY9yUfuosPYFrh40NPdrcXw4pz6WYTX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MmaQZ7Hzg0amkBZ78E97KTdq9cfLPxhRuof9Qjuiklqe56BSOlbheRZciUjHQ+2Lw9Afeb2craMSr6SBFpSc2mnVzckJVkONjwq4JFtmdFl6zwWdGorIwjfYAlLxCCsxcq8oToyWyC/5GhlPBbTQ9Zo1IiB3/dRFc7oNxCEScTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dSGOu0b6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dSGOu0b6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32D71C433F1; Tue, 26 Mar 2024 11:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711452855; bh=olpSxbuDYHiKY9yUfuosPYFrh40NPdrcXw4pz6WYTX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dSGOu0b6EoH+HEbOwLoVD0BKZxH8jISjzlDoY4hQJKLIZZ+tizgsBfGMWTtQPDhfA dr/7xJqqjDfo+Qfp7qXp+KPBPFd6TSAgMJ/NRl5O6baDayl6hUaeQbmkgIlR46+Fp+ fJ/8PIjcRyQmyZDPCVH/kg655JUG1uXKYbyX5Ybk0FAbh2sK0tZbUB7L6ygTZVkKYz NGQFVC3iwQ5W+hBtacR2iQ2DJR/Vcr0/NVjnd0bOiOiGoawEDx4JyBeOgQhbvZeEML t6MmpnpKCXr3V9lLnb+AIr6MYyRrPk5L09K0IkXw8+neq+D3ExzHNiveOPlHeTbJx0 Q4WbpjvRojEtQ== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com Cc: Antoine Tenart , steffen.klassert@secunet.com, willemdebruijn.kernel@gmail.com, netdev@vger.kernel.org Subject: [PATCH net v4 3/5] udp: do not transition UDP GRO fraglist partial checksums to unnecessary Date: Tue, 26 Mar 2024 12:34:00 +0100 Message-ID: <20240326113403.397786-4-atenart@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326113403.397786-1-atenart@kernel.org> References: <20240326113403.397786-1-atenart@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org UDP GRO validates checksums and in udp4/6_gro_complete fraglist packets are converted to CHECKSUM_UNNECESSARY to avoid later checks. However this is an issue for CHECKSUM_PARTIAL packets as they can be looped in an egress path and then their partial checksums are not fixed. Different issues can be observed, from invalid checksum on packets to traces like: gen01: hw csum failure skb len=3008 headroom=160 headlen=1376 tailroom=0 mac=(106,14) net=(120,40) trans=160 shinfo(txflags=0 nr_frags=0 gso(size=0 type=0 segs=0)) csum(0xffff232e ip_summed=2 complete_sw=0 valid=0 level=0) hash(0x77e3d716 sw=1 l4=1) proto=0x86dd pkttype=0 iif=12 ... Fix this by only converting CHECKSUM_NONE packets to CHECKSUM_UNNECESSARY by reusing __skb_incr_checksum_unnecessary. All other checksum types are kept as-is, including CHECKSUM_COMPLETE as fraglist packets being segmented back would have their skb->csum valid. Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.") Signed-off-by: Antoine Tenart Reviewed-by: Willem de Bruijn --- net/ipv4/udp_offload.c | 8 +------- net/ipv6/udp_offload.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 3bb69464930b..548476d78237 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -722,13 +722,7 @@ INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff) skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4); skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; - if (skb->ip_summed == CHECKSUM_UNNECESSARY) { - if (skb->csum_level < SKB_MAX_CSUM_LEVEL) - skb->csum_level++; - } else { - skb->ip_summed = CHECKSUM_UNNECESSARY; - skb->csum_level = 0; - } + __skb_incr_checksum_unnecessary(skb); return 0; } diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index 312bcaeea96f..bbd347de00b4 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -174,13 +174,7 @@ INDIRECT_CALLABLE_SCOPE int udp6_gro_complete(struct sk_buff *skb, int nhoff) skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4); skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; - if (skb->ip_summed == CHECKSUM_UNNECESSARY) { - if (skb->csum_level < SKB_MAX_CSUM_LEVEL) - skb->csum_level++; - } else { - skb->ip_summed = CHECKSUM_UNNECESSARY; - skb->csum_level = 0; - } + __skb_incr_checksum_unnecessary(skb); return 0; } From patchwork Tue Mar 26 11:34:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 13603963 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7335B6CDB6 for ; Tue, 26 Mar 2024 11:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452858; cv=none; b=AlRXEKZ7T+sZyR4l5eK3DPVmxPYG+Fnhtxd22hdh0V9lGfGrPMu7b43cwcSXFKgVtLJQBAnd1IOLFy9wcyIf4Qj7BxBWzEZLTYvZ+eKadNHXvAtY6neumgvvA2YgNwejFsShXtBXN+66N8Ea2bcWJTGm3dwJTlzhvnQgg5JsyOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452858; c=relaxed/simple; bh=lNZ3GsF+2FDIGqDK/pc65J09dJNN1ybvqZZZwXWhNVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c7E8xEpTR2YjbaphcCMmIah6FcR1YZlf2hXk0Ut1sKq4fcAJcvGpJayI3q8j2NjTNUbKj1lOTgleQGGfSdHap6ffR330Ry437zO+O11yIwGJ7WB/+Sg1dICDutKJ3gRekgwI2m8yK6sUDWkhFZmzZ1+Z+K7t0SGE8sMZKcJXEfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oUczJQ3K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oUczJQ3K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6A89C43601; Tue, 26 Mar 2024 11:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711452858; bh=lNZ3GsF+2FDIGqDK/pc65J09dJNN1ybvqZZZwXWhNVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oUczJQ3KZQAH8g5O3nUq/MuoItBMo81KOxqK7O+7oVJO2aArqbkFTTtge0SIJdry0 60Ka34ypjGGO8IlqofrWsuckRoKUgnoCjAhlwn/0auygqQLL5x0/EXhht2Q+340eGF jl1j/h8tu2rI1D6vSU0H2K8de2Ac0lssUsuWCWXBt3s25vi6T15vBgvXegCAPXRw5t AeniVmV91tStojlc5TdiFTrwvXITy3lCnILkPScBXqnBku5a28KKXuBAitbvjsHUC/ ZjCd2m3iILSGtknNSMLJT72eHESoJmpXznLhkcBX+wXCOdRtunkLeurpxxtmkvVxDb rQhO/XXtJVhig== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com Cc: Antoine Tenart , steffen.klassert@secunet.com, willemdebruijn.kernel@gmail.com, netdev@vger.kernel.org, Willem de Bruijn Subject: [PATCH net v4 4/5] udp: prevent local UDP tunnel packets from being GROed Date: Tue, 26 Mar 2024 12:34:01 +0100 Message-ID: <20240326113403.397786-5-atenart@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326113403.397786-1-atenart@kernel.org> References: <20240326113403.397786-1-atenart@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org GRO has a fundamental issue with UDP tunnel packets as it can't detect those in a foolproof way and GRO could happen before they reach the tunnel endpoint. Previous commits have fixed issues when UDP tunnel packets come from a remote host, but if those packets are issued locally they could run into checksum issues. If the inner packet has a partial checksum the information will be lost in the GRO logic, either in udp4/6_gro_complete or in udp_gro_complete_segment and packets will have an invalid checksum when leaving the host. Prevent local UDP tunnel packets from ever being GROed at the outer UDP level. Due to skb->encapsulation being wrongly used in some drivers this is actually only preventing UDP tunnel packets with a partial checksum to be GROed (see iptunnel_handle_offloads) but those were also the packets triggering issues so in practice this should be sufficient. Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.") Fixes: 36707061d6ba ("udp: allow forwarding of plain (non-fraglisted) UDP GRO packets") Suggested-by: Paolo Abeni Signed-off-by: Antoine Tenart Reviewed-by: Willem de Bruijn --- net/ipv4/udp_offload.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 548476d78237..3498dd1d0694 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -559,6 +559,12 @@ struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, */ NAPI_GRO_CB(skb)->is_flist = 0; if (!sk || !udp_sk(sk)->gro_receive) { + /* If the packet was locally encapsulated in a UDP tunnel that + * wasn't detected above, do not GRO. + */ + if (skb->encapsulation) + goto out; + if (skb->dev->features & NETIF_F_GRO_FRAGLIST) NAPI_GRO_CB(skb)->is_flist = sk ? !udp_test_bit(GRO_ENABLED, sk) : 1; From patchwork Tue Mar 26 11:34:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 13603964 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7646056771 for ; Tue, 26 Mar 2024 11:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452861; cv=none; b=GS+WTCii4JXVaeyRla5qEZxYBtzJXKH6TkRk5XXi+Sw/mvFnaygIAqHqKVkNrRk37g1YcMdsrIXliZkhHlAqTpZKWLlOcxRITcmP58n92OsJsnbCR1Y6clxnrCYbC3q9c3j/O4gtA1sdqJDpnGUKTmsGIGnksZZ8rin2X7Yq9YY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711452861; c=relaxed/simple; bh=Ld5ZYdJDMtAhbqbX4VbZ8afAYRtQJsDM/MORcFOZQk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NGsIHRc26Pvuf5BZjrgpDd31iDurnIvdxJ1iTSN0+3C1XUaA9L4O/zKK/SuO//jXkvkz/jxerPbxin1t0ZTQyzFLuOOUjs71hbahJ3fYtnjlAO1A2C3mnamXzewq5Q8K7kZNpJznU6kryrqS2lgQ6mrpCc0t2KTAreuzRt1MLL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NA71yI2E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NA71yI2E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1FA9C433C7; Tue, 26 Mar 2024 11:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711452861; bh=Ld5ZYdJDMtAhbqbX4VbZ8afAYRtQJsDM/MORcFOZQk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NA71yI2ERQkxpQ93UmqmuJaRVVasi/ZJQD1H9Ir8mO3SIeSo7kZBi+kvckW88pYAg wFcMCgQ42rbBkqtNzoW4ohFYUE60pD5a0x1YQ5PWbVmvJ9nA+zQiYBADkxfee1Rll4 rcCqdqrbr8pRdIc6jT4PDgS+T7X78nSoLoUqtrSSFOtBBXMNVxgkwUCP1Q7L7Hyp1V pZDbZauo/JvsdyB+NV0gRBvMbkm4xa+HNbmNHY3UP3JahXcB6OlgQVhSKvoJy/oEcl fVS9dpImW6lkzodivk/rTWo86Nkw8Wi1MZRO/q9W2x1gO+RXLKX1KwHmyTXug8Wmvv NWWJawgzBqtJA== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com Cc: Antoine Tenart , steffen.klassert@secunet.com, willemdebruijn.kernel@gmail.com, netdev@vger.kernel.org Subject: [PATCH net v4 5/5] selftests: net: gro fwd: update vxlan GRO test expectations Date: Tue, 26 Mar 2024 12:34:02 +0100 Message-ID: <20240326113403.397786-6-atenart@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326113403.397786-1-atenart@kernel.org> References: <20240326113403.397786-1-atenart@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org UDP tunnel packets can't be GRO in-between their endpoints as this causes different issues. The UDP GRO fwd vxlan tests were relying on this and their expectations have to be fixed. We keep both vxlan tests and expected no GRO from happening. The vxlan UDP GRO bench test was removed as it's not providing any valuable information now. Fixes: a062260a9d5f ("selftests: net: add UDP GRO forwarding self-tests") Signed-off-by: Antoine Tenart --- tools/testing/selftests/net/udpgro_fwd.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/net/udpgro_fwd.sh b/tools/testing/selftests/net/udpgro_fwd.sh index 380cb15e942e..83ed987cff34 100755 --- a/tools/testing/selftests/net/udpgro_fwd.sh +++ b/tools/testing/selftests/net/udpgro_fwd.sh @@ -244,7 +244,7 @@ for family in 4 6; do create_vxlan_pair ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on ip netns exec $NS_DST ethtool -K veth$DST rx-gro-list on - run_test "GRO frag list over UDP tunnel" $OL_NET$DST 1 1 + run_test "GRO frag list over UDP tunnel" $OL_NET$DST 10 10 cleanup # use NAT to circumvent GRO FWD check @@ -258,13 +258,7 @@ for family in 4 6; do # load arp cache before running the test to reduce the amount of # stray traffic on top of the UDP tunnel ip netns exec $NS_SRC $PING -q -c 1 $OL_NET$DST_NAT >/dev/null - run_test "GRO fwd over UDP tunnel" $OL_NET$DST_NAT 1 1 $OL_NET$DST - cleanup - - create_vxlan_pair - run_bench "UDP tunnel fwd perf" $OL_NET$DST - ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on - run_bench "UDP tunnel GRO fwd perf" $OL_NET$DST + run_test "GRO fwd over UDP tunnel" $OL_NET$DST_NAT 10 10 $OL_NET$DST cleanup done