From: Junyoung Jang <graypanda.inzag@gmail.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Jason Wang <jasowangio@gmail.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Junyoung Jang <graypanda.inzag@gmail.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Gwanhyun Lee <gwanhyunlee@gmail.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap
Date: Thu, 19 Nov 2026 23:42:39 +0900 [thread overview]
Message-ID: <20261119144241.360238-5-graypanda.inzag@gmail.com> (raw)
In-Reply-To: <20261119144241.360238-1-graypanda.inzag@gmail.com>
Add tun and macvtap write tests with a 512-byte virtio header and a
14-byte Ethernet frame. A hdr_len of 256 must fail with -EINVAL
because it exceeds the post-padding payload. A zero hdr_len must
continue to accept the same valid frame.
These tests exercise the common header parser through both drivers.
On the unpatched kernel, each oversized hdr_len test accepts the
packet instead of rejecting it.
In x86-64 QEMU, the patched kernel passed all 105 tun and five tap
selftests, including the new cases.
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
tools/testing/selftests/net/tap.c | 29 +++++++++++++++++++++++++++++
tools/testing/selftests/net/tun.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/tools/testing/selftests/net/tap.c b/tools/testing/selftests/net/tap.c
index a0c9418132c8..bf5d36cf73c9 100644
--- a/tools/testing/selftests/net/tap.c
+++ b/tools/testing/selftests/net/tap.c
@@ -425,4 +425,33 @@ TEST_F(tap, test_packet_crash_tap_invalid_eth_proto)
ASSERT_EQ(errno, EINVAL);
}
+TEST_F(tap, padded_hdr_len_exceeds_payload)
+{
+ const int hdr_size = 512;
+ uint8_t pkt[512 + ETH_HLEN] = { 0 };
+ struct virtio_net_hdr *vh = (void *)pkt;
+ ssize_t ret;
+
+ ASSERT_EQ(ioctl(self->fd, TUNSETVNETHDRSZ, &hdr_size), 0);
+ vh->hdr_len = 256;
+ build_eth(pkt + hdr_size, ETH_P_IP);
+
+ ret = write(self->fd, pkt, sizeof(pkt));
+ ASSERT_EQ(ret, -1);
+ ASSERT_EQ(errno, EINVAL);
+}
+
+TEST_F(tap, padded_hdr_len_zero)
+{
+ const int hdr_size = 512;
+ uint8_t pkt[512 + ETH_HLEN] = { 0 };
+ ssize_t ret;
+
+ ASSERT_EQ(ioctl(self->fd, TUNSETVNETHDRSZ, &hdr_size), 0);
+ build_eth(pkt + hdr_size, ETH_P_IP);
+
+ ret = write(self->fd, pkt, sizeof(pkt));
+ ASSERT_EQ(ret, sizeof(pkt));
+}
+
TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index 34de2580e32e..525fd588d916 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -683,6 +683,37 @@ TEST_F(tun_vnet_gso, vlan_tcpv4_gso_no_csum_64k)
ASSERT_EQ(ret, len);
}
+TEST_F(tun_vnet_gso, padded_hdr_len_exceeds_payload)
+{
+ const int hdr_size = 512;
+ uint8_t pkt[512 + ETH_HLEN] = { 0 };
+ struct virtio_net_hdr *vh = (void *)pkt;
+ ssize_t ret;
+
+ ASSERT_EQ(ioctl(self->fd, TUNSETVNETHDRSZ, &hdr_size), 0);
+ vh->hdr_len = 256;
+ build_eth(pkt + hdr_size, ETH_P_IP, param_hwaddr_outer_src,
+ param_hwaddr_outer_dst);
+
+ ret = write(self->fd, pkt, sizeof(pkt));
+ ASSERT_EQ(ret, -1);
+ ASSERT_EQ(errno, EINVAL);
+}
+
+TEST_F(tun_vnet_gso, padded_hdr_len_zero)
+{
+ const int hdr_size = 512;
+ uint8_t pkt[512 + ETH_HLEN] = { 0 };
+ ssize_t ret;
+
+ ASSERT_EQ(ioctl(self->fd, TUNSETVNETHDRSZ, &hdr_size), 0);
+ build_eth(pkt + hdr_size, ETH_P_IP, param_hwaddr_outer_src,
+ param_hwaddr_outer_dst);
+
+ ret = write(self->fd, pkt, sizeof(pkt));
+ ASSERT_EQ(ret, sizeof(pkt));
+}
+
FIXTURE(tun_vnet_udptnl)
{
char ifname[IFNAMSIZ];
--
2.43.0
next prev parent reply other threads:[~2026-11-19 14:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 14:42 [PATCH net v3 0/4] tun, tap: bound vnet header and skb copy lengths Junyoung Jang
2026-11-19 14:42 ` [PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding Junyoung Jang
2026-11-19 20:10 ` Willem de Bruijn
2026-11-19 14:42 ` [PATCH net v3 2/4] tap: clamp zero-copy copylen to remaining payload length Junyoung Jang
2026-11-19 21:11 ` Willem de Bruijn
2026-11-19 14:42 ` [PATCH net v3 3/4] tun: " Junyoung Jang
2026-11-19 21:13 ` Willem de Bruijn
2026-11-19 14:42 ` Junyoung Jang [this message]
2026-11-19 21:15 ` [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119144241.360238-5-graypanda.inzag@gmail.com \
--to=graypanda.inzag@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=gwanhyunlee@gmail.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.