]> git.ipfire.org Git - thirdparty/qemu.git/commit
virtio: fix off-by-one and invalid access in virtqueue_ordered_fill
authorJonah Palmer <jonah.palmer@oracle.com>
Mon, 21 Jul 2025 15:02:08 +0000 (15:02 +0000)
committerMichael Tokarev <mjt@tls.msk.ru>
Sat, 2 Aug 2025 05:11:22 +0000 (08:11 +0300)
commitf8af00503728aec83ab8b760a1deb8ba3cb5988f
tree6f81e3b54c8df9d90b7dc92584fc740c2f3ae27d
parentd6b2796a2831d4ba40021cc260c06ca6c6dc8130
virtio: fix off-by-one and invalid access in virtqueue_ordered_fill

Commit b44135daa372 introduced virtqueue_ordered_fill for
VIRTIO_F_IN_ORDER support but had a few issues:

* Conditional while loop used 'steps <= max_steps' but should've been
  'steps < max_steps' since reaching steps == max_steps would indicate
  that we didn't find an element, which is an error. Without this
  change, the code would attempt to read invalid data at an index
  outside of our search range.

* Incremented 'steps' using the next chain's ndescs instead of the
  current one.

This patch corrects the loop bounds and synchronizes 'steps' and index
increments.

We also add a defensive sanity check against malicious or invalid
descriptor counts to avoid a potential infinite loop and DoS.

Fixes: b44135daa372 ("virtio: virtqueue_ordered_fill - VIRTIO_F_IN_ORDER support")
Reported-by: terrynini <terrynini38514@gmail.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
Message-Id: <20250721150208.2409779-1-jonah.palmer@oracle.com>
Reviewed-by: Si-Wei Liu <si-wei.liu@oracle.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit 6fcf5ebafad65adc19a616260ca7dc90005785d1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
hw/virtio/virtio.c