Skip to contentSkip to conversation

usb: gadget: uvc: Fix clearing of vdev

PATCH In review Guenter Roeck 2 participants 2 messages Oct 2, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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]>
---
 drivers/usb/gadget/function/f_uvc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_uvc.c +1 -1
index e6948cf8def3..836601227155 100644
@@ -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;
Signature · 1 line
2.36.2
#1 lore raw

Hi Guenter!

Thanks for the Patch.

Quoted 37 lines · Guenter Roeck

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]>

---
drivers/usb/gadget/function/f_uvc.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_uvc.c +1 -1
index e6948cf8def3..836601227155 100644
@@ -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;
Signature · 1 line
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

Signature · 4 lines
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 |