Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp567645rwp; Wed, 12 Jul 2023 19:05:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlGsZRadqGiM08CBi99SKda8E+TlQOFrj/64IHh09jxSLYgliwKCgM/MEtEdFm5Yh8VkC4mU X-Received: by 2002:a05:6358:6f97:b0:134:cb65:fbbe with SMTP id s23-20020a0563586f9700b00134cb65fbbemr707510rwn.13.1689213950039; Wed, 12 Jul 2023 19:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689213950; cv=none; d=google.com; s=arc-20160816; b=e8Sb+68J9GRfcexiqGFrqBG9UoAP2zi5rgFOfWPmh6IjJVDNhAD1POv1+eIb64O7MW ahwWcB/tcTngJQfEVieYHMw4lvuogmhvCa14AO4lKOx6n21XP2KgZOeij/2mEq8u8zHu JklAbxacxK7ENwlHXhuxasJpWrpSZbl7TkmDO6WUprIZZbtovKEiQ6J2Zwk3QsHuVWnC rC0SNdAqW+PQgch/NZyvfb2/hiSNe68IJgx6ic/8WPSMKM4U8z9mTl1Ck3qJqZhnWrVf wxpoXjNyY0ds1LeQTaxk7pFHmCsU9psNoY1A/sC0hLp33knmClyH668elxLTH41fMV1L VDXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=IC4l+DMQhb6kc5rWIsMuFvnWetpCKotmNlfSav918o4=; fh=RWPiS2/Hmizc5WR4VYzZimP7pf2pfjpYuWb9ZFYmtCc=; b=tuitivXoXxA/g5WBsTeCcA0mNgGhn9kHBJVMPfUVBfjs5eSAg62Cp3RowIVQEgBroy v+hvXoPkL/r5O1oQ14FD0PQOjeBzg88WYkC7FoKoXt649qVWLxnA4UN8D86l2F6sxmNs 0ylb0lwrwPWk647W8MJVZa167MF+kAsbhnQ+jb/ewPwNjNFgCMC1ie4zDslNbaCZUuEl qpFso9HbVdkevLA6p1qbaOzjMOBEvre/h5uTpkiRIu2fabePlZT+xL6I7tPVH7GItYih jJs+8VA++6cODLQX2YszAMxNJsq5vNhP3LSL5n3RQ/flN6hapq1todxj9MCR6gjRiOKH A9Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=VdDCd2rw; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be3-20020a656e43000000b0055c4c9cc01esi4363095pgb.148.2023.07.12.19.05.37; Wed, 12 Jul 2023 19:05:49 -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=@cloudflare.com header.s=google header.b=VdDCd2rw; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233381AbjGMBzd (ORCPT + 99 others); Wed, 12 Jul 2023 21:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231901AbjGMBzb (ORCPT ); Wed, 12 Jul 2023 21:55:31 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B332115 for ; Wed, 12 Jul 2023 18:55:24 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-7653bd3ff2fso22422085a.3 for ; Wed, 12 Jul 2023 18:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1689213323; x=1691805323; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=IC4l+DMQhb6kc5rWIsMuFvnWetpCKotmNlfSav918o4=; b=VdDCd2rwQPbltzkne/8cYfxnkuaCKmFeRcipHkeV5r5b9iyVOJ/o/XOTDIvxXsoZRq kzJrj9I6zxi8mHbcPDLKrJ/iTuQu+OTIzr6ATwW+JkoDfWEFyD+x2vOHh7fxGo4ZF1Xs PvudhpsE7CEWCSNNZfNksQ00yWADTZWPg5X8w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689213323; x=1691805323; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IC4l+DMQhb6kc5rWIsMuFvnWetpCKotmNlfSav918o4=; b=jnXiwHiu6B5WbXKndVP46WSvimQ5ss23eRHbWuMJ8Mul0YIv1W6FdlZKs9rNhZrujM kKCYA/wpVv5PHvWtKchC0spJQ/qmV+8IO7tHASs5x9ykoWct2VM/mCTzkqgye2iZIDec fZJKfysWvNN9ATGbFTC3/ozsaTPOcVmojCe4tyxdluQkKRsot1e5aEp2v+J6Z6R6xH+T 84qh9CWtDwNoVKTKOhWwahJqSQ+V0B4J988UrQAvJ37xfisLeAhXa1GHFlDDUaa1i/bn f914T6oYNTezoRcLbutzILilIN6OwzAjLwt5EesQyf6V+QU8NTmawUMjC7La7HV6MK3f JQcw== X-Gm-Message-State: ABy/qLao8ATquhZtgyffvVz4LjOGXSIGHyEH8YXyikHmmxg8xchkfoYt IHgJr8U1H9OivdNEg7sWchNJCUTzsbAY3uqTG+YJ2A== X-Received: by 2002:a05:620a:198e:b0:767:173e:9 with SMTP id bm14-20020a05620a198e00b00767173e0009mr233241qkb.58.1689213323421; Wed, 12 Jul 2023 18:55:23 -0700 (PDT) Received: from debian.debian ([140.141.197.139]) by smtp.gmail.com with ESMTPSA id e1-20020a05620a208100b0076729e726cbsm2580913qka.22.2023.07.12.18.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 18:55:22 -0700 (PDT) Date: Wed, 12 Jul 2023 18:55:20 -0700 From: Yan Zhai To: "open list:NETWORKING [TCP]" Cc: kernel-team@cloudflare.com, Eric Dumazet , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Marcelo Ricardo Leitner , Xin Long , Herbert Xu , Andrew Melnychenko , Jason Wang , Willem de Bruijn , open list , "open list:SCTP PROTOCOL" Subject: [PATCH net] gso: fix GSO_DODGY bit handling for related protocols Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 SKB_GSO_DODGY bit indicates a GSO packet comes from an untrusted source. The canonical way is to recompute the gso_segs to avoid device driver issues. Afterwards, the DODGY bit can be removed to avoid re-check at the egress of later devices, e.g. packets can egress to a vlan device backed by a real NIC. Commit 1fd54773c267 ("udp: allow header check for dodgy GSO_UDP_L4 packets.") checks DODGY bit for UDP, but for packets that can be fed directly to the device after gso_segs reset, it actually falls through to fragmentation [1]. Commit 90017accff61 ("sctp: Add GSO support") and commit 3820c3f3e417 ("[TCP]: Reset gso_segs if packet is dodgy") both didn't remove the DODGY bit after recomputing gso_segs. This change fixes the GSO_UDP_L4 handling case, and remove the DODGY bit at other places. Fixes: 90017accff61 ("sctp: Add GSO support") Fixes: 3820c3f3e417 ("[TCP]: Reset gso_segs if packet is dodgy") Fixes: 1fd54773c267 ("udp: allow header check for dodgy GSO_UDP_L4 packets.") Signed-off-by: Yan Zhai --- [1]: https://lore.kernel.org/all/CAJPywTKDdjtwkLVUW6LRA2FU912qcDmQOQGt2WaDo28KzYDg+A@mail.gmail.com/ --- net/ipv4/tcp_offload.c | 1 + net/ipv4/udp_offload.c | 19 +++++++++++++++---- net/ipv6/udp_offload.c | 19 +++++++++++++++---- net/sctp/offload.c | 2 ++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 8311c38267b5..f9b93708c22e 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -87,6 +87,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, /* Packet is from an untrusted source, reset gso_segs. */ skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss); + skb_shinfo(skb)->gso_type &= ~SKB_GSO_DODGY; segs = NULL; goto out; diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 75aa4de5b731..bd29cf19bb6b 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -388,11 +388,22 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, if (!pskb_may_pull(skb, sizeof(struct udphdr))) goto out; - if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 && - !skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) - return __udp_gso_segment(skb, features, false); - mss = skb_shinfo(skb)->gso_size; + + if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) { + if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) { + /* Packet is from an untrusted source, reset actual gso_segs */ + skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len - sizeof(*uh), + mss); + skb_shinfo(skb)->gso_type &= ~SKB_GSO_DODGY; + + segs = NULL; + goto out; + } else { + return __udp_gso_segment(skb, features, false); + } + } + if (unlikely(skb->len <= mss)) goto out; diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index ad3b8726873e..6857d9f7bd06 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -43,11 +43,22 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, if (!pskb_may_pull(skb, sizeof(struct udphdr))) goto out; - if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 && - !skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) - return __udp_gso_segment(skb, features, true); - mss = skb_shinfo(skb)->gso_size; + + if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) { + if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) { + /* Packet is from an untrusted source, reset actual gso_segs */ + skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len - sizeof(*uh), + mss); + skb_shinfo(skb)->gso_type &= ~SKB_GSO_DODGY; + + segs = NULL; + goto out; + } else { + return __udp_gso_segment(skb, features, true); + } + } + if (unlikely(skb->len <= mss)) goto out; diff --git a/net/sctp/offload.c b/net/sctp/offload.c index 502095173d88..3d2b44db0d42 100644 --- a/net/sctp/offload.c +++ b/net/sctp/offload.c @@ -65,6 +65,8 @@ static struct sk_buff *sctp_gso_segment(struct sk_buff *skb, skb_walk_frags(skb, frag_iter) pinfo->gso_segs++; + pinfo->gso_type &= ~SKB_GSO_DODGY; + segs = NULL; goto out; } -- 2.30.2