From patchwork Thu Jul 13 17:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 120079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1982845vqm; Thu, 13 Jul 2023 10:39:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlF3kh8TixwKz6bITStU92iPwy/8Pt4NnUOD1HWGCoZEQhc7MbsDbMGcmKOUk8yhbQdIGkno X-Received: by 2002:a05:6a20:9189:b0:12f:d350:8a12 with SMTP id v9-20020a056a20918900b0012fd3508a12mr433551pzd.21.1689269952642; Thu, 13 Jul 2023 10:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689269952; cv=none; d=google.com; s=arc-20160816; b=i8ojxcKR/0jqApL5VtQtYFRXM61b8lP1JHw1nCjcVk3INf31B/t9mZgzHMhYei7CKg wt2+QpBk9lTIPCKR8dDvFOML/ZJ6LQ7qUySo1Ekv6XK8hz8oful7J8aPf/yxnVbhTGfz Ji6c41Qd7lHeZg2SZrSkGmwCtelR/DY8WGfX6Ye79t7lRhGRQNs0bYYz3cFW3j66q1AO LeYZ34LMHnoYquev9rynCbUbhUD66km9KjYAZ9tq/ajMXq92Uw2n9PPQMMLOFou0P95q 8X/fwT06PAT97EBt4UUvaPdfyb1qm9hPI5U0o7QMbLIOuWbxG5f5C2XdmzvuYGdcAJbw o7Zw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cu9-20020a056a00448900b0068208d19b15si5303675pfb.249.2023.07.13.10.38.57; Thu, 13 Jul 2023 10:39:12 -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 S233739AbjGMR2e (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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771327929798560905 X-GMAIL-MSGID: 1771327929798560905 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 Reviewed-by: Willem de Bruijn Acked-by: Jason Wang --- 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;