Sasha Levin
2021-Aug-24 00:53 UTC
[PATCH AUTOSEL 5.13 08/26] virtio_vdpa: reject invalid vq indices
From: Vincent Whitchurch <vincent.whitchurch at axis.com> [ Upstream commit cb5d2c1f6cc0e5769099a7d44b9d08cf58cae206 ] Do not call vDPA drivers' callbacks with vq indicies larger than what the drivers indicate that they support. vDPA drivers do not bounds check the indices. Signed-off-by: Vincent Whitchurch <vincent.whitchurch at axis.com> Link: https://lore.kernel.org/r/20210701114652.21956-1-vincent.whitchurch at axis.com Signed-off-by: Michael S. Tsirkin <mst at redhat.com> Acked-by: Jason Wang <jasowang at redhat.com> Reviewed-by: Stefano Garzarella <sgarzare at redhat.com> Signed-off-by: Sasha Levin <sashal at kernel.org> --- drivers/virtio/virtio_vdpa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index e28acf482e0c..e9b9dd03f44a 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -149,6 +149,9 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, if (!name) return NULL; + if (index >= vdpa->nvqs) + return ERR_PTR(-ENOENT); + /* Queue shouldn't already be set up. */ if (ops->get_vq_ready(vdpa, index)) return ERR_PTR(-ENOENT); -- 2.30.2