Re: [PATCH net] tap: clamp zero-copy copylen to remaining payload length
From: Junyoung Jang
Date: Wed Nov 18 2026 - 05:21:30 EST
Apologies for the noise — I accidentally sent out an unfinished local
draft that still had an unreplaced placeholder in the Fixes tag and
was missing a Co-developed-by trailer.
Thanks as well for pointing out the oversized hdr_len path via
__tun_vnet_hdr_get(). I will send a corrected v2 shortly with the
proper trailers and an updated commit message/comment covering both
paths, and will check tun_get_user() separately.
pw-bot: cr
On Wed, Nov 18, 2026 at 2:03 AM <netdev-bot+sashiko@xxxxxxxxxx> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 (1) · Medium: 1 · 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).
>
> - [Medium] The Fixes: trailer in the commit message is an unfilled
> template: `Fixes: <12자리_커밋_해시> ("<원본_커밋_제목>")`.
> - [Low] The commit message and the new comment ("A padded vnet header can
> leave fewer payload bytes than GOODCOPY_LEN.") describe only the…
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but tun_get_user()
> in drivers/net/tun.c has the same unbounded zero-copy copylen.
>
> --
>
> tap: clamp zero-copy copylen to remaining payload length
>
> This commit clamps copylen in the zero-copy TX branch of tap_get_user()
> to the remaining payload length. Without the clamp, a padded vnet header
> can leave fewer frame bytes than GOODCOPY_LEN, and the uninitialized
> part of the skb linear head is then transmitted.
>
> > Fixes: <12자리_커밋_해시> ("<원본_커밋_제목>")
>
> [Severity: Medium]
> This trailer looks like an unfilled template. The placeholders translate
> to "<12-digit commit hash>" and "<original commit title>".
>
> The trailer sits above the --- separator, so git am keeps it in the
> applied commit, and stable tooling can't use it to select the fix for
> backporting.
>
> Could this cite the commit that introduced the zero-copy copylen sizing
> in tap_get_user()? That would be either the macvtap zerocopy support or
> the later copylen clamp rework.
>
> > diff --git a/drivers/net/tap.c b/drivers/net/tap.c
> > index 2f19fb07bb2d4..b1f8776a5ca57 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);
> > + /* A padded vnet header can leave fewer payload bytes than GOODCOPY_LEN. */
> > + copylen = min_t(unsigned long, copylen, len);
>
> [Severity: Low]
> The comment and the commit message only describe the case where
> hdr_len == 0 falls back to GOODCOPY_LEN. Doesn't this min_t() also close
> a second trigger?
>
> __tun_vnet_hdr_get() checks hdr_len against the iterator count before it
> skips the header padding:
>
> drivers/net/tun_vnet.h:__tun_vnet_hdr_get() {
> ...
> if (hdr_len > iov_iter_count(from))
> return -EINVAL;
>
> iov_iter_advance(from, sz - parsed_size);
> ...
> }
>
> That means a guest-supplied hdr_len is bounded by payload plus padding,
> not by len. Before this patch, with a large TUNSETVNETHDRSZ,
> clamp(hdr_len, ETH_HLEN, good_linear) could reach good_linear while len
> is only 14. The leak would then be much larger than the 114 bytes
> described.
>
> Should the changelog and the comment mention this path, so the size of
> the disclosure isn't understated?
>
> [Severity: High]
> This is a pre-existing issue and wasn't introduced by this patch, but
> does tun_get_user() in drivers/net/tun.c have the same unbounded
> copylen?
>
> drivers/net/tun.c:tun_get_user() {
> ...
> copylen = min(hdr_len ? hdr_len : GOODCOPY_LEN, good_linear);
> linear = copylen;
> ...
> }
>
> Nothing bounds copylen to len there. When zerocopy is set,
> tun_can_build_skb() returns false, and tun_alloc_skb() calls
> skb_put(skb, linear) with linear == copylen. zerocopy_sg_from_iter()
> then copies only min(skb_headlen(skb), iov_iter_count(from)) bytes into
> the head.
>
> Both triggers seem to apply to tun:
>
> - the 246-byte vnet header plus 14-byte frame from the commit message
> (tun_vnet_ioctl() only enforces a lower bound on the header size)
> - an oversized guest hdr_len, as described above
>
> tun_chr_open() sets SOCK_ZEROCOPY unconditionally. With
> vhost_net.experimental_zcopytx=1, the more common tun backend would
> therefore still put uninitialized host heap bytes on the wire.
>
> The notes below the --- cite the analogous tun.c report. Is a matching
> fix for tun_get_user() planned?
>
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113164903.785381-1-graypanda.inzag%40gmail.com