[v2,4/7] vhost: fix check on virtqueue access in async registration
Checks
Commit Message
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: 78639d54563a ("vhost: introduce async enqueue registration API")
Cc: stable@dpdk.org
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/vhost/vhost.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
@@ -1857,7 +1857,15 @@ rte_vhost_async_channel_register(int vid, uint16_t queue_id)
return -1;
rte_rwlock_write_lock(&vq->access_lock);
+
+ if (unlikely(!vq->access_ok)) {
+ ret = -1;
+ goto out_unlock;
+ }
+
ret = async_channel_register(dev, vq);
+
+out_unlock:
rte_rwlock_write_unlock(&vq->access_lock);
return ret;
@@ -1909,6 +1917,11 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
return ret;
}
+ if (unlikely(!vq->access_ok)) {
+ ret = -1;
+ goto out_unlock;
+ }
+
if (!vq->async) {
ret = 0;
} else if (vq->async->pkts_inflight_n) {
@@ -1920,6 +1933,7 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
ret = 0;
}
+out_unlock:
rte_rwlock_write_unlock(&vq->access_lock);
return ret;