linux/drivers/media/usb/uvc
Xiaomeng Tong 261f33388c media: uvcvideo: Fix missing check to determine if element is found in list
The list iterator will point to a bogus position containing HEAD if
the list is empty or the element is not found in list. This case
should be checked before any use of the iterator, otherwise it will
lead to a invalid memory access. The missing check here is before
"pin = iterm->id;", just add check here to fix the security bug.

In addition, the list iterator value will *always* be set and non-NULL
by list_for_each_entry(), so it is incorrect to assume that the iterator
value will be NULL if the element is not found in list, considering
the (mis)use here: "if (iterm == NULL".

Use a new value 'it' as the list iterator, while use the old value
'iterm' as a dedicated pointer to point to the found element, which
1. can fix this bug, due to 'iterm' is NULL only if it's not found.
2. do not need to change all the uses of 'iterm' after the loop.
3. can also limit the scope of the list iterator 'it' *only inside*
   the traversal loop by simply declaring 'it' inside the loop in the
   future, as usage of the iterator outside of the list_for_each_entry
   is considered harmful. https://lkml.org/lkml/2022/2/17/1032

Fixes: d5e90b7a6c ("[media] uvcvideo: Move to video_ioctl2")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-05-08 07:08:53 +02:00
..
Kconfig media: Kconfig: cleanup VIDEO_DEV dependencies 2022-03-18 05:58:35 +01:00
Makefile media: uvcvideo: Add a metadata device node 2018-01-04 06:41:47 -05:00
uvc_ctrl.c media: uvcvideo: Avoid returning invalid controls 2021-12-07 11:29:54 +01:00
uvc_debugfs.c media: usb: uvc: no need to check return value of debugfs_create functions 2020-09-26 10:15:17 +02:00
uvc_driver.c media: docs: media: uvcvideo: Use linux-media mailing list 2022-05-08 07:08:23 +02:00
uvc_entity.c media: uvcvideo: Use dev_ printk aliases 2021-01-27 15:06:10 +01:00
uvc_isight.c media: uvcvideo: Rename debug functions 2021-01-27 15:08:19 +01:00
uvc_metadata.c media: uvcvideo: Use dev->name for querycap() 2021-09-30 10:07:47 +02:00
uvc_queue.c media: uvcvideo: Rename debug functions 2021-01-27 15:08:19 +01:00
uvc_status.c media: uvcvideo: Rename debug functions 2021-01-27 15:08:19 +01:00
uvc_v4l2.c media: uvcvideo: Fix missing check to determine if element is found in list 2022-05-08 07:08:53 +02:00
uvc_video.c media: uvcvideo: fix division by zero at stream start 2021-12-07 11:29:53 +01:00
uvcvideo.h media: uvcvideo: Increase UVC_CTRL_CONTROL_TIMEOUT to 5 seconds. 2021-12-07 11:29:54 +01:00