linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zheng Wang <zyytlz.wz@163.com>
To: support.opensource@diasemi.com
Cc: sre@kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, hackerzheng666@gmail.com,
	1395428693sheep@gmail.com, alex000young@gmail.com,
	Zheng Wang <zyytlz.wz@163.com>
Subject: [PATCH] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition
Date: Fri, 10 Mar 2023 02:10:36 +0800	[thread overview]
Message-ID: <20230309181036.262674-1-zyytlz.wz@163.com> (raw)

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 mtk_jpeg_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: c1a281e34dae ("power: Add support for DA9150 Charger")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/power/supply/da9150-charger.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/power/supply/da9150-charger.c b/drivers/power/supply/da9150-charger.c
index 14da5c595dd9..41b68f2f6ed8 100644
--- a/drivers/power/supply/da9150-charger.c
+++ b/drivers/power/supply/da9150-charger.c
@@ -642,6 +642,7 @@ static int da9150_charger_remove(struct platform_device *pdev)
 	struct da9150_charger *charger = platform_get_drvdata(pdev);
 	int irq;
 
+	cancel_work_sync(&charger->otg_work);
 	/* Make sure IRQs are released before unregistering power supplies */
 	irq = platform_get_irq_byname(pdev, "CHG_VBUS");
 	free_irq(irq, charger);
-- 
2.25.1


             reply	other threads:[~2023-03-09 18:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 18:10 Zheng Wang [this message]
2023-03-09 23:39 ` [PATCH] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Sebastian Reichel
2023-03-09 23:40   ` [PATCH] power: supply: bq24190: Fix use after free bug in bq24190_remove " Sebastian Reichel
2023-03-10 16:24   ` [PATCH] power: supply: da9150: Fix use after free bug in da9150_charger_remove " Zheng Hacker
2023-03-10 16:25   ` [PATCH] power: supply: bq24190: Fix use after free bug in bq24190_remove " Zheng Hacker
  -- strict thread matches above, loose matches on Subject: below --
2023-03-09 17:47 Zheng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230309181036.262674-1-zyytlz.wz@163.com \
    --to=zyytlz.wz@163.com \
    --cc=1395428693sheep@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=hackerzheng666@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=support.opensource@diasemi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).