Skip to contentSkip to conversation

virtio: use masked features with set_features_ex

PATCH New Michael S. Tsirkin 1 participant 2 messages Jul 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 virtio: use masked features with set_features_ex

virtio_set_features_nocheck() calls set_features_ex with guest-supplied feature bits, without masking the value with host features (unlike set_features which gets the correct val & host_features).

This does not matter if the driver matches spec, but drivers can be malicious or buggy and set bit outside the host mask.

Devices don't expect this, so unsupported guest feature bits getting set can break the host. In virtio-net, this can enable RSC without vnet header support and cause out-of-bounds reads from short packets.

Pass the masked features to set_features_ex, consistent with set_features.

Fixes CVE-2026-63321
Fixes 64a6a336f4 ("virtio: add support for negotiating extended features")
Cc Jason Wang <[email protected]>
Cc Yuri Benditovich <[email protected]>
Cc Paolo Abeni <[email protected]>

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3623

---
 hw/virtio/virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio.c +1 -1
index f4d86a3655..7c19080db5 100644
@@ -3320,7 +3320,7 @@ static int virtio_set_features_nocheck(VirtIODevice *vdev, const uint64_t *val)
     virtio_features_and(tmp, val, vdev->host_features_ex);
 
     if (k->set_features_ex) {
-        k->set_features_ex(vdev, val);
+        k->set_features_ex(vdev, tmp);
     } else if (k->set_features) {
         bad = bad || virtio_features_use_ex(tmp);
         k->set_features(vdev, tmp[0]);
Signature · 1 line
MST
#1 lore raw

PATCH 2/2 virtio-net: fix OOB read in RSC receive path

The RSC receive path parses incoming frames at guest_hdr_len byte offsets, but the backend buffer contains only host_hdr_len bytes of vnet header. If the lengths differ, RSC would read at the wrong offset and cause an OOB read.

This is no longer possible after the previous patch, but the assumption seem fragile. Along the defense in depth lines, let's validate. To ensure we are not breaking any valid setups by mistake, warn and fall back to the normal receive path when host_hdr_len != guest_hdr_len.

Fixes CVE-2026-63321
Fixes 2974e916df ("virtio-net: support RSC v4/v6 tcp traffic for Windows HCK")
Cc Jason Wang <[email protected]>
Cc Yuri Benditovich <[email protected]>
Cc Wei Xu <[email protected]>

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3623

---
 hw/net/virtio-net.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/net/virtio-net.c +7 -0
index f0e3beb290..2761644dfd 100644
@@ -2674,6 +2674,13 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf,
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
     if ((n->rsc4_enabled || n->rsc6_enabled)) {
+        /* this never happens with existing backends, but just in case. */
+        if (n->host_hdr_len != n->guest_hdr_len) {
+            warn_report_once("virtio-net: host_hdr_len %zu != guest_hdr_len %zu, "
+                             "skipping RSC",
+                             n->host_hdr_len, n->guest_hdr_len);
+            return virtio_net_do_receive(nc, buf, size);
+        }
         return virtio_net_rsc_receive(nc, buf, size);
     } else {
         return virtio_net_do_receive(nc, buf, size);
Signature · 1 line
MST