Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: graypanda.inzag@gmail.com
Cc: willemdebruijn.kernel@gmail.com, jasowangio@gmail.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	shuah@kernel.org, gwanhyunlee@gmail.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding
Date: Mon, 23 Nov 2026 15:38:10 +0000	[thread overview]
Message-ID: <179544829010.3135.9748959187466482821@kernel.org> (raw)
In-Reply-To: <20261119144241.360238-2-graypanda.inzag@gmail.com>

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

  parent reply	other threads:[~2026-11-23 15:38 UTC|newest]

Thread overview: 10+ 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-23 15:38   ` netdev-bot+sashiko [this message]
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

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=179544829010.3135.9748959187466482821@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=graypanda.inzag@gmail.com \
    --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