vduse: Validate vq_num in vduse_validate_config()
authorHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Mon, 28 Nov 2022 15:57:15 +0000 (07:57 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Jan 2023 06:24:31 +0000 (07:24 +0100)
commitc6c6af90101f9f7dd2dc0330f48497cc55b37941
treed757fcb8f9eac5001661fd1561ba64c123960f92
parentab23a6dbfc7232a6d5b6baff781ad1f3d32dbdb0
vduse: Validate vq_num in vduse_validate_config()

[ Upstream commit 937c783aa3d8d77963ec91918d3298edb45b9161 ]

Add a limit to 'config->vq_num' which is user controlled data which
comes from an vduse_ioctl to prevent large memory allocations.

Micheal says  - This limit is somewhat arbitrary.
However, currently virtio pci and ccw are limited to a 16 bit vq number.
While MMIO isn't it is also isn't used with lots of VQs due to
current lack of support for per-vq interrupts.
Thus, the 0xffff limit on number of VQs corresponding
to a 16-bit VQ number seems sufficient for now.

This is found using static analysis with smatch.

Suggested-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Message-Id: <20221128155717.2579992-1-harshit.m.mogalapalli@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/vdpa/vdpa_user/vduse_dev.c