Re: [PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding

From: netdev-bot+sashiko

Date: Mon Nov 23 2026 - 10:38:27 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] At this commit, the new check in __tun_vnet_hdr_get()
(drivers/net/tun_vnet.h:141-143) only limits a non-zero hdr_len to the…
- [Low] The commit message says "The new tun and tap selftests pass on
the patched kernel", but this commit only changes…

--

net: tun_vnet: validate hdr_len after skipping header padding

This patch moves the iov_iter_advance() past the virtio header padding in
__tun_vnet_hdr_get() so it happens before the hdr_len check. hdr_len is
then compared against the payload that is really left. With that, a
hdr_len larger than the frame is rejected with -EINVAL in tun_get_user()
and tap_get_user().

> 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.

[Severity: Low]
This commit only changes drivers/net/tun_vnet.h. Which selftests does
"The new tun and tap selftests" refer to?

They appear to be added by a later patch in this series, "selftests: net:
check padded vnet hdr_len in tun and tap". That patch adds
padded_hdr_len_exceeds_payload and padded_hdr_len_zero to
tools/testing/selftests/net/tun.c and tools/testing/selftests/net/tap.c.

Pointing at tests elsewhere in the same series is common. Could the
message name that selftest patch, though, so stable backporters know to
take it as well?

> diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h
> index f4c652b1fa44d..0b96228916814 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;

[Severity: High]
Does this fully close the uninitialized bytes leak that the commit
message describes? The check only limits a non-zero hdr_len, so
hdr_len == 0 always passes.

On the vhost-net zerocopy path, tun_get_user() then falls back to
GOODCOPY_LEN and does not cap it by the remaining payload len:

drivers/net/tun.c:tun_get_user() {
...
if (msg_control) {
...
copylen = min(hdr_len ? hdr_len : GOODCOPY_LEN, good_linear);
linear = copylen;
...
}

tap_get_user() does the same:

drivers/net/tap.c:tap_get_user() {
...
copylen = clamp(hdr_len ?: GOODCOPY_LEN, ETH_HLEN, good_linear);
linear = copylen;
...
}

Take the same 512-byte vnet_hdr_sz and a 14-byte frame. The
handle_tx_zerocopy() threshold (len >= VHOST_GOODCOPY_LEN) includes the
vnet header, so this frame still takes the zerocopy path. After that:

tun_get_user() / tap_get_user()
tun_alloc_skb() / tap_alloc_skb()
skb_put(skb, linear); /* linear == 128 */
zerocopy_sg_from_iter()
int copy = min_t(int, skb_headlen(skb), iov_iter_count(from)); /* 14 */

Can that leave 114 bytes of uninitialized heap in the transmitted frame?
That is the same result this patch sets out to fix.

The trigger needs vhost-net with experimental_zcopytx=1, SOCK_ZEROCOPY on
tap, and a large vnet_hdr_sz set by the host. With those in place, the
guest controls hdr_len == 0 and the frame length.

Two later patches in this series appear to close the gap: "tap: clamp
zero-copy copylen to remaining payload length" and "tun: clamp zero-copy
copylen to remaining payload length". They clamp copylen to len with
min_t() in tap_get_user() and tun_get_user(). Could that dependency be
noted here, or those changes folded into this patch, so this fix is not
backported without them?

>
> - iov_iter_advance(from, sz - parsed_size);
> -
> return hdr_len;
> }

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119144241.360238-1-graypanda.inzag%40gmail.com