[PATCH net v3 1/4] net: tun_vnet: validate hdr_len after skipping header padding
From: Junyoung Jang
Date: Thu Nov 19 2026 - 09:44:07 EST
__tun_vnet_hdr_get() checks hdr_len against iov_iter_count(from) before
advancing past the configured virtio header padding. With a 512-byte
header and a 14-byte Ethernet frame, hdr_len=256 passes because the
iterator still includes header padding. After the advance, only
14 bytes remain. tun_get_user() and tap_get_user() can then reserve a
linear skb area larger than the frame and transmit uncopied bytes.
Advance past the padding before comparing hdr_len with the remaining
payload. Both callers return immediately on error and discard their
iterator, so the cursor position on -EINVAL is not observable by them.
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.
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@xxxxxxxxx>
Fixes: 2506251e81d1 ("tun: Decouple vnet handling")
Fixes: 6a53fc5a8770 ("tap: Use tun's vnet-related code")
Co-developed-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>
---
drivers/net/tun_vnet.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h
index f4c652b1fa44..0b9622891681 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;
- iov_iter_advance(from, sz - parsed_size);
-
return hdr_len;
}
--
2.43.0