linux-brain/drivers/media/usb/em28xx
Dongliang Mu d2ea2f0725 media: em28xx-input: fix refcount bug in em28xx_usb_disconnect
[ Upstream commit 6fa54bc713c262e1cfbc5613377ef52280d7311f ]

If em28xx_ir_init fails, it would decrease the refcount of dev. However,
in the em28xx_ir_fini, when ir is NULL, it goes to ref_put and decrease
the refcount of dev. This will lead to a refcount bug.

Fix this bug by removing the kref_put in the error handling code
of em28xx_ir_init.

refcount_t: underflow; use-after-free.
WARNING: CPU: 0 PID: 7 at lib/refcount.c:28 refcount_warn_saturate+0x18e/0x1a0 lib/refcount.c:28
Modules linked in:
CPU: 0 PID: 7 Comm: kworker/0:1 Not tainted 5.13.0 #3
Workqueue: usb_hub_wq hub_event
RIP: 0010:refcount_warn_saturate+0x18e/0x1a0 lib/refcount.c:28
Call Trace:
  kref_put.constprop.0+0x60/0x85 include/linux/kref.h:69
  em28xx_usb_disconnect.cold+0xd7/0xdc drivers/media/usb/em28xx/em28xx-cards.c:4150
  usb_unbind_interface+0xbf/0x3a0 drivers/usb/core/driver.c:458
  __device_release_driver drivers/base/dd.c:1201 [inline]
  device_release_driver_internal+0x22a/0x230 drivers/base/dd.c:1232
  bus_remove_device+0x108/0x160 drivers/base/bus.c:529
  device_del+0x1fe/0x510 drivers/base/core.c:3540
  usb_disable_device+0xd1/0x1d0 drivers/usb/core/message.c:1419
  usb_disconnect+0x109/0x330 drivers/usb/core/hub.c:2221
  hub_port_connect drivers/usb/core/hub.c:5151 [inline]
  hub_port_connect_change drivers/usb/core/hub.c:5440 [inline]
  port_event drivers/usb/core/hub.c:5586 [inline]
  hub_event+0xf81/0x1d40 drivers/usb/core/hub.c:5668
  process_one_work+0x2c9/0x610 kernel/workqueue.c:2276
  process_scheduled_works kernel/workqueue.c:2338 [inline]
  worker_thread+0x333/0x5b0 kernel/workqueue.c:2424
  kthread+0x188/0x1d0 kernel/kthread.c:319
  ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Reported-by: Dongliang Mu <mudongliangabcd@gmail.com>
Fixes: ac5688637144 ("media: em28xx: Fix possible memory leak of em28xx struct")
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-09-15 09:47:33 +02:00
..
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile media: prefix header search paths with $(srctree)/ 2019-05-18 11:49:56 +09:00
em28xx-audio.c media updates for v4.20-rc1 2018-10-29 14:29:58 -07:00
em28xx-camera.c MAINTAINERS & files: Canonize the e-mails I use at files 2018-05-04 06:21:06 -04:00
em28xx-cards.c media: em28xx: modules workqueue not inited for 2nd device 2019-08-14 05:06:44 -03:00
em28xx-core.c media: em28xx: Fix use-after-free in em28xx_alloc_urbs 2021-03-04 10:26:20 +01:00
em28xx-dvb.c media: em28xx: fix memory leak 2021-05-11 14:04:10 +02:00
em28xx-i2c.c media: usb: fix several typos 2019-03-01 09:43:27 -05:00
em28xx-input.c media: em28xx-input: fix refcount bug in em28xx_usb_disconnect 2021-09-15 09:47:33 +02:00
em28xx-reg.h media: usb: fix several typos 2019-03-01 09:43:27 -05:00
em28xx-v4l.h media: update/fix my e-mail on some places 2018-05-10 07:27:15 -04:00
em28xx-vbi.c media: em28xx: Add SPDX license tags where needed 2018-03-06 05:54:52 -05:00
em28xx-video.c media: Fix various misspellings of disconnected 2019-08-19 12:02:28 -03:00
em28xx.h media: Fix various misspellings of disconnected 2019-08-19 12:02:28 -03:00