drm/virtio: fix bounds check in virtio_gpu_cmd_get_capset()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 4 Jul 2018 09:42:50 +0000 (12:42 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jan 2020 13:49:54 +0000 (14:49 +0100)
commit043bf2daf5a4b791713a7aa43b74ab7ff6ba8789
treedf0054e7675eabd76146e4ac3ab0b8dc65d8cbda
parentcdb273fd8cd4ff99b4c2e0411fe6c705c7cbed62
drm/virtio: fix bounds check in virtio_gpu_cmd_get_capset()

[ Upstream commit 09c4b49457434fa74749ad6194ef28464d9f5df9 ]

This doesn't affect runtime because in the current code "idx" is always
valid.

First, we read from "vgdev->capsets[idx].max_size" before checking
whether "idx" is within bounds.  And secondly the bounds check is off by
one so we could end up reading one element beyond the end of the
vgdev->capsets[] array.

Fixes: 62fb7a5e1096 ("virtio-gpu: add 3d/virgl support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20180704094250.m7sgvvzg3dhcvv3h@kili.mountain
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/virtio/virtgpu_vq.c