Skip to content

Commit

Permalink
hw/virtio-iommu: Fix potential OOB access in virtio_iommu_handle_comm…
Browse files Browse the repository at this point in the history
…and()

In the virtio_iommu_handle_command() when a PROBE request is handled,
output_size takes a value greater than the tail size and on a subsequent
iteration we can get a stack out-of-band access. Initialize the
output_size on each iteration.

The issue was found with ASAN. Credits to:
Yiming Tao(Zhejiang University)
Gaoning Pan(Zhejiang University)

Fixes: 1733eeb ("virtio-iommu: Implement RESV_MEM probe request")
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reported-by: Mauro Matteo Cascella <mcascell@redhat.com>
Cc: qemu-stable@nongnu.org

Message-Id: <20230717162126.11693-1-eric.auger@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit cf2f89e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
eauger authored and Michael Tokarev committed Aug 4, 2023
1 parent 71e05c4 commit 18963f4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hw/virtio/virtio-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,15 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)
VirtIOIOMMU *s = VIRTIO_IOMMU(vdev);
struct virtio_iommu_req_head head;
struct virtio_iommu_req_tail tail = {};
size_t output_size = sizeof(tail), sz;
VirtQueueElement *elem;
unsigned int iov_cnt;
struct iovec *iov;
void *buf = NULL;
size_t sz;

for (;;) {
size_t output_size = sizeof(tail);

elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
if (!elem) {
return;
Expand Down

0 comments on commit 18963f4

Please sign in to comment.