[PATCH net v3 0/4] tun, tap: bound vnet header and skb copy lengths

From: Junyoung Jang

Date: Thu Nov 19 2026 - 09:43:51 EST


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@xxxxxxxxx/
v1: https://lore.kernel.org/netdev/20261113164903.785381-1-graypanda.inzag@xxxxxxxxx/

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