1
0
Fork 0
alistair23-linux/drivers/media/platform/vivid
Alexander Popov 5aa7ad7e99 media: vivid: Fix wrong locking that causes race conditions on streaming stop
commit 6dcd5d7a7a upstream.

There is the same incorrect approach to locking implemented in
vivid_stop_generating_vid_cap(), vivid_stop_generating_vid_out() and
sdr_cap_stop_streaming().

These functions are called during streaming stopping with vivid_dev.mutex
locked. And they all do the same mistake while stopping their kthreads,
which need to lock this mutex as well. See the example from
vivid_stop_generating_vid_cap():
  /* shutdown control thread */
  vivid_grab_controls(dev, false);
  mutex_unlock(&dev->mutex);
  kthread_stop(dev->kthread_vid_cap);
  dev->kthread_vid_cap = NULL;
  mutex_lock(&dev->mutex);

But when this mutex is unlocked, another vb2_fop_read() can lock it
instead of vivid_thread_vid_cap() and manipulate the buffer queue.
That causes a use-after-free access later.

To fix those issues let's:
  1. avoid unlocking the mutex in vivid_stop_generating_vid_cap(),
vivid_stop_generating_vid_out() and sdr_cap_stop_streaming();
  2. use mutex_trylock() with schedule_timeout_uninterruptible() in
the loops of the vivid kthread handlers.

Signed-off-by: Alexander Popov <alex.popov@linux.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Tested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: <stable@vger.kernel.org>      # for v3.18 and up
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-11-29 10:10:04 +01:00
..
Kconfig Linux 5.2-rc2 2019-05-28 11:21:51 -04:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
vivid-cec.c media: replace strcpy() by strscpy() 2018-09-11 13:32:17 -04:00
vivid-cec.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-core.c Linux 5.3-rc4 2019-08-12 13:22:54 -03:00
vivid-core.h media: vivid: add HDMI (dis)connect RX emulation 2019-06-21 17:33:14 -04:00
vivid-ctrls.c media: vivid: fix device init when no_error_inj=1 and fb disabled 2019-07-25 06:31:30 -04:00
vivid-ctrls.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-kthread-cap.c media: vivid: Fix wrong locking that causes race conditions on streaming stop 2019-11-29 10:10:04 +01:00
vivid-kthread-cap.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-kthread-out.c media: vivid: Fix wrong locking that causes race conditions on streaming stop 2019-11-29 10:10:04 +01:00
vivid-kthread-out.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-osd.c media: vivid: fix incorrect assignment operation when setting video mode 2019-06-05 15:25:15 -04:00
vivid-osd.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-radio-common.c media: use strscpy() instead of strlcpy() 2018-09-11 13:32:17 -04:00
vivid-radio-common.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-radio-rx.c media: use strscpy() instead of strlcpy() 2018-09-11 13:32:17 -04:00
vivid-radio-rx.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-radio-tx.c media: use strscpy() instead of strlcpy() 2018-09-11 13:32:17 -04:00
vivid-radio-tx.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-rds-gen.c media: use strscpy() instead of strlcpy() 2018-09-11 13:32:17 -04:00
vivid-rds-gen.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-sdr-cap.c media: vivid: Fix wrong locking that causes race conditions on streaming stop 2019-11-29 10:10:04 +01:00
vivid-sdr-cap.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-vbi-cap.c media: vivid: make input std_signal per-input 2019-06-21 17:28:25 -04:00
vivid-vbi-cap.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-vbi-gen.c media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-vbi-gen.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-vbi-out.c media: vivid: drop v4l2_ctrl_request_complete() from start_streaming 2018-12-03 15:04:07 -05:00
vivid-vbi-out.h media: vivid: add SPDX license info 2018-02-14 13:14:31 -05:00
vivid-vid-cap.c media: vivid: Set vid_cap_streaming and vid_out_streaming to true 2019-11-29 10:10:03 +01:00
vivid-vid-cap.h media: vidioc_cropcap -> vidioc_g_pixelaspect 2018-11-20 13:57:21 -05:00
vivid-vid-common.c media: vivid: add support for new pixelformats 2019-07-30 12:17:34 -04:00
vivid-vid-common.h media: v4l2: Get rid of ->vidioc_enum_fmt_vid_{cap, out}_mplane 2019-06-05 07:48:32 -04:00
vivid-vid-out.c media: vivid: Set vid_cap_streaming and vid_out_streaming to true 2019-11-29 10:10:03 +01:00
vivid-vid-out.h media: vidioc_cropcap -> vidioc_g_pixelaspect 2018-11-20 13:57:21 -05:00