linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] vduse: Validate vq_num in vduse_validate_config()
@ 2022-11-28 15:57 Harshit Mogalapalli
  2022-11-29  2:59 ` Jason Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Harshit Mogalapalli @ 2022-11-28 15:57 UTC (permalink / raw)
  To: sgarzare
  Cc: harshit.m.mogalapalli, error27, harshit.m.mogalapalli,
	Michael S . Tsirkin, Jason Wang, Xie Yongji, Gautam Dawar,
	Maxime Coquelin, Parav Pandit, Eli Cohen, virtualization,
	linux-kernel

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>
---
v1->v2: Change title of the commit and description, add a limit to
	vq_num.

v2->v3: Improve commit message to include reason for setting limit to
	0xffff

Only compile and boot tested.
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 35dceee3ed56..31017ebc4d7c 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1440,6 +1440,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config)
 	if (config->config_size > PAGE_SIZE)
 		return false;
 
+	if (config->vq_num > 0xffff)
+		return false;
+
 	if (!device_is_allowed(config->device_id))
 		return false;
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] vduse: Validate vq_num in vduse_validate_config()
  2022-11-28 15:57 [PATCH v3] vduse: Validate vq_num in vduse_validate_config() Harshit Mogalapalli
@ 2022-11-29  2:59 ` Jason Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Wang @ 2022-11-29  2:59 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: sgarzare, error27, harshit.m.mogalapalli, Michael S . Tsirkin,
	Xie Yongji, Gautam Dawar, Maxime Coquelin, Parav Pandit,
	Eli Cohen, virtualization, linux-kernel

On Mon, Nov 28, 2022 at 11:57 PM Harshit Mogalapalli
<harshit.m.mogalapalli@oracle.com> wrote:
>
> 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>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
> v1->v2: Change title of the commit and description, add a limit to
>         vq_num.
>
> v2->v3: Improve commit message to include reason for setting limit to
>         0xffff
>
> Only compile and boot tested.
> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index 35dceee3ed56..31017ebc4d7c 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -1440,6 +1440,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config)
>         if (config->config_size > PAGE_SIZE)
>                 return false;
>
> +       if (config->vq_num > 0xffff)
> +               return false;
> +
>         if (!device_is_allowed(config->device_id))
>                 return false;
>
> --
> 2.38.1
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-29  3:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 15:57 [PATCH v3] vduse: Validate vq_num in vduse_validate_config() Harshit Mogalapalli
2022-11-29  2:59 ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).