struct vring_desc *idesc = NULL;
struct vring *s_vring;
uint64_t dlen;
+ uint32_t nr_descs;
int ret;
uint8_t perm;
s_vring->avail->ring[idx_m & (vq->size - 1)] = desc_id;
desc_ring = vq->desc;
+ nr_descs = vq->size;
if (vq->desc[desc_id].flags & VRING_DESC_F_INDIRECT) {
dlen = vq->desc[desc_id].len;
+ nr_descs = dlen / sizeof(struct vring_desc);
+ if (unlikely(nr_descs > vq->size))
+ return -1;
+
desc_ring = (struct vring_desc *)(uintptr_t)
vhost_iova_to_vva(dev, vq,
vq->desc[desc_id].addr, &dlen,
do {
if (unlikely(desc_id >= vq->size))
goto fail;
+ if (unlikely(nr_descs-- == 0))
+ goto fail;
desc = desc_ring[desc_id];
perm = desc.flags & VRING_DESC_F_WRITE ?
VHOST_ACCESS_WO : VHOST_ACCESS_RO;
struct vring_desc *idesc = NULL;
struct vring *s_vring;
uint64_t dlen;
+ uint32_t nr_descs;
int ret;
if (!dev || !vring_m)
desc_id = vq->used->ring[idx & (vq->size - 1)].id;
desc_ring = vq->desc;
+ nr_descs = vq->size;
if (unlikely(desc_id >= vq->size))
return -1;
if (vq->desc[desc_id].flags & VRING_DESC_F_INDIRECT) {
dlen = vq->desc[desc_id].len;
+ nr_descs = dlen / sizeof(struct vring_desc);
+ if (unlikely(nr_descs > vq->size))
+ return -1;
+
desc_ring = (struct vring_desc *)(uintptr_t)
vhost_iova_to_vva(dev, vq,
vq->desc[desc_id].addr, &dlen,
do {
if (unlikely(desc_id >= vq->size))
goto fail;
+ if (unlikely(nr_descs-- == 0))
+ goto fail;
desc = desc_ring[desc_id];
if (desc.flags & VRING_DESC_F_WRITE)
vhost_log_write(dev, desc.addr, desc.len);