2022-10-02 18:13:32

by Guenter Roeck

[permalink] [raw]
Subject: [PATCH] usb: gadget: uvc: Fix clearing of vdev

Commit e4ce9ed835bc ("usb: gadget: uvc: ensure the vdev is unset")
introduced code to clear the video device on video device registration.
However, it uses sizeof(uvc->video) instead of sizeof(uvc->vdev) to clear
uvc->vdev. This may result in the following build error.

In function 'fortify_memset_chk',
inlined from 'uvc_register_video'
at drivers/usb/gadget/function/f_uvc.c:424:2:
include/linux/fortify-string.h:301:25: error:
call to '__write_overflow_field' declared with attribute warning:
detected write beyond size of field

The problem is exposed by commit 9b91a6523078 ("usb: gadget: uvc: increase
worker prio to WQ_HIGHPRI") which increases the size of struct uvc_video.

Fixes: e4ce9ed835bc ("usb: gadget: uvc: ensure the vdev is unset")
Cc: Michael Grzeschik <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
drivers/usb/gadget/function/f_uvc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index e6948cf8def3..836601227155 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -421,7 +421,7 @@ uvc_register_video(struct uvc_device *uvc)
int ret;

/* TODO reference counting. */
- memset(&uvc->vdev, 0, sizeof(uvc->video));
+ memset(&uvc->vdev, 0, sizeof(uvc->vdev));
uvc->vdev.v4l2_dev = &uvc->v4l2_dev;
uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev;
uvc->vdev.fops = &uvc_v4l2_fops;
--
2.36.2


2022-10-02 18:24:36

by Michael Grzeschik

[permalink] [raw]
Subject: Re: [PATCH] usb: gadget: uvc: Fix clearing of vdev

Hi Guenter!

Thanks for the Patch.

On Sun, Oct 02, 2022 at 10:44:30AM -0700, Guenter Roeck wrote:
>Commit e4ce9ed835bc ("usb: gadget: uvc: ensure the vdev is unset")
>introduced code to clear the video device on video device registration.
>However, it uses sizeof(uvc->video) instead of sizeof(uvc->vdev) to clear
>uvc->vdev. This may result in the following build error.
>
>In function 'fortify_memset_chk',
> inlined from 'uvc_register_video'
> at drivers/usb/gadget/function/f_uvc.c:424:2:
>include/linux/fortify-string.h:301:25: error:
> call to '__write_overflow_field' declared with attribute warning:
> detected write beyond size of field
>
>The problem is exposed by commit 9b91a6523078 ("usb: gadget: uvc: increase
>worker prio to WQ_HIGHPRI") which increases the size of struct uvc_video.
>
>Fixes: e4ce9ed835bc ("usb: gadget: uvc: ensure the vdev is unset")
>Cc: Michael Grzeschik <[email protected]>
>Signed-off-by: Guenter Roeck <[email protected]>
>---
> drivers/usb/gadget/function/f_uvc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
>index e6948cf8def3..836601227155 100644
>--- a/drivers/usb/gadget/function/f_uvc.c
>+++ b/drivers/usb/gadget/function/f_uvc.c
>@@ -421,7 +421,7 @@ uvc_register_video(struct uvc_device *uvc)
> int ret;
>
> /* TODO reference counting. */
>- memset(&uvc->vdev, 0, sizeof(uvc->video));
>+ memset(&uvc->vdev, 0, sizeof(uvc->vdev));
> uvc->vdev.v4l2_dev = &uvc->v4l2_dev;
> uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev;
> uvc->vdev.fops = &uvc_v4l2_fops;
>--
>2.36.2

This was already addressed by the following patch some days ago.

https://lore.kernel.org/linux-usb/202209290106.E6EFD95D4@keescook/T/#t

Thanks,
Michael

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (2.10 kB)
signature.asc (849.00 B)
Download all attachments