linux/drivers/media/usb
Shuah Khan 90cd366bc6 [media] media: Protect enable_source and disable_source handler code paths
Drivers might try to access and run enable_source and disable_source
handlers when the driver that implements these handlers is clearing
the handlers during its unregister.

Fix the following race condition:

process 1				process 2

request video streaming			unbind au0828
v4l2 checks if tuner is free
...					...

					au0828_unregister_media_device()
...					...
					(doesn't hold graph_mutex)
					mdev->enable_source = NULL;
if (mdev && mdev->enable_source)	mdev->disable_source = NULL;
	mdev->enable_source()
(enable_source holds graph_mutex)

As shown above enable_source check is done without holding the graph_mutex.
If unbind happens to be in progress, au0828 could clear enable_source and
disable_source handlers leading to null pointer de-reference.

Fix it by protecting enable_source and disable_source set and clear and
protecting enable_source and disable_source handler access and the call
itself.

process 1				process 2

request video streaming			unbind au0828
v4l2 checks if tuner is free
...					...

					au0828_unregister_media_device()
...					...
					(hold graph_mutex while clearing)
					mdev->enable_source = NULL;
if (mdev)				mdev->disable_source = NULL;
(hold graph_mutex to check and
 call enable_source)
    if (mdev->enable_source)
	mdev->enable_source()

If graph_mutex is held to just heck for handler being null and needs to be
released before calling the handler, there will be another window for the
handlers to be cleared. Hence, enable_source and disable_source handlers
no longer hold the graph_mutex and expect callers to hold it to avoid
forcing them release the graph_mutex before calling the handlers.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-02-03 07:39:35 -02:00
..
airspy [media] usb: constify vb2_ops structures 2016-09-19 16:20:35 -03:00
as102 media: usb: as102: as102_usb_drv: don't print error when allocating urb fails 2016-08-30 19:13:53 +02:00
au0828 [media] media: Protect enable_source and disable_source handler code paths 2017-02-03 07:39:35 -02:00
b2c2 [media] b2c2: don't break long lines 2016-10-21 09:38:31 -02:00
cpia2 [media] media: usb: cpia2: Use kmemdup instead of kmalloc and memcpy 2017-01-31 07:46:34 -02:00
cx231xx [media] rc-main: assign driver type during allocation 2017-01-30 13:59:57 -02:00
dvb-usb [media] gp8psk: fix spelling mistake: "firmare" -> "firmware" 2017-01-30 15:45:54 -02:00
dvb-usb-v2 [media] zd1301: ZyDAS ZD1301 DVB USB interface driver 2017-02-03 06:47:35 -02:00
em28xx [media] rc-main: assign driver type during allocation 2017-01-30 13:59:57 -02:00
go7007 [media] go7007: add MEDIA_CAMERA_SUPPORT dependency 2016-11-23 13:15:02 -02:00
gspca [media] media: Drop FSF's postal address from the source code files 2017-01-27 11:38:09 -02:00
hackrf [media] usb: constify vb2_ops structures 2016-09-19 16:20:35 -03:00
hdpvr [media] hdpvr: fix interrupted recording 2016-11-16 13:30:30 -02:00
msi2500 [media] usb: constify vb2_ops structures 2016-09-19 16:20:35 -03:00
pulse8-cec [media] cec: pass parent device in register(), not allocate() 2016-11-29 12:07:17 -02:00
pvrusb2 [media] pvrusb2-io: Add some spaces for better code readability 2017-01-31 08:05:45 -02:00
pwc Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
s2255 [media] media: Drop FSF's postal address from the source code files 2017-01-27 11:38:09 -02:00
siano [media] siano: don't break long lines 2016-10-21 09:52:50 -02:00
stk1160 [media] constify i2c_algorithm structures 2016-09-19 16:27:02 -03:00
stkwebcam [media] media: Drop FSF's postal address from the source code files 2017-01-27 11:38:09 -02:00
tm6000 [media] tm6000: Clean up file handle in open() error path 2017-01-31 07:45:24 -02:00
ttusb-budget [media] ttusb-budget: don't break long lines 2016-10-21 09:54:20 -02:00
ttusb-dec [media] media: Drop FSF's postal address from the source code files 2017-01-27 11:38:09 -02:00
usbtv media updates for v4.10-rc1 2016-12-16 09:39:16 -08:00
usbvision [media] media: Drop FSF's postal address from the source code files 2017-01-27 11:38:09 -02:00
uvc [media] uvcvideo: Change result code of debugfs_init to void 2017-01-31 10:56:48 -02:00
zr364xx [media] media: Drop FSF's postal address from the source code files 2017-01-27 11:38:09 -02:00
Kconfig [media] pulse8-cec: move out of staging 2016-11-16 15:47:12 -02:00
Makefile [media] pulse8-cec: move out of staging 2016-11-16 15:47:12 -02:00