Skip to content

Commit

Permalink
vhost: fix missing check on virtqueue access
Browse files Browse the repository at this point in the history
[ upstream commit 094c442cdbf1da3a19ae82ca7069fee8b3a43343 ]

Acquiring the access lock is not enough to ensure
virtqueue's metadata such as vring pointers are valid.

The access status must also be checked.

Fixes: 4e0de8d ("vhost: protect vring access done by application")

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Acked-by: David Marchand <david.marchand@redhat.com>
  • Loading branch information
mcoquelin authored and bluca committed Nov 8, 2023
1 parent db07b9f commit 6a3395a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/librte_vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,10 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)

rte_spinlock_lock(&vq->access_lock);

if (unlikely(!vq->enabled || vq->avail == NULL))
if (unlikely(!vq->access_ok))
goto out;

if (unlikely(!vq->enabled))
goto out;

ret = *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx;
Expand Down Expand Up @@ -1433,9 +1436,15 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)

rte_spinlock_lock(&vq->access_lock);

if (unlikely(!vq->access_ok)) {
ret = -1;
goto out_unlock;
}

vq->notif_enable = enable;
ret = vhost_enable_guest_notification(dev, vq, enable);

out_unlock:
rte_spinlock_unlock(&vq->access_lock);

return ret;
Expand Down Expand Up @@ -1495,7 +1504,10 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid)

rte_spinlock_lock(&vq->access_lock);

if (unlikely(vq->enabled == 0 || vq->avail == NULL))
if (unlikely(!vq->access_ok))
goto out;

if (unlikely(!vq->enabled))
goto out;

ret = *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx;
Expand Down

0 comments on commit 6a3395a

Please sign in to comment.