πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10789

[PATCH net v2 2/3] selftests: net: tuntap: fix UDP checksum length in build_udp_packet_csum()

#10789
From: Eric Dumazet
Date: Wed, 04 Nov 2026 05:01
51 lines
9607 bytes
build_udp_packet_csum() passes udph->len, which is in network byte
order, as the number of bytes to checksum. On little-endian hosts this
reads up to 64KB past the UDP header and computes a wrong checksum.

Existing callers did not crash only because they use packet buffers
of MAX_VNET_TUNNEL_PACKET_SZ bytes.

Use ntohs(udph->len), as tap.c does in its own build_udp_packet().

While at it, clear udph->check before summing instead of relying on
the caller, and send 0xffff instead of a computed zero checksum, as
the kernel does with CSUM_MANGLED_0.

Fixes: a942fcd72e97 ("selftest: tun: Introduce tuntap_helpers.h header for TUN/TAP testing")
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
 tools/testing/selftests/net/tuntap_helpers.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/tuntap_helpers.h b/tools/testing/selftests/net/tuntap_helpers.h
index d6c0437136ec..ecad83fae158 100644
--- a/tools/testing/selftests/net/tuntap_helpers.h
+++ b/tools/testing/selftests/net/tuntap_helpers.h
@@ -330,14 +330,22 @@ static inline void build_udp_packet_csum(uint8_t *buf, int family,
 	size_t ipalen = ip_addr_len(family);
 	uint32_t sum;
 
+	udph->check = 0;
+
 	/* No extension IPv4 and IPv6 headers addresses are the last fields */
 	sum = add_csum(buf - 2 * ipalen, 2 * ipalen);
 	sum += htons(IPPROTO_UDP) + udph->len;
 
 	if (!csum_off)
-		sum += add_csum(buf, udph->len);
+		sum += add_csum(buf, ntohs(udph->len));
 
 	udph->check = finish_ip_csum(sum);
+
+	/* A zero UDP checksum means no checksum: send 0xffff instead,
+	 * as the kernel does with CSUM_MANGLED_0.
+	 */
+	if (!csum_off && !udph->check)
+		udph->check = 0xffff;
 }
 
 static inline int build_udp_packet(uint8_t *buf, uint16_t sport, uint16_t dport,
-- 
2.53.0
Technical Details
Message-ID: <20261104050131.629967-3-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356193-linux-kernel-netdev=dewy.ru
References: <20261104050131.629967-1-edumazet@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356193-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2 2/3] selftests: net: tuntap: fix UDP checksum length in build_udp_packet_csum()
Date: Wed,  4 Nov 2026 06:01:30 +0100
Organization: Usenet Network
Message-ID: <20261104050131.629967-3-edumazet@kernel.org>
References: <20261104050131.629967-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3328931"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5Blm/EAFfu7DG6qXgVlA6g+Qr+4= sha256:rYRbkXK2aeYhQMTcQflONtqTSEaMMVkOE66cRPYZUOg=
	sha1:JoISXGOSQMxsK+G1kFE4uNuGobg= sha256:77BzDmjtKIO4IStK5MN/bZgi7C6Rdec3WqjqplM8bbE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CEE5A112ADF; Wed,  4 Nov 2026 08:02:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id JHS2dXKdaxL7;
	Wed,  4 Nov 2026 08:02:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356193-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id EC46A112AD3; Wed,  4 Nov 2026 08:02:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 888122B1E8; Wed,  4 Nov 2026 05:01:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793768510;
	b=kx3R1OscrAKBEYPEe4vqCrCoLzEz/53q70DFwjn6BkVzK0P1NoKoAUtUNruCCy26PrH0
	 rbQ51pUXfIGn2FkkkEQyFwOM0qjP+/rirtmL4OOr5yuOsCQUknPb6pOZkISHE4M65Vfb3
	 3H2/DnDyj5uELi1BqSYpasL8m9dLoskYWYcokANzHB543IXblUvBxV9MUUcI5OXiNOgJY
	 2uEnDC4lvQ6ebWSk4oI7aI7Amum5JrVqYKlK6Pb/u9lWDXZ1eOqEwt5jkv5soANSKd5y4
	 mskMCLGYcdcDa64c60Klo4byBNbZEFk4czJOUTkTVB/xuhyPmP3E6An1col6hDaf6Sw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793768510;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=5GMAqY7FM6ZAQr9W6BNb+fX/DcRpx409vq4+uvPz0kM=;
	b=omUYSYVf3anApt9tIiXnNZ7jwXmFdER6tU8Hl1ryaAUDorXPGD7fFczyBGzjukn5qjLc
	 DliagKKXJUbD30OvNjQ4uYhqSgl5UTMpDeEDYHPbarTRqLMjJxN5mbS/GgsLsWbrb9h/V
	 MO5Spj1+ScehnDykKigN8fSkf4K3eR0A/F+jUdlsF+fJ/q+8GD/B7lnMNe5z8bwC/fVrV
	 WORh04t3Z+FSHZVi6s26pBjGOxHV89WZnmMlRQnh6PW8jikqsa48hF+yVTzvgtFB4SHWQ
	 6HrQcr4QaQUJpMBIoiMzk/3z8IGw6i6mIFfzBEXI6hwbpBqqUS+WWniWIMShKr3ndQA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LRJlvdw2;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 86A69606A33A;
	Wed,  4 Nov 2026 05:01:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LRJlvdw2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793768504;
	b=tVS4dikqE70KF780EkQtIlYT/kl+7tbYiOVoK+/VBQx3tLb2FlLjF8U/Y+6DxwERENXd
	 fe/uFkN8wFh5rsUYjwXXGmr2J3/ye61suhbClI4mgOAN2yNPI3ioHGTjiq/l/8qtR7HAN
	 mDHrKvX47SKU4TcSQiEwTf/fxFxONg9Ig8dGgUGBHW2YezGfEg10CKiOjtfocCK1u13J7
	 mcyrHBoNGYTbU9FKMqq42OzoVTssPtinTElvT16PX5EWgkW4Ri7MyQ7OfgC0A20fE7d4Q
	 Oy/Q0tOPlnCsJs4N7G0czmwh8YraRrcCACGxv19Pkyhysf8Rv12NO0mX76BGgJys1kQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793768504;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=5GMAqY7FM6ZAQr9W6BNb+fX/DcRpx409vq4+uvPz0kM=;
	b=Xxs9HmOgCsKZtFPK7Ne9OBSaiXd2nmRKjPyGditGiDAtv4af+Pl6F/4bsmwt6MLN+U6h
	 RbyWY0/O0lUC2/KqOSOtTDkDHoL5fj7ULpQjjD6m3UF5dGtf1VutSrAV0ysV13GphwzjZ
	 7MR64CVxpPh54gUlyXb0GUoiBjExfGmM0H0TjhGwoBMH+zokrz+5FWey81iwbxcqUlUGp
	 sVLr/Rvz4AX2xWbpqDpJZW8Hr629/sgjcZyYNb/yYSdJ/RN+bchY7Ir4ixlIQkx+kDIBc
	 vsXrl2BebQB3fMZvom70k/HqdD45RH46TDSiiOm5afwPdUYNh6HIPAUBjRTsO/rzcnw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LRJlvdw2;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65764606A329;
	Wed,  4 Nov 2026 05:01:44 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A45DB1F000C1;
	Wed,  4 Nov 2026 05:01:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793768504;
	bh=5GMAqY7FM6ZAQr9W6BNb+fX/DcRpx409vq4+uvPz0kM=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=LRJlvdw25Xn4b3ldmZixbHRHdB75iJJps7HrEj5OLHlxh6QvGS13Ce74HnCf/H5aa
	 +iBXWoI2Lxhn7mUL4CeWdc7d25IdJnKGLScCeY2HNCPIXpyz7me/R6XXULkAzjlhrM
	 sWzk0Hqc/EVlc9xyQJfR3WUEbyO76ryKPFC81tu+mw+KirEFUerNvwEtlTyHTskn0A
	 k2B71zGp9Jxs9GA8OjLDXfhcYf2+MHnBk0SKJQ+PYuQH67PcPPI6zsdc1/DtwMeWpg
	 d3lKDC7TcxTzFY03h6G7cbT0YbGv//y8pZRoCxzOVljMKQTbBaT4X/pH+8EgJUaKOx
	 g8Ombk6P3rLqg==
X-Cc: Eric Dumazet <edumazet@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Eugenio PΓ©rez <eperezma@redhat.com>,
	Hassan Sultan <hassansultan@google.com>,
	virtualization@lists.linux.dev
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261104050131.629967-1-edumazet@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list