Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1444950rwp; Thu, 13 Jul 2023 10:56:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgb3dJwYMsa8sMNZ2pvzIDf0JSqTevOUgD0jY6tJzF8ykiO+RuNlned5Phw5A+NNd+zqdm X-Received: by 2002:a17:902:f68c:b0:1b8:c8bc:c81b with SMTP id l12-20020a170902f68c00b001b8c8bcc81bmr438299plg.21.1689271013613; Thu, 13 Jul 2023 10:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689271013; cv=none; d=google.com; s=arc-20160816; b=TeR7QZZEswrd57fURm1LqJ/dczMnWO3p3qR+tv+BUlcDGgYywvmcDNb5rhCrHnlv1n vz4g51rA33D7FLBp6IyPVugDfCcb/5hhSrV8aGG9SAeTMjfsEB1OS2svfNhyZ3FKt+Gj 3EaA5caoQa078nRmXDb2wf20YH+Zs7KbQRVy5V/mtRBTmlhR+t9BbTRA5iYxjW93uboa jHsZagB6t2FurAuKjEfbq20jQZGYR39havrFEk+QQ21VMgWCjLCI63mUZvLBlA+eOvCn h+5+yhYW29dDkrwdJEiB0cL29gHopoLgDq8AemwvpT853flrym6NP2+r90Cc90sQ8CCP Dc5w== 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=y8HL7CUl8Nl4Ioty23RUOK+NanZNksrYlNe7u93OccY=; fh=RWPiS2/Hmizc5WR4VYzZimP7pf2pfjpYuWb9ZFYmtCc=; b=zdtYl9kkQlDngNdQjVKiEjCLvVndOPGR4HZ4FTu05jYZ8xyHT9HBIe6sjzFVRkXAiN wdkF+kvMK0Sfnxa3YCDbNpIJSHGjCD+UClboNM0z3TADWzpYfdkUTAmOT5I5SMEDYRmG vTtrLQiaHvgspEYerj763oR0pRaJUobMGhN4XjzAZC4hsCkYSHHfRjbqvEGzYhPN/hQf /13hWfdSCNaZzRc/XuB4WtVWb+OgAmsZ6LHldPxRji8X8yMCmIknXO5NlNoFw6Aw50rO YoKb4FL+Mw2LuLFlv87BDnje4FB+EDUP4ughyPj3iH5p6AyMmlk9ot544bkTYE5zxlMF aEsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=IgmWTLtW; 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 h5-20020a170902680500b001b54ff18ed1si5274305plk.267.2023.07.13.10.56.40; Thu, 13 Jul 2023 10:56:53 -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=IgmWTLtW; 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 S233707AbjGMR2e (ORCPT + 99 others); Thu, 13 Jul 2023 13:28:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233714AbjGMR2W (ORCPT ); Thu, 13 Jul 2023 13:28:22 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AF4E2D4E for ; Thu, 13 Jul 2023 10:28:04 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-7659db6339eso43005385a.1 for ; Thu, 13 Jul 2023 10:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1689269283; x=1691861283; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=y8HL7CUl8Nl4Ioty23RUOK+NanZNksrYlNe7u93OccY=; b=IgmWTLtWvzxwXmXKucGTWvHEQBwX4I+ktgmiKb5RlTIuEAiLZLITR0bjYejAFKSH3I ZAot26yTteCpMKtiRr65TyvjIDaOxA5L+5hQvVlBFMyuJ4l+Pi3Uvcu0H4luOKn/aAV1 gWZuHm84uvEENnxo0XK6Fnz+Pd/curjNjIggs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689269283; x=1691861283; 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=y8HL7CUl8Nl4Ioty23RUOK+NanZNksrYlNe7u93OccY=; b=Sk7NHbkRb2/VC3iDyOrRGT4JWRWOJDi3b+nQzBGCXki5WP1B4QVNsGHQw/XDTK5Gf7 5Ca0jv2MhaLzDRpDLZJwfpfeCAbJMgSwdpqXXKbxa/+LwA36NQbNHkQtrxCURofF4Wlc rGJcoCm95RVx0e+S7EK4ayvy5BvyODiwjIoDIhflDbcr7k7kv6DFfF/+gEBkPidFQ/hC NUfaUS5F7vJCmeB/uqF55sIRxw7Gz36dbMrrauV/FeFt5xr0ylkdyUX/Nw3/zDT8ootH /8XJFCf7I4qN7pSj9AAK+VVS3HmONzrrrubfJLL5achRenbFEBsiwLRoH4ljE9YVNvS1 EYjg== X-Gm-Message-State: ABy/qLZ8CL7zoyWdqHTH46NyfZ8Zgr9ypxlbsJSAWO1ZA8tH3VvMFADI KpeUBZtHyWf6Sn5R5X4v0ANZIA== X-Received: by 2002:a05:620a:4455:b0:765:5ba6:a5c0 with SMTP id w21-20020a05620a445500b007655ba6a5c0mr429843qkp.14.1689269283055; Thu, 13 Jul 2023 10:28:03 -0700 (PDT) Received: from debian.debian ([140.141.197.139]) by smtp.gmail.com with ESMTPSA id e10-20020a05620a12ca00b007592f2016f4sm3040949qkl.110.2023.07.13.10.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 10:28:02 -0700 (PDT) Date: Thu, 13 Jul 2023 10:28:00 -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 v2 net] gso: fix dodgy bit handling for GSO_UDP_L4 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=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 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: https://lore.kernel.org/all/CAJPywTKDdjtwkLVUW6LRA2FU912qcDmQOQGt2WaDo28KzYDg+A@mail.gmail.com/ This change restores the expected behavior of GSO_UDP_L4 packets. Fixes: 1fd54773c267 ("udp: allow header check for dodgy GSO_UDP_L4 packets.") Suggested-by: Willem de Bruijn Signed-off-by: Yan Zhai --- v2: dropped modifications to tcp/sctp on DODGY bit removal after validating gso_segs. Also moved the UDP header check into __udp_gso_segment (per Willem's suggestion). --- net/ipv4/udp_offload.c | 16 +++++++++++----- net/ipv6/udp_offload.c | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 75aa4de5b731..f402946da344 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -274,13 +274,20 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, __sum16 check; __be16 newlen; - if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST) - return __udp_gso_segment_list(gso_skb, features, is_ipv6); - mss = skb_shinfo(gso_skb)->gso_size; if (gso_skb->len <= sizeof(*uh) + mss) return ERR_PTR(-EINVAL); + if (skb_gso_ok(gso_skb, features | NETIF_F_GSO_ROBUST)) { + /* Packet is from an untrusted source, reset gso_segs. */ + skb_shinfo(gso_skb)->gso_segs = DIV_ROUND_UP(gso_skb->len - sizeof(*uh), + mss); + return NULL; + } + + if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST) + return __udp_gso_segment_list(gso_skb, features, is_ipv6); + skb_pull(gso_skb, sizeof(*uh)); /* clear destructor to avoid skb_segment assigning it to tail */ @@ -388,8 +395,7 @@ 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)) + if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) return __udp_gso_segment(skb, features, false); mss = skb_shinfo(skb)->gso_size; diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index ad3b8726873e..09fa7a42cb93 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -43,8 +43,7 @@ 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)) + if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) return __udp_gso_segment(skb, features, true); mss = skb_shinfo(skb)->gso_size; -- 2.30.2