Skip to content

Commit

Permalink
vhost: validate index in inflight API
Browse files Browse the repository at this point in the history
[ upstream commit d2475e8 ]

This patch validates the queue index parameter, in order
to ensure neither out-of-bound accesses nor NULL pointer
dereferencing happen.

Fixes: 4d891f7 ("vhost: add APIs to get inflight ring")

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
mcoquelin authored and bluca committed Nov 9, 2020
1 parent 215263f commit 4a20f64
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/librte_vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,15 +1505,23 @@ rte_vhost_get_vring_base_from_inflight(int vid,
uint16_t *last_used_idx)
{
struct rte_vhost_inflight_info_packed *inflight_info;
struct vhost_virtqueue *vq;
struct virtio_net *dev = get_device(vid);

if (dev == NULL || last_avail_idx == NULL || last_used_idx == NULL)
return -1;

if (queue_id >= VHOST_MAX_VRING)
return -1;

vq = dev->virtqueue[queue_id];
if (!vq)
return -1;

if (!vq_is_packed(dev))
return -1;

inflight_info = dev->virtqueue[queue_id]->inflight_packed;
inflight_info = vq->inflight_packed;
if (!inflight_info)
return -1;

Expand Down

0 comments on commit 4a20f64

Please sign in to comment.