* [PATCH net v3 0/4] tun, tap: bound vnet header and skb copy lengths
@ 2026-11-19 14:42 Junyoung Jang
2026-11-19 14:42 ` [PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding Junyoung Jang
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Junyoung Jang @ 2026-11-19 14:42 UTC (permalink / raw)
To: Willem de Bruijn, Jason Wang, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
There are two independent length mismatches in tun and tap TX paths.
Since v6.15, __tun_vnet_hdr_get() has compared hdr_len with an iterator
count that still includes configured virtio header padding. A 512-byte
header, hdr_len of 256, and a 14-byte Ethernet frame pass that check
even though only 14 payload bytes remain after the padding is skipped.
Commit 2506251e81d1 ("tun: Decouple vnet handling") introduced this
ordering for tun. Commit 6a53fc5a8770 ("tap: Use tun's vnet-related
code") brought the common parser into tap.
An older zero-copy issue also affects both drivers when hdr_len is zero.
With a 246-byte padded header and a 14-byte frame, the full 260-byte
vhost descriptor crosses its 256-byte zero-copy threshold. The drivers
choose GOODCOPY_LEN (128) without limiting it to the remaining frame,
allowing an skb to carry uncopied bytes. Commit 97bc3633bec7
("macvtap: macvtapTX zero-copy support") added the tap calculation.
Commit 0690899b4d45 ("tun: experimental zero copy tx support") added
the matching tun path.
Patch 1 validates hdr_len after skipping padding. Patches 2 and 3 bound
the zero-copy skb head to the remaining payload in tap and tun. Patch 4
adds direct-write regression tests for both drivers.
Clamping keeps valid short frames on the zero-copy completion path.
A normal-copy fallback would complete the vhost ubuf_info with failure
and increase tx_zcopy_err. Without packet-socket listeners, 401 short
frames completed without raising that counter.
Changes since v2:
- Separate the v6.15 header validation regression from the older
GOODCOPY_LEN issue and fix the shared parser.
- Add the matching tun zero-copy fix and tun/macvtap selftests.
- Retain the tap copylen clamp, with its original macvtap Fixes tag.
An AI coding assistant assisted with analysis, code and reproducer
preparation. In x86-64 QEMU/vhost-net, both drivers now deliver only
14 bytes for the short-frame case and reject the oversized hdr_len
case with -EINVAL. The patched kernel passed all 105 tun and five tap
selftests.
---
v2: https://lore.kernel.org/netdev/20261118120102.3717000-1-graypanda.inzag@gmail.com/
v1: https://lore.kernel.org/netdev/20261113164903.785381-1-graypanda.inzag@gmail.com/
Junyoung Jang (4):
net: tun_vnet: validate hdr_len after skipping header padding
tap: clamp zero-copy copylen to remaining payload length
tun: clamp zero-copy copylen to remaining payload length
selftests: net: check padded vnet hdr_len in tun and tap
drivers/net/tap.c | 2 ++
drivers/net/tun.c | 1 +
drivers/net/tun_vnet.h | 3 +--
tools/testing/selftests/net/tap.c | 29 +++++++++++++++++++++++++++++
tools/testing/selftests/net/tun.c | 31 +++++++++++++++++++++++++++++++
5 files changed, 64 insertions(+), 2 deletions(-)
base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding
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 ` 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
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Junyoung Jang @ 2026-11-19 14:42 UTC (permalink / raw)
To: Willem de Bruijn, Jason Wang, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
__tun_vnet_hdr_get() checks hdr_len against iov_iter_count(from) before
advancing past the configured virtio header padding. With a 512-byte
header and a 14-byte Ethernet frame, hdr_len=256 passes because the
iterator still includes header padding. After the advance, only
14 bytes remain. tun_get_user() and tap_get_user() can then reserve a
linear skb area larger than the frame and transmit uncopied bytes.
Advance past the padding before comparing hdr_len with the remaining
payload. Both callers return immediately on error and discard their
iterator, so the cursor position on -EINVAL is not observable by them.
The problem was identified during review of the tap zero-copy fix and
reproduced with vhost-net in an x86-64 QEMU guest: a 14-byte input
produced a 256-byte frame on both tun and tap. After the change, both
drivers reject that input with -EINVAL. The new tun and tap selftests
pass on the patched kernel.
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Fixes: 2506251e81d1 ("tun: Decouple vnet handling")
Fixes: 6a53fc5a8770 ("tap: Use tun's vnet-related code")
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>
---
drivers/net/tun_vnet.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h
index f4c652b1fa44..0b9622891681 100644
--- a/drivers/net/tun_vnet.h
+++ b/drivers/net/tun_vnet.h
@@ -138,11 +138,10 @@ static inline int __tun_vnet_hdr_get(int sz, unsigned int flags,
hdr->hdr_len = cpu_to_tun_vnet16(flags, hdr_len);
}
+ iov_iter_advance(from, sz - parsed_size);
if (hdr_len > iov_iter_count(from))
return -EINVAL;
- iov_iter_advance(from, sz - parsed_size);
-
return hdr_len;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net v3 2/4] tap: clamp zero-copy copylen to remaining payload length
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 14:42 ` 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 14:42 ` [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap Junyoung Jang
3 siblings, 1 reply; 9+ messages in thread
From: Junyoung Jang @ 2026-11-19 14:42 UTC (permalink / raw)
To: Willem de Bruijn, Jason Wang, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
tap_get_user() chooses GOODCOPY_LEN when the virtio hdr_len is zero,
without limiting it to the payload remaining after the virtio header.
A 246-byte padded header and a 14-byte Ethernet frame give vhost-net a
260-byte TX descriptor, above its 256-byte zero-copy threshold. The
128-byte skb head then contains only 14 copied bytes; the rest can be
transmitted as stale kernel heap contents.
The original macvtap zero-copy support introduced the copylen choice.
Commit bab632d69ee4 ("vhost: vhost TX zero-copy support") connected
the in-tree vhost-net caller, so this case predates the v6.15 header
validation regression.
Clamp copylen to the remaining payload before allocating the skb. This
also covers cases where the entire frame fits in the skb's linear area.
An AI-assisted code review found this issue. An x86-64 QEMU/vhost-net
reproducer observed a 128-byte frame from 14 input bytes, including a
114-byte uncopied tail. The patched kernel delivered 14 bytes in the
same test and in 400 repeated short-frame sends.
Fixes: 97bc3633bec7 ("macvtap: macvtapTX zero-copy support")
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>
---
drivers/net/tap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 2f19fb07bb2d..f25c58d6e986 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -608,6 +608,8 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
struct iov_iter i;
copylen = clamp(hdr_len ?: GOODCOPY_LEN, ETH_HLEN, good_linear);
+ /* The remaining payload may be shorter than copylen. */
+ copylen = min_t(unsigned long, copylen, len);
linear = copylen;
i = *from;
iov_iter_advance(&i, copylen);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net v3 3/4] tun: clamp zero-copy copylen to remaining payload length
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 14:42 ` [PATCH net v3 2/4] tap: clamp zero-copy copylen to remaining payload length Junyoung Jang
@ 2026-11-19 14:42 ` Junyoung Jang
2026-11-19 21:13 ` Willem de Bruijn
2026-11-19 14:42 ` [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap Junyoung Jang
3 siblings, 1 reply; 9+ messages in thread
From: Junyoung Jang @ 2026-11-19 14:42 UTC (permalink / raw)
To: Willem de Bruijn, Jason Wang, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
tun_get_user() also derives copylen from hdr_len or GOODCOPY_LEN
without bounding it to len after removing the virtio header. A
padded header can make a short frame cross vhost-net's zero-copy
threshold. tun_alloc_skb() then reserves more linear packet data than
zerocopy_sg_from_iter() copies, and the uncopied tail can be delivered
to the network stack.
Limit copylen to len before the NAPI fragments and skb allocation
branches. The requested copy length then cannot exceed the supplied
payload. The normal skb-building path is unchanged.
This matching tun issue was noted during review of the tap zero-copy
fix. An AI coding assistant helped prepare the /dev/net/tun
reproducer. In x86-64 QEMU/vhost-net, a 14-byte input produced a
128-byte frame with a nonzero uncopied tail. The patched kernel
delivered 14 bytes, completed 300 repeated short sends, and still
selected zero-copy for a later 400-byte frame.
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Fixes: 0690899b4d45 ("tun: experimental zero copy tx support")
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>
---
drivers/net/tun.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index dcec7311e601..76486cde21e4 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1850,6 +1850,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
* The rest of the buffer is mapped from userspace.
*/
copylen = min(hdr_len ? hdr_len : GOODCOPY_LEN, good_linear);
+ copylen = min_t(size_t, copylen, len);
linear = copylen;
iov_iter_advance(&i, copylen);
if (iov_iter_npages(&i, INT_MAX) <= MAX_SKB_FRAGS)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap
2026-11-19 14:42 [PATCH net v3 0/4] tun, tap: bound vnet header and skb copy lengths Junyoung Jang
` (2 preceding siblings ...)
2026-11-19 14:42 ` [PATCH net v3 3/4] tun: " Junyoung Jang
@ 2026-11-19 14:42 ` Junyoung Jang
2026-11-19 21:15 ` Willem de Bruijn
3 siblings, 1 reply; 9+ messages in thread
From: Junyoung Jang @ 2026-11-19 14:42 UTC (permalink / raw)
To: Willem de Bruijn, Jason Wang, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding
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
0 siblings, 0 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-19 20:10 UTC (permalink / raw)
To: Junyoung Jang, Willem de Bruijn, Jason Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
Junyoung Jang wrote:
> __tun_vnet_hdr_get() checks hdr_len against iov_iter_count(from) before
> advancing past the configured virtio header padding. With a 512-byte
> header and a 14-byte Ethernet frame, hdr_len=256 passes because the
> iterator still includes header padding. After the advance, only
> 14 bytes remain. tun_get_user() and tap_get_user() can then reserve a
> linear skb area larger than the frame and transmit uncopied bytes.
>
> Advance past the padding before comparing hdr_len with the remaining
> payload. Both callers return immediately on error and discard their
> iterator, so the cursor position on -EINVAL is not observable by them.
>
> The problem was identified during review of the tap zero-copy fix and
> reproduced with vhost-net in an x86-64 QEMU guest: a 14-byte input
> produced a 256-byte frame on both tun and tap. After the change, both
> drivers reject that input with -EINVAL. The new tun and tap selftests
> pass on the patched kernel.
>
If respinning, please state explicitly that this restores existing
pre 6.15 behavior.
> Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Fixes: 2506251e81d1 ("tun: Decouple vnet handling")
> Fixes: 6a53fc5a8770 ("tap: Use tun's vnet-related code")
> 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>
Reviewed-by: Willem de Bruijn <willemb@google.com>
> ---
> drivers/net/tun_vnet.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h
> index f4c652b1fa44..0b9622891681 100644
> --- a/drivers/net/tun_vnet.h
> +++ b/drivers/net/tun_vnet.h
> @@ -138,11 +138,10 @@ static inline int __tun_vnet_hdr_get(int sz, unsigned int flags,
> hdr->hdr_len = cpu_to_tun_vnet16(flags, hdr_len);
> }
>
> + iov_iter_advance(from, sz - parsed_size);
> if (hdr_len > iov_iter_count(from))
> return -EINVAL;
>
> - iov_iter_advance(from, sz - parsed_size);
> -
> return hdr_len;
> }
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 2/4] tap: clamp zero-copy copylen to remaining payload length
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
0 siblings, 0 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-19 21:11 UTC (permalink / raw)
To: Junyoung Jang, Willem de Bruijn, Jason Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
Junyoung Jang wrote:
> tap_get_user() chooses GOODCOPY_LEN when the virtio hdr_len is zero,
> without limiting it to the payload remaining after the virtio header.
> A 246-byte padded header and a 14-byte Ethernet frame give vhost-net a
> 260-byte TX descriptor, above its 256-byte zero-copy threshold. The
> 128-byte skb head then contains only 14 copied bytes; the rest can be
> transmitted as stale kernel heap contents.
>
> The original macvtap zero-copy support introduced the copylen choice.
> Commit bab632d69ee4 ("vhost: vhost TX zero-copy support") connected
> the in-tree vhost-net caller, so this case predates the v6.15 header
> validation regression.
>
> Clamp copylen to the remaining payload before allocating the skb. This
> also covers cases where the entire frame fits in the skb's linear area.
>
> An AI-assisted code review found this issue. An x86-64 QEMU/vhost-net
> reproducer observed a 128-byte frame from 14 input bytes, including a
> 114-byte uncopied tail. The patched kernel delivered 14 bytes in the
> same test and in 400 repeated short-frame sends.
If respinning:
tun/tap's vnet_hdr_sz must be at least ~129. That is far larger than any
header vhost would negotiate, so it only happens when the VMM sets
vnet_hdr_sz inconsistently with the vhost features. The guest controls the
packet contents but not vnet_hdr_sz, so a guest can't trigger this on its
own against a sane VMM.
> Fixes: 97bc3633bec7 ("macvtap: macvtapTX zero-copy support")
> 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>
Reviewed-by: Willem de Bruijn <willemb@google.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 3/4] tun: clamp zero-copy copylen to remaining payload length
2026-11-19 14:42 ` [PATCH net v3 3/4] tun: " Junyoung Jang
@ 2026-11-19 21:13 ` Willem de Bruijn
0 siblings, 0 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-19 21:13 UTC (permalink / raw)
To: Junyoung Jang, Willem de Bruijn, Jason Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
Junyoung Jang wrote:
> tun_get_user() also derives copylen from hdr_len or GOODCOPY_LEN
> without bounding it to len after removing the virtio header. A
> padded header can make a short frame cross vhost-net's zero-copy
> threshold. tun_alloc_skb() then reserves more linear packet data than
> zerocopy_sg_from_iter() copies, and the uncopied tail can be delivered
> to the network stack.
>
> Limit copylen to len before the NAPI fragments and skb allocation
> branches. The requested copy length then cannot exceed the supplied
> payload. The normal skb-building path is unchanged.
>
> This matching tun issue was noted during review of the tap zero-copy
> fix. An AI coding assistant helped prepare the /dev/net/tun
> reproducer. In x86-64 QEMU/vhost-net, a 14-byte input produced a
> 128-byte frame with a nonzero uncopied tail. The patched kernel
> delivered 14 bytes, completed 300 repeated short sends, and still
> selected zero-copy for a later 400-byte frame.
>
> Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Fixes: 0690899b4d45 ("tun: experimental zero copy tx support")
> 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>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Thanks for converting the original patch into this more complete
series.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap
2026-11-19 14:42 ` [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap Junyoung Jang
@ 2026-11-19 21:15 ` Willem de Bruijn
0 siblings, 0 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-19 21:15 UTC (permalink / raw)
To: Junyoung Jang, Willem de Bruijn, Jason Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Junyoung Jang, Simon Horman, Shuah Khan, Gwanhyun Lee, netdev,
linux-kernel, linux-kselftest
Junyoung Jang wrote:
> 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>
Reviewed-by: Willem de Bruijn <willemb@google.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-19 21:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net v3 4/4] selftests: net: check padded vnet hdr_len in tun and tap Junyoung Jang
2026-11-19 21:15 ` Willem de Bruijn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox