From: hyunjungg <hj351016@gmail.com>
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>
Cc: linux-kernel@vger.kernel.org,
Krzysztof Kozlowski <krzk@kernel.org>,
linux-samsung-soc@vger.kernel.org,
Hans de Goede <hansg@kernel.org>,
Hyunjung Ko <hj351016@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 2/5] extcon: palmas: drain ID-detect work before the extcon device is freed
Date: Fri, 6 Nov 2026 22:17:27 +0900 [thread overview]
Message-ID: <20261106131730.2633139-3-hj351016@gmail.com> (raw)
In-Reply-To: <20261106131730.2633139-1-hj351016@gmail.com>
From: Hyunjung Ko <hj351016@gmail.com>
palmas_usb_probe() registers the GPIO ID-detect work for device-managed
cancellation before it allocates and registers the extcon device that
the work handler dereferences:
devm_delayed_work_autocancel(&pdev->dev, &palmas_usb->wq_detectid,
palmas_gpio_id_detect);
...
palmas_usb->edev = devm_extcon_dev_allocate(&pdev->dev, ...);
devm_extcon_dev_register(&pdev->dev, palmas_usb->edev);
...
devm_request_threaded_irq(..., palmas_gpio_id_irq_handler, ...);
devres releases resources in reverse registration order, so on unbind
the extcon device is torn down first and the work is cancelled last:
/* free_irq() */
devm_extcon_dev_unregister() / extcon freed
...
cancel_delayed_work_sync(&palmas_usb->wq_detectid); /* too late */
palmas_gpio_id_irq_handler() queues wq_detectid with a debounce delay on
every ID GPIO edge, so a work instance can be pending at unbind. The
handler palmas_gpio_id_detect() dereferences palmas_usb->edev via
extcon_set_state_sync(). Its only early-return guard tests
palmas_usb->id_gpiod (acquired before the work registration, so still
valid), not ->edev, so it does not prevent the access. If the work runs
in the window after the extcon device has been freed but before the
work is cancelled, it dereferences freed memory -> use-after-free.
Register the work for cancellation after the extcon device is allocated
and registered (and before the IRQs, which queue it), so devres (LIFO)
frees the IRQs first, then cancels the work, and only then frees the
extcon device. The ID GPIO the handler also uses is acquired earlier and
thus still outlives the work. devm_delayed_work_autocancel() still runs
INIT_DELAYED_WORK() before the work is first queued (the IRQ handler and
the explicit palmas_gpio_id_detect() call both run after it).
Found by static analysis / code review; compile-tested only, not
reproduced on hardware (requires a Palmas/TWL6035 USB PHY).
Fixes: f94a5becabf4 ("extconn: Clean-up few drivers by using managed work init")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index d339b86..f7496e5 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -237,12 +237,6 @@ static int palmas_usb_probe(struct platform_device *pdev)
palmas_usb->sw_debounce_jiffies = msecs_to_jiffies(debounce);
}
- status = devm_delayed_work_autocancel(&pdev->dev,
- &palmas_usb->wq_detectid,
- palmas_gpio_id_detect);
- if (status)
- return status;
-
palmas->usb = palmas_usb;
palmas_usb->palmas = palmas;
@@ -265,6 +259,12 @@ static int palmas_usb_probe(struct platform_device *pdev)
return status;
}
+ status = devm_delayed_work_autocancel(&pdev->dev,
+ &palmas_usb->wq_detectid,
+ palmas_gpio_id_detect);
+ if (status)
+ return status;
+
if (palmas_usb->enable_id_detection) {
palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data,
PALMAS_ID_OTG_IRQ);
next prev parent reply other threads:[~2026-11-06 13:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:17 [PATCH 0/5] extcon: fix work-vs-devres teardown use-after-free in MUIC/connector drivers hyunjungg
2026-11-06 13:17 ` [PATCH 1/5] extcon: intel-int3496: drain ID work before its GPIOs and extcon device are freed hyunjungg
2026-11-06 15:46 ` Hans de Goede
2026-11-06 13:17 ` hyunjungg [this message]
2026-11-06 13:17 ` [PATCH 3/5] extcon: max8997: drain MUIC IRQ work before extcon device is freed hyunjungg
2026-11-06 13:17 ` [PATCH 4/5] extcon: max14577: " hyunjungg
2026-11-06 13:17 ` [PATCH 5/5] extcon: max77693: " hyunjungg
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=20261106131730.2633139-3-hj351016@gmail.com \
--to=hj351016@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=hansg@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®