Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Steffen Trumtrar
Thu, 12 Nov 2026 11:19
[PATCH net-next v5 2/9] virtio-net: zero the whole tx header
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
Date: Thu, 12 Nov 2026 11:19
56 lines
12649 bytes
12649 bytes
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@pengutronix.de>
---
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
Re: [PATCH net-next v5 2/9] virtio-net: zero the whole tx header
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:55
Date: Mon, 16 Nov 2026 13:55
104 lines
12362 bytes
12362 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · 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 commit fixes a real bug: virtio-net TX headers reach the
device with stale or uninitialised bytes.
- [Low] The commit message says the bytes the helper does not set "go to
the device as they were in skb->cb or the headroom", but it never says…
--
virtio-net: zero the whole tx header
This commit clears the whole negotiated virtio-net header in xmit_skb()
before virtio_net_hdr_tnl_from_skb() fills it in. Bytes past struct
virtio_net_hdr no longer carry stale skb->cb or headroom contents to the
device. The separate num_buffers assignment for mergeable rx buffers is
dropped because the memset covers it.
> 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);
> +
[Severity: Medium]
This fixes uninitialized bytes reaching the device. Should it carry a Fixes:
tag and go to net on its own, rather than as part of a net-next series?
Before this change, non-tunnel skbs only went through
virtio_net_hdr_from_skb(). That clears sizeof(struct virtio_net_hdr), which
is 10 bytes.
virtnet_probe() sets vi->hdr_len to 12 (VIRTIO_F_VERSION_1 or MRG_RXBUF), 20
(hash report) or 24 (UDP tunnel GSO). So bytes 10 through hdr_len - 1 went to
the device unchanged from skb->cb or the headroom.
The 24-byte layout and the current form of the num_buffers assignment come
from this commit, which is in currently maintained stable kernels:
Fixes: 56a06bd40fab ("virtio_net: enable gso over UDP tunnel support.")
The 12-byte and 20-byte cases are older, so their origin commits could be
named as well.
Without the tag, the fix only lives in a net-next feature series (RX
timestamp support). Would stable and distro kernels then keep sending up to
14 stale bytes per packet?
> 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;
> -
[Severity: Low]
The commit message says the remaining bytes "go to the device as they were
in skb->cb or the headroom". It does not say that this exposes kernel memory
to the device. Could the message state that?
In the can_push case of xmit_skb(), hdr points into the skb headroom:
if (can_push)
hdr = (struct virtio_net_hdr_v1_hash_tunnel *)(skb->data -
hdr_len);
The skb allocators don't zero the headroom, and nothing writes the bytes in
front of the Ethernet header. So up to 14 bytes of uninitialized slab
content per packet ended up in buffers the device can read. This matters
when the host or backend is not trusted, for example SEV-SNP/TDX guests or
VDUSE and vhost-user backends.
Also, the virtio spec requires the driver to set num_buffers to zero on
transmit, so a non-zero value there breaks the spec.
The XDP TX path in the same driver already zeroes the whole header in
__virtnet_xdp_xmit_one():
memset(hdr, 0, vi->hdr_len);
Without words like "info leak" or "uninitialized memory", might maintainers
and stable reviewers treat this patch as a cleanup?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-v6-7-topic-virtio-net-ptp-v5-0-7ab67b572f4f%40pengutronix.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads