Skip to content

Commit

Permalink
vhost: fix packed ring potential buffer overflow
Browse files Browse the repository at this point in the history
[ upstream commit 93ed2f4 ]

Similar as split ring, the multiple accesses of descriptor length will
lead to potential risk. One-time access of descriptor length can
eliminate this risk.

Fixes: 2f3225a ("vhost: add vector filling support for packed ring")

Signed-off-by: Marvin Liu <yong.liu@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  • Loading branch information
MarvinLiu123 authored and cpaelzer committed May 11, 2021
1 parent a6eda73 commit 5075e41
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/librte_vhost/virtio_net.c
Expand Up @@ -667,9 +667,10 @@ fill_vec_buf_packed_indirect(struct virtio_net *dev,
return -1;
}

*len += descs[i].len;
dlen = descs[i].len;
*len += dlen;
if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
descs[i].addr, descs[i].len,
descs[i].addr, dlen,
perm)))
return -1;
}
Expand All @@ -690,6 +691,7 @@ fill_vec_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
bool wrap_counter = vq->avail_wrap_counter;
struct vring_packed_desc *descs = vq->desc_packed;
uint16_t vec_id = *vec_idx;
uint64_t dlen;

if (avail_idx < vq->last_avail_idx)
wrap_counter ^= 1;
Expand Down Expand Up @@ -722,11 +724,12 @@ fill_vec_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
len, perm) < 0))
return -1;
} else {
*len += descs[avail_idx].len;
dlen = descs[avail_idx].len;
*len += dlen;

if (unlikely(map_one_desc(dev, vq, buf_vec, &vec_id,
descs[avail_idx].addr,
descs[avail_idx].len,
dlen,
perm)))
return -1;
}
Expand Down

0 comments on commit 5075e41

Please sign in to comment.