linux/drivers/media
Ricardo Ribalda 4ca25c0b74 media: uvcvideo: Fix race condition with usb_kill_urb
commit 619d9b710c upstream.

usb_kill_urb warranties that all the handlers are finished when it
returns, but does not protect against threads that might be handling
asynchronously the urb.

For UVC, the function uvc_ctrl_status_event_async() takes care of
control changes asynchronously.

If the code is executed in the following order:

CPU 0					CPU 1
===== 					=====
uvc_status_complete()
					uvc_status_stop()
uvc_ctrl_status_event_work()
					uvc_status_start() -> FAIL

Then uvc_status_start will keep failing and this error will be shown:

<4>[    5.540139] URB 0000000000000000 submitted while active
drivers/usb/core/urb.c:378 usb_submit_urb+0x4c3/0x528

Let's improve the current situation, by not re-submiting the urb if
we are stopping the status event. Also process the queued work
(if any) during stop.

CPU 0					CPU 1
===== 					=====
uvc_status_complete()
					uvc_status_stop()
					uvc_status_start()
uvc_ctrl_status_event_work() -> FAIL

Hopefully, with the usb layer protection this should be enough to cover
all the cases.

Cc: stable@vger.kernel.org
Fixes: e5225c820c ("media: uvcvideo: Send a control event when a Control Change interrupt arrives")
Reviewed-by: Yunke Cao <yunkec@chromium.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2023-03-11 13:55:43 +01:00
..
cec media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
common media: videobuf2-core: take mmap_lock in vb2_get_unmapped_area() 2022-12-07 11:25:40 -08:00
dvb-core media: dvb-core: Fix UAF due to refcount races at releasing 2023-01-07 11:11:49 +01:00
dvb-frontends media: stv0288: use explicitly signed char 2023-01-07 11:11:36 +01:00
firewire media: Makefiles: remove extra spaces 2022-03-12 16:59:52 +01:00
i2c media: i2c: ov7670: 0 instead of -EINVAL was returned 2023-03-10 09:33:44 +01:00
mc media: mc: Get media_device directly from pad 2023-03-10 09:33:42 +01:00
mmc media: media/*/Kconfig: sort entries 2022-03-18 05:58:35 +01:00
pci media: ipu3-cio2: Fix PM runtime usage_count in driver unbind 2023-03-10 09:34:26 +01:00
platform media: amphion: correct the unspecified color space 2023-03-10 09:33:44 +01:00
radio media: si470x: Fix use-after-free in si470x_int_in_callback() 2022-12-31 13:33:04 +01:00
rc media: rc: Fix use-after-free bugs caused by ene_tx_irqsim() 2023-03-10 09:33:44 +01:00
spi media updates for v5.18-rc1 2022-03-23 14:51:35 -07:00
test-drivers media: vimc: Fix wrong function called when vimc_init() fails 2022-12-31 13:32:16 +01:00
tuners media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
usb media: uvcvideo: Fix race condition with usb_kill_urb 2023-03-11 13:55:43 +01:00
v4l2-core media: drivers/media/v4l2-core/v4l2-h264 : add detection of null pointers 2023-03-10 09:33:44 +01:00
Kconfig media: remove reference to CONFIG_EMBEDDED in MEDIA_SUPPORT_FILTER 2022-09-08 18:19:29 +02:00
Makefile media: Makefiles: remove extra spaces 2022-03-12 16:59:52 +01:00