Re: [PATCH net v3 3/4] tun: clamp zero-copy copylen to remaining payload length
From: Willem de Bruijn
Date: Thu Nov 19 2026 - 16:13:43 EST
Junyoung Jang wrote:
> tun_get_user() also derives copylen from hdr_len or GOODCOPY_LEN
> without bounding it to len after removing the virtio header. A
> padded header can make a short frame cross vhost-net's zero-copy
> threshold. tun_alloc_skb() then reserves more linear packet data than
> zerocopy_sg_from_iter() copies, and the uncopied tail can be delivered
> to the network stack.
>
> Limit copylen to len before the NAPI fragments and skb allocation
> branches. The requested copy length then cannot exceed the supplied
> payload. The normal skb-building path is unchanged.
>
> This matching tun issue was noted during review of the tap zero-copy
> fix. An AI coding assistant helped prepare the /dev/net/tun
> reproducer. In x86-64 QEMU/vhost-net, a 14-byte input produced a
> 128-byte frame with a nonzero uncopied tail. The patched kernel
> delivered 14 bytes, completed 300 repeated short sends, and still
> selected zero-copy for a later 400-byte frame.
>
> Suggested-by: Willem de Bruijn <willemdebruijn.kernel@xxxxxxxxx>
> Fixes: 0690899b4d45 ("tun: experimental zero copy tx support")
> Co-developed-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>
Reviewed-by: Willem de Bruijn <willemb@xxxxxxxxxx>
Thanks for converting the original patch into this more complete
series.