Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp577111rwp; Wed, 12 Jul 2023 19:20:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlG3C4kVMu051bhUQqc2HA6ye6zuFsA79VidJYyC6BQs9FBuwa/0j6xZCGGCCSMGUU5Hniv/ X-Received: by 2002:a05:6358:9499:b0:134:c530:c2fa with SMTP id i25-20020a056358949900b00134c530c2famr469733rwb.30.1689214822299; Wed, 12 Jul 2023 19:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689214822; cv=none; d=google.com; s=arc-20160816; b=WwDy2g9cjc/KyeGpYhmK1++4BD5AZDcSA649JYog/oUkMhNVnN1Bs5X4YQIOGq5Bdy nGk5E16IJDYLkBAJjskj+vu7F++V3+tL6GO29SjFdz9RLMZroQNI/ZGPfbRceft3S7G7 ZIRpIe3YqXWLZvUZ3OEDKmaYsMPjBBJZ69BEmDnEe9foHffxReIFaVowpetPgVPNl82b 0r7UdT/zIC522F4AUSCMtMPg2g9kyQePIVNJhY8LcRW8/MLSdDMUIw2hw0pHPrSARyJK xv3h7dqFTC92+NeAYFnMZDg6XbMvsSBP4jVqV6/LIIjMleaaVD9qbtc2rTRwYVAt0sCC mF+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=aiS3BGLVDtj4R25tckJIQtyqK9hOLbEea2jDynKrbjU=; fh=swmwYARvwYa6RsY+EHesiFUY2NKK8H6FatzwAU0IpPc=; b=ndsvW3Kx4RrgSy4fpjyDSYqvDE6/HS7eTpVX2ePYxYTCFe8iHZMMjdooRDnboIuQIs +9mwLjWa6OHdWhRS1AeZq7r91bEwXOJ5ttjDaLyT62nF/CXVFD2HkWMCrSHQjKR9tCZ4 OeT2pX26+RV1DalK5PfwJXQZUIg4+ygidbQWDVsMiCXbnFtaLCPMG3KI1dnq6ya1liSV u9xQnhlwRcaUeKYEAs8Ls7chOMbNrw6FwJ8VgoPkjHnRT6aWZe8mUGr+6bkqpfgurgrw AamkLzYr3puThxQFIPErhw3MCErX+2vNSFHrpMzgzE6FgLMLlg8i8Yp9J6Gx8klInALv yn7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=KZMBpTBH; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a630984000000b0055b57fa6d19si4228318pgj.208.2023.07.12.19.20.10; Wed, 12 Jul 2023 19:20:22 -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=@gmail.com header.s=20221208 header.b=KZMBpTBH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233450AbjGMCCh (ORCPT + 99 others); Wed, 12 Jul 2023 22:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232178AbjGMCCg (ORCPT ); Wed, 12 Jul 2023 22:02:36 -0400 Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEF3E1FD6; Wed, 12 Jul 2023 19:02:34 -0700 (PDT) Received: by mail-vs1-xe32.google.com with SMTP id ada2fe7eead31-444c5209861so114471137.2; Wed, 12 Jul 2023 19:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689213754; x=1691805754; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aiS3BGLVDtj4R25tckJIQtyqK9hOLbEea2jDynKrbjU=; b=KZMBpTBH33didekshXEgRJxJXueNDxLw+OpJOIIGIFg19vFpc8eHiiFgaqQzvx0eC2 y28J42zKZ35/vfYYazEAvbf1np9k5Z2RZ7MJw1CTLZVgLIdWI9htYO+6ZMZSufdsQPS0 T0VO1cew0ZSA8Ou/So3CxboIfYIBMoDu2mOpgQx50brRYWJEv6LgmlHKKylIm6Amzvq9 JCXGdD7TQXYBjwQ0cBtz6rpQKcwmvT6C1osF8oPIN2qlEn/qCq+uhNSaBx+/16jUWVyP ugwYZ/KFo7TH83eHvL0ZXk+YlCBe9HWzpSOdU/2IPJz8sgbiqPdf5Qzxavev9KgOKEA0 mwcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689213754; x=1691805754; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aiS3BGLVDtj4R25tckJIQtyqK9hOLbEea2jDynKrbjU=; b=Fg9EW0+h2YxIk6KXPCZaKdMLZLP9aD6KyKPIb9h0iaa/uhdrx8JHJALsUhLJl/oT0r OrpXJyrJqiPhPY12kPNqX1QCdGLxyL7SaQ/SUaRhH/pJTB1vf8yUkCnVs7bFqhs+ucFF sWXH2TkfWgW/IXQtOSSd+GXE8su7AoFPOwVDyeHqDit01fY9yO8cT6/N+DIfWrF7/2kL pB4DVZP/+tv1FYWXTkrCdFR5hNhV96smc93wph5y2eMXjPWGzSGVKMw7M83H18qDfitI EybEtIi+6wQe4ePyQMXp5Wy6dwWHSSS2QVUtwEuZVRyXbamsDueZRDfqLtmShPGbsFT7 Rg6w== X-Gm-Message-State: ABy/qLYxrdpCGsTvvt8mbDdNDN3+voEgjkfX9iN5+5FUX6hUpdAaqk0J HGgX6vsamD0+Idfbs62GTiwiUyQ2pTOO7315Ycwucy0UxcQ= X-Received: by 2002:a67:ef99:0:b0:443:5bec:a2fd with SMTP id r25-20020a67ef99000000b004435beca2fdmr270251vsp.18.1689213753738; Wed, 12 Jul 2023 19:02:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Willem de Bruijn Date: Wed, 12 Jul 2023 22:01:57 -0400 Message-ID: Subject: Re: [PATCH net] gso: fix GSO_DODGY bit handling for related protocols To: Yan Zhai Cc: "open list:NETWORKING [TCP]" , 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 , open list , "open list:SCTP PROTOCOL" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Wed, Jul 12, 2023 at 9:55=E2=80=AFPM Yan Zhai wrote= : > > 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. These two things should not be conflated. Only the USO fix is strictly needed to fix the reported issue. > 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 packet= s.") Link: https://lore.kernel.org/all/CAJPywTKDdjtwkLVUW6LRA2FU912qcDmQOQGt2WaD= o28KzYDg+A@mail.gmail.com/ > Signed-off-by: Yan Zhai > > --- > [1]: > https://lore.kernel.org/all/CAJPywTKDdjtwkLVUW6LRA2FU912qcDmQOQGt2WaDo28K= zYDg+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 =3D DIV_ROUND_UP(skb->len, mss)= ; > + skb_shinfo(skb)->gso_type &=3D ~SKB_GSO_DODGY; > > segs =3D 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 =3D skb_shinfo(skb)->gso_size; Why move the block below this line? > + > + 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 actu= al gso_segs */ > + skb_shinfo(skb)->gso_segs =3D DIV_ROUND_UP(skb->l= en - sizeof(*uh), > + mss); > + skb_shinfo(skb)->gso_type &=3D ~SKB_GSO_DODGY; > + > + segs =3D NULL; > + goto out; > + } else { > + return __udp_gso_segment(skb, features, false); > + } > + } > + The validation should take place inside __udp_gso_segment. Revert the previous patch to always enter that function for USO packets: if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) return __udp_gso_segment(skb, features, false); And in that function decide to return NULL after validation. > if (unlikely(skb->len <=3D 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_bu= ff *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 =3D 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, re= set actual gso_segs */ > + skb_shinfo(skb)->gso_segs =3D DIV_ROUND_U= P(skb->len - sizeof(*uh), > + = mss); > + skb_shinfo(skb)->gso_type &=3D ~SKB_GSO_D= ODGY; > + > + segs =3D NULL; > + goto out; > + } else { > + return __udp_gso_segment(skb, features, t= rue); > + } > + } > + > if (unlikely(skb->len <=3D 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 &=3D ~SKB_GSO_DODGY; > + > segs =3D NULL; > goto out; > } > -- > 2.30.2 >