Skip to contentSkip to conversation

hw/virtio-iommu: Fix potential OOB access in virtio_iommu_handle_command()

PATCH In review Eric Auger 2 participants 3 messages Jul 17, 2023

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH v2 1/1 hw/virtio-iommu: Fix potential OOB access in virtio_iommu_handle_command()

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 1733eebb9e7 ("virtio-iommu: Implement RESV_MEM probe request")

---
- added the Cc: [email protected] and copied 2 persons involved in the reporting loop

---
 hw/virtio/virtio-iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/virtio/virtio-iommu.c +3 -1
index 201127c488..4dcf1d5c62 100644
@@ -728,13 +728,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;
Signature · 1 line
2.38.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Eric Auger

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.

A backtrace would be helpful (or reproducer).

Quoted 7 lines

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

Fixes 1733eebb9e7 ("virtio-iommu: Implement RESV_MEM probe request")

Did you mean:

?

Quoted 8 lines

---
- added the Cc: [email protected] and copied 2 persons involved in the reporting loop

---
  hw/virtio/virtio-iommu.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
author
#2 lore raw

Hi Philippe,

Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Eric Auger

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.

A backtrace would be helpful (or reproducer).

Well the way to hit it in explained above. PROBE request followed by a different request consumed within the same virtio_iommu_handle_command() call

Quoted 9 lines
Quoted 8 lines

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

Fixes 1733eebb9e7 ("virtio-iommu: Implement RESV_MEM probe request")
Quoted 5 lines

Did you mean:

?

If I understand correctly trhe actual people who found the issue using the tool were those I mentionned in the credits section in the commit msg. but unfortunately I don't have their full address. Mauro Matteo forwarded me the report which transited though Yiming Tao. Anyway I will be glad to put more precise in the R-b tags if I get some additional info.

Thanks

Eric

Quoted 12 lines
Quoted 9 lines

---
- added the Cc: [email protected] and copied 2 persons involved in the reporting loop
---
  hw/virtio/virtio-iommu.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)