>From c4c0f0a489045622360fffab0fdb06067209c01f Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 2 Dec 2026 17:27:31 -0800 Subject: [PATCH 2/2] net/virtio: drop offload packets sent without negotiation If GUEST_CSUM and GUEST_TSO4/6 are not negotiated, the device must not set VIRTIO_NET_HDR_F_NEEDS_CSUM or a gso_type in the receive header. VirtualBox does it anyway when the host interface uses GRO. The driver ignores the header when no receive offload is enabled, so the application gets a packet with a partial checksum and larger than the MTU, with nothing in the mbuf to say so. It then fails checksum validation, or gets forwarded and dropped further down the path. Check the header in the non-vector receive paths. If the device violates the negotiation, drop the packet, count it in the error statistics and log the reason once. A compliant device never triggers this, so no hypervisor detection is needed. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01F2mfDETH9cBBVF3tcqkwcH --- drivers/net/virtio/virtio_rxtx.c | 53 +++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 7cdab4b..4ce9162 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -987,6 +987,46 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr) return 0; } +/* Report once that the device ignores feature negotiation */ +static __rte_cold __rte_noinline void +virtio_rx_hdr_unexpected(const struct virtio_hw *hw, + const struct virtio_net_hdr *hdr) +{ + static bool warned; + + if (warned) + return; + warned = true; + + PMD_DRV_LOG(ERR, + "port %u: device sent flags %#x gso_type %#x without GUEST_CSUM/GUEST_TSO negotiated, dropping such packets", + hw->port_id, hdr->flags, hdr->gso_type); +} + +/* + * Process the receive header. + * + * If no receive offload feature was negotiated, the device is required + * to set neither NEEDS_CSUM nor a gso_type. Some devices do it anyway. + * The application did not ask for packets with a partial checksum or + * larger than MTU, so do not pass them up. + */ +static inline int +virtio_rx_hdr(const struct virtio_hw *hw, struct rte_mbuf *m, + struct virtio_net_hdr *hdr) +{ + if (hw->has_rx_offload) + return virtio_rx_offload(m, hdr); + + if (unlikely((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) || + hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE)) { + virtio_rx_hdr_unexpected(hw, hdr); + return -EINVAL; + } + + return 0; +} + /* * A mergeable packet is complete: pass it up or drop it. * The drop has to wait until here, the remaining buffers of the @@ -1066,7 +1106,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) if (hw->vlan_strip) rte_vlan_strip(rxm); - if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) { + if (virtio_rx_hdr(hw, rxm, hdr) < 0) { virtio_discard_rxbuf(vq, rxm); rxvq->stats.errors++; continue; @@ -1171,7 +1211,7 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, if (hw->vlan_strip) rte_vlan_strip(rxm); - if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) { + if (virtio_rx_hdr(hw, rxm, hdr) < 0) { virtio_discard_rxbuf(vq, rxm); rxvq->stats.errors++; continue; @@ -1293,8 +1333,7 @@ virtio_recv_pkts_inorder(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - drop = hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0; + drop = virtio_rx_hdr(hw, rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1466,8 +1505,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - drop = hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0; + drop = virtio_rx_hdr(hw, rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1632,8 +1670,7 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - drop = hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0; + drop = virtio_rx_hdr(hw, rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); -- 2.43.0