From: Hans de Goede <hansg@kernel.org>
To: hyunjungg <hj351016@gmail.com>,
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, stable@vger.kernel.org
Subject: Re: [PATCH 1/5] extcon: intel-int3496: drain ID work before its GPIOs and extcon device are freed
Date: Fri, 6 Nov 2026 16:46:15 +0100 [thread overview]
Message-ID: <318911bd-dc33-4399-987e-fc05e86d732b@kernel.org> (raw)
In-Reply-To: <20261106131730.2633139-2-hj351016@gmail.com>
Hi,
On 6-Nov-26 14:17, hyunjungg wrote:
> From: Hyunjung Ko <hj351016@gmail.com>
>
> int3496_probe() registers the debounce work for device-managed
> cancellation before it acquires any of the resources that the work
> handler dereferences:
>
> devm_delayed_work_autocancel(dev, &data->work, int3496_do_usb_id);
> ...
> data->gpio_usb_id = devm_gpiod_get(dev, "id", ...);
> data->gpio_vbus_en = devm_gpiod_get(dev, "vbus", ...);
> data->gpio_usb_mux = devm_gpiod_get(dev, "mux", ...);
> data->edev = devm_extcon_dev_allocate(dev, int3496_cable);
> devm_extcon_dev_register(dev, data->edev);
> devm_request_threaded_irq(dev, data->usb_id_irq, ...);
>
> devres releases resources in reverse registration order, so on unbind
> the extcon device and all three GPIO descriptors are released first and
> the work is cancelled last:
>
> /* free_irq() */
> devm_extcon_dev_unregister() / extcon freed
> gpiod_put(mux) / gpiod_put(vbus_en) / gpiod_put(usb_id)
> ...
> cancel_delayed_work_sync(&data->work); /* too late */
>
> int3496_thread_isr() arms the work with mod_delayed_work() on every ID
> pin edge, so a work instance can be pending or running at unbind. The
> handler int3496_do_usb_id() dereferences data->gpio_usb_id
> (gpiod_get_value_cansleep), data->gpio_usb_mux, data->gpio_vbus_en and
> data->edev (extcon_set_state_sync) with no guard. If it runs in the
> window after the GPIOs/extcon device have been released but before the
> work is cancelled, it operates on freed resources -> use-after-free.
>
> Register the work for cancellation after the GPIOs and extcon device
> are acquired and registered (and before the IRQ, which arms it), so
> devres (LIFO) frees the IRQ first, then cancels the work, and only then
> releases the GPIOs and extcon device. devm_delayed_work_autocancel()
> still performs INIT_DELAYED_WORK() before the work is first queued
> (queue_delayed_work() below, and the IRQ handler, both run after it).
>
> Found by static analysis / code review; compile-tested only, not
> reproduced on hardware (requires an INT3496 ACPI USB-ID mux device).
>
> 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>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Regards,
Hans
> ---
> diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
> index 7d16d5b..40774fb 100644
> --- a/drivers/extcon/extcon-intel-int3496.c
> +++ b/drivers/extcon/extcon-intel-int3496.c
> @@ -130,9 +130,6 @@ static int int3496_probe(struct platform_device *pdev)
> return -ENOMEM;
>
> data->dev = dev;
> - ret = devm_delayed_work_autocancel(dev, &data->work, int3496_do_usb_id);
> - if (ret)
> - return ret;
>
> data->gpio_usb_id =
> devm_gpiod_get(dev, "id", GPIOD_IN | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
> @@ -169,6 +166,10 @@ static int int3496_probe(struct platform_device *pdev)
> return ret;
> }
>
> + ret = devm_delayed_work_autocancel(dev, &data->work, int3496_do_usb_id);
> + if (ret)
> + return ret;
> +
> ret = devm_request_threaded_irq(dev, data->usb_id_irq,
> NULL, int3496_thread_isr,
> IRQF_SHARED | IRQF_ONESHOT |
next prev parent reply other threads:[~2026-11-06 15:46 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 [this message]
2026-11-06 13:17 ` [PATCH 2/5] extcon: palmas: drain ID-detect work before the extcon device is freed hyunjungg
2026-11-06 13:17 ` [PATCH 3/5] extcon: max8997: drain MUIC IRQ work before " 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=318911bd-dc33-4399-987e-fc05e86d732b@kernel.org \
--to=hansg@kernel.org \
--cc=cw00.choi@samsung.com \
--cc=hj351016@gmail.com \
--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®