]> git.baikalelectronics.ru Git - kernel.git/commit
power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race...
authorZheng Wang <zyytlz.wz@163.com>
Sat, 11 Mar 2023 17:46:50 +0000 (01:46 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Apr 2023 09:16:36 +0000 (11:16 +0200)
commit2e4b1ff3ce84abd0572a57454909e9baffa93510
tree90b56dff05166336c4cffae53a65b200958a5b10
parenta27f198b4ea7afc6e3e3716d85c511a00fdad339
power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition

[ Upstream commit 06615d11cc78162dfd5116efb71f29eb29502d37 ]

In da9150_charger_probe, &charger->otg_work is bound with
da9150_charger_otg_work. da9150_charger_otg_ncb may be
called to start the work.

If we remove the module which will call da9150_charger_remove
to make cleanup, there may be a unfinished work. The possible
sequence is as follows:

Fix it by canceling the work before cleanup in the da9150_charger_remove

CPU0                  CPUc1

                    |da9150_charger_otg_work
da9150_charger_remove      |
power_supply_unregister  |
device_unregister   |
power_supply_dev_release|
kfree(psy)          |
                    |
                    |  power_supply_changed(charger->usb);
                    |   //use

Fixes: bfbb7cce2191 ("power: Add support for DA9150 Charger")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/power/supply/da9150-charger.c