Article View: linux.kernel.netdev
Article #11646[PATCH net v3 7/8] selftests: net: tun: test more outer header mismatches of UDP tunnel GSO
From: Eric Dumazet
Date: Thu, 05 Nov 2026 11:57
Date: Thu, 05 Nov 2026 11:57
135 lines
12144 bytes
12144 bytes
Add tap tests for the outer header checks of UDP tunnel GSO packets
not covered yet:
- outer_proto_ok_ipv6: a 4in6 frame with an outer IPv6 header is
accepted.
- outer_proto_bad_family: an IPv4 ethertype on a declared IPv6 tunnel
is rejected.
- outer_proto_bad_vlan_ipv6: an IPv6 ethertype behind a VLAN tag on a
declared IPv4 tunnel is rejected.
- outer_proto_bad_vlan_offset: a VLAN tagged frame whose
outer_th_offset ignores the tag is rejected.
- outer_proto_bad_l4: an outer IPv4 header carrying GRE instead of UDP
is rejected.
Without the first patch of this series, the four outer_proto_bad
tests fail because the kernel accepts the frames.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/netdev/179386753718.488856.13433005125725728519@kernel.org/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
tools/testing/selftests/net/tun.c | 97 +++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index cfeca53863ce..a135d3aa10d1 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -869,6 +869,103 @@ TEST_F(tun_vnet_udptnl_proto, outer_proto_link_type)
ASSERT_EQ(ret, len);
}
+/* Build a 4in6 Geneve GSO frame whose outer ethertype is @l3proto. */
+static int build_udptnl6_frame(uint8_t *buf, uint16_t l3proto,
+ int payload_len)
+{
+ int hlen = UDP_TUNNEL_GENEVE_4IN6_HDRLEN;
+ uint8_t *outer_udph, *cur = buf;
+ int pktlen;
+
+ memset(buf, 0, TUN_VNET_TNL_SIZE + hlen + payload_len);
+
+ cur += build_virtio_net_hdr_v1_hash_tunnel(cur, true, hlen, 1400,
+ AF_INET6, AF_INET);
+ cur += build_eth(cur, l3proto, param_hwaddr_outer_dst,
+ param_hwaddr_outer_src);
+
+ pktlen = UDP_TUNNEL_GENEVE_4IN6_HDRLEN - ETH_HLEN -
+ sizeof(struct ipv6hdr) + payload_len;
+ cur += build_ipv6_header(cur, IPPROTO_UDP, 0, pktlen,
+ ¶m_ipaddr6_outer_dst,
+ ¶m_ipaddr6_outer_src);
+
+ outer_udph = cur;
+ cur += build_udp_header(cur, UDP_SRC_PORT, VN_PORT,
+ pktlen - sizeof(struct udphdr));
+ cur += build_geneve_header(cur, VN_ID);
+ cur += build_eth(cur, ETH_P_IP, param_hwaddr_inner_dst,
+ param_hwaddr_inner_src);
+ cur += build_ipv4_header(cur, IPPROTO_UDP,
+ sizeof(struct udphdr) + payload_len,
+ ¶m_ipaddr4_inner_dst,
+ ¶m_ipaddr4_inner_src);
+ cur += build_udp_packet(cur, UDP_DST_PORT, UDP_SRC_PORT, payload_len,
+ AF_INET, false);
+ build_udp_packet_csum(outer_udph, AF_INET6, false);
+
+ return cur - buf;
+}
+
+TEST_F(tun_vnet_udptnl_proto, outer_proto_ok_ipv6)
+{
+ int len, ret;
+
+ len = build_udptnl6_frame(self->pkt, ETH_P_IPV6, 2800);
+ ret = write(self->fd, self->pkt, len);
+ ASSERT_EQ(ret, len);
+}
+
+/* An IPv4 ethertype on a declared IPv6 tunnel. */
+TEST_F(tun_vnet_udptnl_proto, outer_proto_bad_family)
+{
+ int len, ret;
+
+ len = build_udptnl6_frame(self->pkt, ETH_P_IP, 2800);
+ ret = write(self->fd, self->pkt, len);
+ ASSERT_EQ(ret, -1);
+ ASSERT_EQ(errno, EINVAL);
+}
+
+TEST_F(tun_vnet_udptnl_proto, outer_proto_bad_vlan_ipv6)
+{
+ int len, ret;
+
+ len = build_udptnl_frame(self->pkt, true, ETH_P_IPV6, 2800);
+ ret = write(self->fd, self->pkt, len);
+ ASSERT_EQ(ret, -1);
+ ASSERT_EQ(errno, EINVAL);
+}
+
+/* outer_th_offset does not account for the VLAN tag. */
+TEST_F(tun_vnet_udptnl_proto, outer_proto_bad_vlan_offset)
+{
+ struct virtio_net_hdr_v1_hash_tunnel *vh = (void *)self->pkt;
+ int len, ret;
+
+ len = build_udptnl_frame(self->pkt, true, ETH_P_IP, 2800);
+ vh->outer_th_offset -= 4;
+ ret = write(self->fd, self->pkt, len);
+ ASSERT_EQ(ret, -1);
+ ASSERT_EQ(errno, EINVAL);
+}
+
+/* The outer IPv4 header does not carry UDP. */
+TEST_F(tun_vnet_udptnl_proto, outer_proto_bad_l4)
+{
+ struct iphdr *iph;
+ int len, ret;
+
+ len = build_udptnl_frame(self->pkt, false, ETH_P_IP, 2800);
+ iph = (struct iphdr *)(self->pkt + TUN_VNET_TNL_SIZE + ETH_HLEN);
+ iph->protocol = IPPROTO_GRE;
+ iph->check = 0;
+ iph->check = build_ip_csum((uint8_t *)iph, iph->ihl << 2, 0);
+ ret = write(self->fd, self->pkt, len);
+ ASSERT_EQ(ret, -1);
+ ASSERT_EQ(errno, EINVAL);
+}
+
/* IFF_TUN device with a tun_pi header: skb->protocol comes from
* userspace, and there is no Ethernet header.
*/
--
2.53.0
Technical Details
Message-ID:
<20261105115715.1466924-8-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-357292-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!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357292-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3 7/8] selftests: net: tun: test more outer header mismatches of UDP tunnel GSO Date: Thu, 5 Nov 2026 12:57:14 +0100 Organization: Usenet Network Message-ID: <20261105115715.1466924-8-edumazet@kernel.org> References: <20261105115715.1466924-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3630979"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:hPiIJRu5VXvUb0RPjeb4xDoP9QU= sha256:msBplj8HwDmL8EF3JY+pUuKu74WemnS3ms9ZHRkQ85Q= sha1:teVlviRPBs3+hUpL2l6IkP/U8eA= sha256:8bBpDmTCIZU8JFknF1tBcC7yso4c/nSmUFwzOBfta1k= 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 D15F91127FE; Thu, 5 Nov 2026 15:04:28 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 Vz04zNxCslz1; Thu, 5 Nov 2026 15:04:20 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-357292-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 399F6112F4E; Thu, 5 Nov 2026 15:04:12 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id B659460CFB7; Thu, 5 Nov 2026 11:58:06 +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=1793879862; b=uxKUHjVJ4xjBxn9BCIwqTKkRKzrxvcFmnMiVHah7JU4E1qnRk1YFB3zbqz2obFN7NcUj UrSSLNchCrB5ZmFP9XiFHrbX3xGrIL0SucoN6fDhAulHAjW1Xenov4Jtz/m0vZ9nRWj// GQfZ1u93b/ILoE+al9a8MeIL3t+IKVShXRAm6+j/r85nYx723UcCoWJYKYiaAaxeN/7eG mPRxGPlCkkl5A4wgZIM5M9BueUOt8UTWdazrPtz+vsejrC5lJBZHFsOgTaciHIbedp8zM +WdjQSKjpcjrPKseuBBHNf04afxJZSBR8KhGxpr9V6lX0FeHxRzpi+SaxAsNW+zxffQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793879862; 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=FrlUYnFS1Z7L+1q5lQqx06nWzKsoICRsNl7leZSERDg=; b=g/8wT8HNdIRfcAroqZIWek+8xVkhzDVqcoIPIIScbV7JEjKsbhDkl3Dc/W988VBE2Wsz AxJmoQkO5yAQLEy7A6r5t11JdkBIQ8TAUfa94FsG3m12mrzE9LuIN29OttyqGkLNIcI8I cMFvil3MgOtIK1jFg54sog3LEW9R67aQlgNA/oTmaKpZpr5MY1i5I/Fo5Ju4JmyxaKBFz gbqwTxBtIqtabokoiGcdLjksKOIDf9wf2LMPdYUWk8mbM89CdjrR7raIrlV5b4yt89c0b OR2YmAxx+1rfjP91JgR7pHH/yHRkXlx/aw84xtSt/hFwUAOZ44XHDC4df+YLHScne0w== 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="Dtdi/Sfw"; 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 32EBB606D81F; Thu, 5 Nov 2026 11:57:42 +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=Dtdi/Sfw 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=1793879861; b=Q7YsxITyV0bL4CPYK3z9W9kq8xomiSSDGGJrgYlAeTyagJTfmx0nFcIDUvdW2FglRw+x WLZTX0YtOjivjnwTWCkA4gkv9lbq/zb9qLy0J9jM8rtX4ghwczPwiX2/iUg5Hx42qr8/E TpUVedX5hg1wUs6qJTJay11/7J5LIyyf3cYNU2chPW4jcif6EDrEDAY55UJrFwnh9zoh1 hiGbioczU0tNWX64p7ZG2e02+7naEbl9kCymKuD/4CMYe76M5zBDCZb+eM8VQtWpPtWJL 8aWhBkvNfjCA9t2HJag/7X675ze+S1DGEZgRCGgGNSi8nth0sBThto5gyLcMwdZxqlw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793879861; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=FrlUYnFS1Z7L+1q5lQqx06nWzKsoICRsNl7leZSERDg=; b=3UFj3JzcyX5ozuyfQxbUoCWL/XTnslhlr83OQd6p+HlR+OR00HyhhY3Ur6agQu8LNBph 9iIk/fgUKWq8jz8/+Q/i13jJCTc+ZfPGDdXXasGaW1qgZPQBnV5uV4S/dHdfh7IWNi7Mn RPQc46198dlaMPHcbpJvZ/Z3lDEU+cMfrd7L0qkR7/r2Ch1o7uu8OtDA/7LR3foDlnxqZ dzuOPpHdlwDRhsO6qmz2jXVPlhv6XU1/iD/F9myJi/8tmbfOwXpEqBR/i0uz7B7XLGivI UqqNhH6oc+VJOP6J/LaMeYxpeAlAvcredH4Tzgh0yJXqxcVJzAtkf5DDOzveJ/jsZhw== 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="Dtdi/Sfw"; 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 10EF0606A32C; Thu, 5 Nov 2026 11:57:41 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69F9B1F0093A; Thu, 5 Nov 2026 11:57:38 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793879860; bh=FrlUYnFS1Z7L+1q5lQqx06nWzKsoICRsNl7leZSERDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Dtdi/SfwZJ0EDyJyO1YuXDHlHml+guaXmoSmve5AvgDVY2pHUToc4tCqn8kFCq9DJ LTJ5ErM+Qkwn5+gWbUMtEOKYxvj1b9+1BecFvzlXI7FqLaNQsrbIYYy0Za+WdkX4Hj 8N01I/io265Vb/O8cJLFKqXHHxod2/gGMkJeWmIJV5VDsvP/eYaWClWOxC67oIi9Kb PrzL7pZmJJp/N61aI3M7VigNJlI0aY3NHGIVFHjC4Zo/HkeSOxGtxJLGNoEJ/Kn8mK ceJ2q+ba9AXhNjjJtALbg/hELdV8+g4e90XZ6Tvx6WUS09fxT2FcQ75PgKFMEtHtzt iJLOrK+C0NTvw== 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