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 0/4] tun, tap: bound vnet header and skb copy lengths
Date: Thu, 19 Nov 2026 23:42:35 +0900 [thread overview]
Message-ID: <20261119144241.360238-1-graypanda.inzag@gmail.com> (raw)
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
next reply other threads:[~2026-11-19 14:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 14:42 Junyoung Jang [this message]
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 ` [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
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-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®