]> git.baikalelectronics.ru Git - kernel.git/commit
media: dm1105: Fix use after free bug in dm1105_remove due to race condition
authorZheng Wang <zyytlz.wz@163.com>
Sat, 18 Mar 2023 08:15:06 +0000 (16:15 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 May 2023 09:35:37 +0000 (11:35 +0200)
commitd2d2b81fcaea1a6e382625502fb3d836a5e57b81
tree531edf9bf46f3ee4d0c131c907ca2d62fe98adc6
parentc43f6cdb2aa0651dca5690f0bce8dc864f91ad98
media: dm1105: Fix use after free bug in dm1105_remove due to race condition

[ Upstream commit 5abda7a16698d4d1f47af1168d8fa2c640116b4a ]

In dm1105_probe, it called dm1105_ir_init and bound
&dm1105->ir.work with dm1105_emit_key.
When it handles IRQ request with dm1105_irq,
it may call schedule_work to start the work.

When we call dm1105_remove to remove the driver, there
may be a sequence as follows:

Fix it by finishing the work before cleanup in dm1105_remove

CPU0                  CPU1

                    |dm1105_emit_key
dm1105_remove      |
  dm1105_ir_exit       |
    rc_unregister_device |
    rc_free_device  |
    rc_dev_release  |
    kfree(dev);     |
                    |
                    | rc_keydown
                    |   //use

Fixes: fc4b26c7cd02 ("V4L/DVB: dm1105: use dm1105_dev & dev instead of dm1105dvb")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/pci/dm1105/dm1105.c