[PATCH net-next v5 2/9] virtio-net: zero the whole tx header
From: Steffen Trumtrar
Date: Thu Nov 12 2026 - 07:28:52 EST
xmit_skb() builds the virtio-net header either in skb->cb or in the
headroom in front of the packet. virtio_net_hdr_tnl_from_skb() only
clears struct virtio_net_hdr (10 bytes) and, for tunnel GSO, the hash
fields; num_buffers is cleared only with mergeable rx buffers. With a
larger negotiated header the remaining bytes go to the device as they
were in skb->cb or the headroom:
- num_buffers with VIRTIO_F_VERSION_1 but without
VIRTIO_NET_F_MRG_RXBUF (header size 12),
- hash_value, hash_report and padding with
VIRTIO_NET_F_HASH_REPORT (header size 20),
- additionally outer_th_offset and inner_nh_offset for packets
without tunnel GSO if a UDP tunnel GSO feature was negotiated
(header size 24).
Clear the whole header before filling it in. This also covers
num_buffers, so drop the separate assignment.
The helpers still clear struct virtio_net_hdr and, for tunnel GSO, the
hash fields themselves; that is now redundant here, but they are
shared with tun, tap, af_packet and the UML vector driver and stay as
they are.
Signed-off-by: Steffen Trumtrar <s.trumtrar@xxxxxxxxxxxxxx>
---
drivers/net/virtio_net.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index dd2c41ef6fbe7..4c740b403ad1e 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -3326,14 +3326,16 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan)
else
hdr = &skb_vnet_common_hdr(skb)->tnl_hdr;
+ /* Fields the helper below does not fill in must not carry stale
+ * skb->cb or headroom bytes to the device.
+ */
+ memset(hdr, 0, hdr_len);
+
if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl,
virtio_is_little_endian(vi->vdev), 0,
false, feature_hdrlen))
return -EPROTO;
- if (vi->mergeable_rx_bufs)
- hdr->hash_hdr.hdr.num_buffers = 0;
-
sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2));
if (can_push) {
__skb_push(skb, hdr_len);
--
2.56.0