Commit cf8f1696 authored by Matthias Lange's avatar Matthias Lange Committed by Michael S. Tsirkin

virtio_ring: fix unmap of indirect descriptors

The function virtqueue_add_split() DMA-maps the scatterlist buffers. In
case a mapping error occurs the already mapped buffers must be unmapped.
This happens by jumping to the 'unmap_release' label.

In case of indirect descriptors the release is wrong and may leak kernel
memory. Because the implementation assumes that the head descriptor is
already mapped it starts iterating over the descriptor list starting
from the head descriptor. However for indirect descriptors the head
descriptor is never mapped in case of an error.

The fix is to initialize the start index with zero in case of indirect
descriptors and use the 'desc' pointer directly for iterating over the
descriptor chain.
Signed-off-by: default avatarMatthias Lange <matthias.lange@kernkonzept.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 02fa5d7b
...@@ -566,13 +566,17 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, ...@@ -566,13 +566,17 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
unmap_release: unmap_release:
err_idx = i; err_idx = i;
i = head;
if (indirect)
i = 0;
else
i = head;
for (n = 0; n < total_sg; n++) { for (n = 0; n < total_sg; n++) {
if (i == err_idx) if (i == err_idx)
break; break;
vring_unmap_one_split(vq, &desc[i]); vring_unmap_one_split(vq, &desc[i]);
i = virtio16_to_cpu(_vq->vdev, vq->split.vring.desc[i].next); i = virtio16_to_cpu(_vq->vdev, desc[i].next);
} }
if (indirect) if (indirect)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment