Article View: linux.kernel.netdev
Article #11647[PATCH net v3 4/8] selftests: net: tuntap: fix UDP checksum length in build_udp_packet_csum()
From: Eric Dumazet
Date: Thu, 05 Nov 2026 11:57
Date: Thu, 05 Nov 2026 11:57
51 lines
9667 bytes
9667 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:
<20261105115715.1466924-5-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357289-linux-kernel-netdev=dewy.ruReferences:
<20261105115715.1466924-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!peer04.iad!feed-me.highwinds-media.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357289-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3 4/8] selftests: net: tuntap: fix UDP checksum length in build_udp_packet_csum() Date: Thu, 5 Nov 2026 12:57:11 +0100 Organization: Usenet Network Message-ID: <20261105115715.1466924-5-edumazet@kernel.org> References: <20261105115715.1466924-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3631082"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:6TMbAwduRaDy/TJpI0PHkKtNg8E= sha256:7dG4H6XvMxvWVixBIIZHf72nCZgae82eulkeKQG/Z48= sha1:iLzKkY17nttEY0Ia3agQl7LKH3I= sha256:rfxtdd/dwYWQW7U5bugG3vB1pUBDlueMiNqA2BvZrzA= 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 D21AC112F54; Thu, 5 Nov 2026 15:04:58 +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 Trywnqu5ZB8c; Thu, 5 Nov 2026 15:04:55 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-357289-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 2AFD41127FE; Thu, 5 Nov 2026 15:04:47 +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 5D86A3AB23; Thu, 5 Nov 2026 11:57:56 +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=1793879853; b=OZir/mlUiCnhMT9nKLt8R8mRZsFUROIYvPGfKHl7bRBv5mm+SBMdZ1lhb77NVWbYezv3 pr5oaiIDBac9R8tVUyFXDsO8On/zpvzmkYgHZd2eJulICGj6IMdaCm1OPEKF1S5hz6DOG dXpusxPS2FpoG12MRjJ9EPtetC6NAxuDhrkOAGFDHdQVAB0NdMfzazzaIlbfTotCOmEhm c9WuhkkUDRV35AsXUkyQWnLu7MrCe4zAcptOoVZJFqpU5gr8FsC945tUtAToTQHbctijq bunRoz55rdOgJcPexY20kIiXxU26aD2q50he9I4D8OVdJXEd0qv5LjJD6U+q0A2qj+g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793879853; 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=lJAnES/OympZrA9ErZNU+ppeBqu02w9DgD2igDG7noxMhppt6Wq7dCUhuw1h3wmiQ871 j7F5SNh08AM5u4T9q+GoqB0WT20VcEDXnARh85R0Qbqsbo9QSbsefSGRUmCfPMtDDbJp2 w3VR/s4H2BvdVoGnVVQb4qs9qM4cU3WGF1A1efGEk+KHNcqpCSi1IJ3Dh1vl2n0MpYsQX evsC2GrX8QdZCmDVlNeYsUqk7AVTMR7zTIVmE+P5BHJ+z+sWRIUdvZUVpv6I7GSxJORYl dUbz0yAOcG5rt5u6ViWVZpsudzCUN1J3vEAM3G56bbzWKDLak/SB0vC3szXdSXHVIyw== 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=La0ow71c; 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 59CF9606D802; Thu, 5 Nov 2026 11:57:33 +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=La0ow71c 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=1793879852; b=VWuXLcMP1Rmgt54VClRbDqe793DaqwT/4TIukJcwcv+CcSwTNxxwmieRoJlC1BSMHO4R x+bbZ2ofHabpndGtM0Iea1JDZhvGis+kYT9HE3N1kvvn2w72wxab/YCr1VgK3+aN15fQv Q9NzyAxPEgRaVbHNecWE07tUhPF9AuLPHOatuaIOwfZYWL9SXfbyYLuGhk5wikImgKIBY gdsJapO8Djs5H+eMo0qp8yis3brysUDxkqH7qV5mTfNZ1b1K/44pr3B+ZnihX4bAxwU5h PGY1TQzzr42liUHgckhk1b5IlLqA4pWHtnrQp+q+zTNhCaCTVIHp+UH56/ps3z37YEQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793879852; 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=nbmJT0Eug1P/xkTzETA7xp6jPvsQvxz7F7gmVkK/NpCjJtTuz1QESVyieWKWfvSzi3/6 gQJEkY/vc2okwagbVtkwMB8+MAjcgRxEtnaY2dMFoxLWhw5b1TiqhWpFXYh1jCwdWtbBP kP8UEvZGeGd5TyZbvBwZy0IUaxAFotM5IO6GeByhJxJgn8y4zaCKyBUnlSi1LSPjt2Ep7 wOhiSWwucYq1RuVJFCFy/2R7LvAsThhVEHH2X9ch08+s+X48n4gLdx6/i0/4+/KgNnYXd cg9o3jOyhuMm//tcHH1U7M53jIHZJ5NZy/bwdcoNtN4Q4UqduzYYVPLCpkzTGQaOklA== 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=La0ow71c; 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 3B1A8606D801; Thu, 5 Nov 2026 11:57:32 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96E9B1F0093A; Thu, 5 Nov 2026 11:57:29 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793879852; bh=5GMAqY7FM6ZAQr9W6BNb+fX/DcRpx409vq4+uvPz0kM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=La0ow71c/c7XYBluF2qRAhPZIWRij2839XlrQiQy94qLDeBhk8knhpNdo1TMXMc9W z40UBp+m/aupTlC+czkll/ZnPlSnh5ANFHckNAreMDIV6NYE5QcT+ll/5tFjAzIINl s8KO2VEgjp9RUVXWJ6Pla4N9FaPbfjnH9uGv0QVtwx88p9V6DL9hHwT/btTmXN4YU4 g5uOSYFD3S3N56TUHlLnO1oGq0r9s+CM1WA3tR3uF3rb2H+A92T+4S9quc19AAzyjJ s+CZGKYeIO1qDcyCalURE3vhc4lbV/ADarRmHqpjIZlzhUXyyH8PeSLyOL9U7jphy3 /2PH4cd1Halhw== X-Cc: Eric Dumazet <edumazet@kernel.org>, Simon Horman <horms@kernel.org>, Willem de Bruijn <willemb@google.com>, "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowangio@gmail.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: <20261105115715.1466924-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 X-Received-Bytes: 9461