Skip to content

Commit e152d8a

Browse files
Dan Carpentermstsirkin
authored andcommitted
virtio_ring: Fix two use after free bugs
The "vq" struct is added to the "vdev->vqs" list prematurely. If we encounter an error later in the function then the "vq" is freed, but since it is still on the list that could lead to a use after free bug. Fixes: cbeedb7 ("virtio_ring: allocate desc state for split ring separately") Reported-by: Robert Buhren <robert.buhren@sect.tu-berlin.de> Reported-by: Felicitas Hetzelt <file@sect.tu-berlin.de> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/X8pGaG/zkI3jk8mk@mwanda Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 411ea23 commit e152d8a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/virtio/virtio_ring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,6 @@ static struct virtqueue *vring_create_virtqueue_packed(
16081608
vq->num_added = 0;
16091609
vq->packed_ring = true;
16101610
vq->use_dma_api = vring_use_dma_api(vdev);
1611-
list_add_tail(&vq->vq.list, &vdev->vqs);
16121611
#ifdef DEBUG
16131612
vq->in_use = false;
16141613
vq->last_add_time_valid = false;
@@ -1669,6 +1668,7 @@ static struct virtqueue *vring_create_virtqueue_packed(
16691668
cpu_to_le16(vq->packed.event_flags_shadow);
16701669
}
16711670

1671+
list_add_tail(&vq->vq.list, &vdev->vqs);
16721672
return &vq->vq;
16731673

16741674
err_desc_extra:
@@ -2085,7 +2085,6 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
20852085
vq->last_used_idx = 0;
20862086
vq->num_added = 0;
20872087
vq->use_dma_api = vring_use_dma_api(vdev);
2088-
list_add_tail(&vq->vq.list, &vdev->vqs);
20892088
#ifdef DEBUG
20902089
vq->in_use = false;
20912090
vq->last_add_time_valid = false;
@@ -2127,6 +2126,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
21272126
memset(vq->split.desc_state, 0, vring.num *
21282127
sizeof(struct vring_desc_state_split));
21292128

2129+
list_add_tail(&vq->vq.list, &vdev->vqs);
21302130
return &vq->vq;
21312131
}
21322132
EXPORT_SYMBOL_GPL(__vring_new_virtqueue);

0 commit comments

Comments
 (0)