linux/drivers/media/rc
Tetsuo Handa 32c7b04d53 media: imon: reorganize serialization
[ Upstream commit db264d4c66 ]

Since usb_register_dev() from imon_init_display() from imon_probe() holds
minor_rwsem while display_open() which holds driver_lock and ictx->lock is
called with minor_rwsem held from usb_open(), holding driver_lock or
ictx->lock when calling usb_register_dev() causes circular locking
dependency problem.

Since usb_deregister_dev() from imon_disconnect() holds minor_rwsem while
display_open() which holds driver_lock is called with minor_rwsem held,
holding driver_lock when calling usb_deregister_dev() also causes circular
locking dependency problem.

Sean Young explained that the problem is there are imon devices which have
two usb interfaces, even though it is one device. The probe and disconnect
function of both usb interfaces can run concurrently.

Alan Stern responded that the driver and USB cores guarantee that when an
interface is probed, both the interface and its USB device are locked.
Ditto for when the disconnect callback gets run. So concurrent probing/
disconnection of multiple interfaces on the same device is not possible.

Therefore, we don't need locks for handling race between imon_probe() and
imon_disconnect(). But we still need to handle race between display_open()
/vfd_write()/lcd_write()/display_close() and imon_disconnect(), for
disconnect event can happen while file descriptors are in use.

Since "struct file"->private_data is set by display_open(), vfd_write()/
lcd_write()/display_close() can assume that "struct file"->private_data
is not NULL even after usb_set_intfdata(interface, NULL) was called.

Replace insufficiently held driver_lock with refcount_t based management.
Add a boolean flag for recording whether imon_disconnect() was already
called. Use RCU for accessing this boolean flag and refcount_t.

Since the boolean flag for imon_disconnect() is shared, disconnect event
on either intf0 or intf1 affects both interfaces. But I assume that this
change does not matter, for usually disconnect event would not happen
while interfaces are in use.

Link: https://syzkaller.appspot.com/bug?extid=c558267ad910fc494497

Reported-by: syzbot <syzbot+c558267ad910fc494497@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: syzbot <syzbot+c558267ad910fc494497@syzkaller.appspotmail.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-09 10:22:38 +02:00
..
img-ir
keymaps media: rc: add keymap for Toshiba CT-90405 remote 2021-06-08 15:56:58 +02:00
ati_remote.c
bpf-lirc.c bpf: Allow to specify user-provided bpf_cookie for BPF perf links 2021-08-17 00:45:07 +02:00
ene_ir.c media: rc: rename s_learning_mode() to s_wideband_receiver() 2021-07-22 08:21:53 +02:00
ene_ir.h
fintek-cir.c
fintek-cir.h
gpio-ir-recv.c
gpio-ir-tx.c media: gpio-ir-tx: fix transmit with long spaces on Orange Pi PC 2022-04-08 14:23:02 +02:00
igorplugusb.c media: igorplugusb: receiver overflow should be reported 2022-01-27 11:04:41 +01:00
iguanair.c
imon_raw.c
imon.c media: imon: reorganize serialization 2022-06-09 10:22:38 +02:00
ir_toy.c media: ir_toy: free before error exiting 2022-04-08 14:23:59 +02:00
ir-hix5hd2.c media: rc: ir-hix5hd2: use the correct HiSilicon copyright 2021-04-09 13:03:24 +02:00
ir-imon-decoder.c
ir-jvc-decoder.c
ir-mce_kbd-decoder.c
ir-nec-decoder.c
ir-rc5-decoder.c
ir-rc6-decoder.c
ir-rcmm-decoder.c
ir-rx51.c
ir-sanyo-decoder.c
ir-sharp-decoder.c
ir-sony-decoder.c
ir-spi.c
ir-xmp-decoder.c
ite-cir.c media: ite-cir: IR receiver stop working after receive overflow 2021-11-18 19:15:53 +01:00
ite-cir.h media: rc: ite-cir: replace some an EN DASH 2021-06-04 08:10:42 +02:00
Kconfig media: rc: introduce Meson IR TX driver 2021-08-04 14:43:49 +02:00
lirc_dev.c media: rc: rename s_learning_mode() to s_wideband_receiver() 2021-07-22 08:21:53 +02:00
Makefile media: rc: introduce Meson IR TX driver 2021-08-04 14:43:49 +02:00
mceusb.c media: mceusb: fix control-message timeouts 2022-01-27 11:02:54 +01:00
meson-ir-tx.c media: rc: introduce Meson IR TX driver 2021-08-04 14:43:49 +02:00
meson-ir.c
mtk-cir.c
nuvoton-cir.c
nuvoton-cir.h
pwm-ir-tx.c
rc-core-priv.h
rc-ir-raw.c
rc-loopback.c media: rc: rename s_learning_mode() to s_wideband_receiver() 2021-07-22 08:21:53 +02:00
rc-main.c media: rc: rc-main.c: deleted the repeated word 2021-07-12 14:26:23 +02:00
redrat3.c media: redrat3: fix control-message timeouts 2022-01-27 11:02:55 +01:00
serial_ir.c
sir_ir.c
st_rc.c media: st_rc: Handle errors of clk_prepare_enable() 2021-06-08 15:55:55 +02:00
streamzap.c media: rc: streamzap: Removed unnecessary 'return' 2021-07-12 14:25:44 +02:00
sunxi-cir.c
ttusbir.c
winbond-cir.c
xbox_remote.c