From nobody Thu Jan 30 19:10:15 2025 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72AAA86348 for ; Mon, 27 Jan 2025 05:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737957473; cv=none; b=UihhpOIdxkwng4gURciShSYgxs0nLZuaFcAmwUH3QkX3PSYjLJSq5M3cf+gVftA/tnvx4YRU8aV9BAv/Uci5eiit0grxd19jiv4SkXdnouGGlYzpXwW0VLf4prNtD6xOIZ0v9whWAUKOMDWyYODN3aZSto0+kgCVKMwJFO6IkeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737957473; c=relaxed/simple; bh=g9tKZKUVtgad6iryP4gNw2rOnw73AjN2VWCn9Ts74a0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=uVUq447tFlA0Jc/8sqvB99nFmT6aodLjPVDqaffoLpbkCIIi0VyqpUs+Hk3pSOkHHhlVAkW3Mi2bAGmUId31iXwS+XQG4FZv2PyAd82s8IIYUJ7dzWnnQ42cN6IaxtJDKT0jL9g1lmApkk674GdM6JPvR2Q10ZeO7gbdyCrbeV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=O+Sk+vqn; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="O+Sk+vqn" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7be8efa231aso413745785a.2 for ; Sun, 26 Jan 2025 21:57:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1737957470; x=1738562270; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/ZAOjkuxXZ0U1ZP58rurbsd7EJpXrywFMWXYNm47nyk=; b=O+Sk+vqnleBqMu5phrqH4llVcsGyCjPafoKombpOr7YP29b1aZFPk+YK1bFRFFvCfY hEZA65Ovul4OC3h/yhgd6MY6NPMAwlpbOBopYUbV57pV034O+gEUKlL+T8tk5sLCJwhv engZ0rHVOm5YgoXXTV8QSn40pbbRcMcBSbLUFNwNhxIOfO/kCOM9aDWcYsQyPnC6bsIf 1iaDmNb3N0VpKWUJh0hJCCaktibxq+dv3W4d2TZCpj+pP25yTcAveU1S0LZjVPxw3Znj lpLc2q46QDIStzgnRQuLzRqsLeq1X/Ot8j+leK2ysmLfm2OgXipqFl+RqiXbXW50dN1U kErw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737957470; x=1738562270; 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=/ZAOjkuxXZ0U1ZP58rurbsd7EJpXrywFMWXYNm47nyk=; b=L7KLuP2nQdWc1rwaWFUSSz8q1hzOA9j2Gc5QulZMozaBT7fnd8n2tNXXl6aOGKd5K5 1vseoUr0T37LHHoiRzlDzlnQkwS1yrutxc7blqVVGAAW15Crb1v3W6/Br1X7JfSqSaUy vQlKKkL6AmYjoZ5/zFpHam2WB14szRzH1BNyABpfGa1JQH1aopwb0X+T0jr/CcOSbr9v 7zIBJ82PNa61xEMi9GuEa2caYMHm7MehFC9wQ+LDUozHnMKBCsTQ5+2YeTeD9xo61bhT Md3yzSqcaQFyn82EcVmKpCumBal+KHNVXMHnLcSATGbIUm2+SSPVAlXITEiRZwVBLxK5 rbcQ== X-Forwarded-Encrypted: i=1; AJvYcCXZWWWXc26XScZJiOnCspVPmEtKOjQ7ceoz8hzyNvUlYZx4vSXPbdw16F8fSRp8181dkmu0MqxpjeZkL0E=@vger.kernel.org X-Gm-Message-State: AOJu0YzPQP8DEXyTTTZyUFwfdQw98bNIjJaddy1+92uX1l/BSOpqBrLY /LQs9f9eVMRW2AYz0rxqqQRCou+dTo8bdBdSRb1Ewb+a9o0odirjnfBHTER1fIA= X-Gm-Gg: ASbGncuR08uDiW1s9ISdG5eBzXJTzQ6UF0CV7fbghVZ3hCCO7ZJv/SDwkjhcf2u6Oc8 qCmCUpIA3MkjQQ9nMOsfKuHtS9uZVx1daSkIR1R2RkuP3wt5t08k7T3k1yY44wIU9RzOBR+Fsz7 vwfCHVLHOMSDKkPN0y/WQy5d0X/hRDnPHEfnTsJKj5rPqMYa8pXU+lIICLnzgCKrN2xcGt16xJZ RUEr0IQMhwRNLuwse/TLNTJ2Yd2ul9yWPNPaDSkQBhjShx/dU81EwNbgbm4m0IQ7z0+cA== X-Google-Smtp-Source: AGHT+IELkxXy4dXj25hoHt7K6wCR+2fW9w4bJEKm+BZlWFP0UcOIGCcS7Emm1gOZ6sT74otzIxA/qQ== X-Received: by 2002:a05:620a:44d5:b0:7b6:d1f6:3dc with SMTP id af79cd13be357-7be6321bf8cmr6759762985a.18.1737957470302; Sun, 26 Jan 2025 21:57:50 -0800 (PST) Received: from debian.debian ([2a09:bac5:79d9:f9b::18e:180]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7be9aeedefesm355991085a.78.2025.01.26.21.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2025 21:57:48 -0800 (PST) Date: Sun, 26 Jan 2025 21:57:46 -0800 From: Yan Zhai To: netdev@vger.kernel.org Cc: Willem de Bruijn , "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Josh Hunt , Alexander Duyck , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH] udp: gso: fix MTU check for small packets Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 4094871db1d6 ("udp: only do GSO if # of segs > 1") avoided GSO for small packets. But the kernel currently dismisses GSO requests only after checking MTU on gso_size. This means any packets, regardless of their payload sizes, would be dropped when MTU is smaller than requested gso_size. Meanwhile, EINVAL would be returned in this case, making it very misleading to debug. Ideally, do not check any GSO related constraints when payload size is smaller than requested gso_size, and return EMSGSIZE on MTU check failure consistently for all packets to ease debugging. Fixes: 4094871db1d6 ("udp: only do GSO if # of segs > 1") Signed-off-by: Yan Zhai --- net/ipv4/udp.c | 18 ++++++++---------- net/ipv6/udp.c | 18 ++++++++---------- tools/testing/selftests/net/udpgso.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index c472c9a57cf6..9aed1b4a871f 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1137,13 +1137,13 @@ static int udp_send_skb(struct sk_buff *skb, struct= flowi4 *fl4, uh->len =3D htons(len); uh->check =3D 0; =20 - if (cork->gso_size) { + if (cork->gso_size && datalen > cork->gso_size) { const int hlen =3D skb_network_header_len(skb) + sizeof(struct udphdr); =20 if (hlen + cork->gso_size > cork->fragsize) { kfree_skb(skb); - return -EINVAL; + return -EMSGSIZE; } if (datalen > cork->gso_size * UDP_MAX_SEGMENTS) { kfree_skb(skb); @@ -1158,15 +1158,13 @@ static int udp_send_skb(struct sk_buff *skb, struct= flowi4 *fl4, return -EIO; } =20 - if (datalen > cork->gso_size) { - skb_shinfo(skb)->gso_size =3D cork->gso_size; - skb_shinfo(skb)->gso_type =3D SKB_GSO_UDP_L4; - skb_shinfo(skb)->gso_segs =3D DIV_ROUND_UP(datalen, - cork->gso_size); + skb_shinfo(skb)->gso_size =3D cork->gso_size; + skb_shinfo(skb)->gso_type =3D SKB_GSO_UDP_L4; + skb_shinfo(skb)->gso_segs =3D DIV_ROUND_UP(datalen, + cork->gso_size); =20 - /* Don't checksum the payload, skb will get segmented */ - goto csum_partial; - } + /* Don't checksum the payload, skb will get segmented */ + goto csum_partial; } =20 if (is_udplite) /* UDP-Lite */ diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 6671daa67f4f..6cdc8ce4c6f9 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1385,13 +1385,13 @@ static int udp_v6_send_skb(struct sk_buff *skb, str= uct flowi6 *fl6, uh->len =3D htons(len); uh->check =3D 0; =20 - if (cork->gso_size) { + if (cork->gso_size && datalen > cork->gso_size) { const int hlen =3D skb_network_header_len(skb) + sizeof(struct udphdr); =20 if (hlen + cork->gso_size > cork->fragsize) { kfree_skb(skb); - return -EINVAL; + return -EMSGSIZE; } if (datalen > cork->gso_size * UDP_MAX_SEGMENTS) { kfree_skb(skb); @@ -1406,15 +1406,13 @@ static int udp_v6_send_skb(struct sk_buff *skb, str= uct flowi6 *fl6, return -EIO; } =20 - if (datalen > cork->gso_size) { - skb_shinfo(skb)->gso_size =3D cork->gso_size; - skb_shinfo(skb)->gso_type =3D SKB_GSO_UDP_L4; - skb_shinfo(skb)->gso_segs =3D DIV_ROUND_UP(datalen, - cork->gso_size); + skb_shinfo(skb)->gso_size =3D cork->gso_size; + skb_shinfo(skb)->gso_type =3D SKB_GSO_UDP_L4; + skb_shinfo(skb)->gso_segs =3D DIV_ROUND_UP(datalen, + cork->gso_size); =20 - /* Don't checksum the payload, skb will get segmented */ - goto csum_partial; - } + /* Don't checksum the payload, skb will get segmented */ + goto csum_partial; } =20 if (is_udplite) diff --git a/tools/testing/selftests/net/udpgso.c b/tools/testing/selftests= /net/udpgso.c index 3f2fca02fec5..fb73f1c331fb 100644 --- a/tools/testing/selftests/net/udpgso.c +++ b/tools/testing/selftests/net/udpgso.c @@ -102,6 +102,13 @@ struct testcase testcases_v4[] =3D { .gso_len =3D CONST_MSS_V4, .r_num_mss =3D 1, }, + { + /* datalen <=3D MSS < gso_len: will fall back to no GSO */ + .tlen =3D CONST_MSS_V4, + .gso_len =3D CONST_MSS_V4 + 1, + .r_num_mss =3D 0, + .r_len_last =3D CONST_MSS_V4, + }, { /* send a single MSS + 1B */ .tlen =3D CONST_MSS_V4 + 1, @@ -205,6 +212,13 @@ struct testcase testcases_v6[] =3D { .gso_len =3D CONST_MSS_V6, .r_num_mss =3D 1, }, + { + /* datalen <=3D MSS < gso_len: will fall back to no GSO */ + .tlen =3D CONST_MSS_V6, + .gso_len =3D CONST_MSS_V6 + 1, + .r_num_mss =3D 0, + .r_len_last =3D CONST_MSS_V6, + }, { /* send a single MSS + 1B */ .tlen =3D CONST_MSS_V6 + 1, --=20 2.30.2