* [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free
@ 2026-11-22 13:34 Luo Qiu
2026-11-23 16:39 ` Mark Pearson
2026-11-23 16:57 ` Rong Zhang
0 siblings, 2 replies; 4+ messages in thread
From: Luo Qiu @ 2026-11-22 13:34 UTC (permalink / raw)
To: Ike Panhc, Mark Pearson, Derek J. Clark, Rong Zhang,
Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86
ideapad_dytc_profile_exit() is called from both ideapad_acpi_remove()
and the probe failure path. It destroys priv->dytc->mutex and frees
priv->dytc, but the platform profile device is registered with
devm_platform_profile_register().
Devres cleanup runs after the driver remove callback, so the profile
device remains registered after its drvdata has been freed. A concurrent
read of its profile sysfs attribute then calls into the driver with the
stale pointer:
BUG: KASAN: slab-use-after-free in dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
Call Trace:
dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
profile_show+0xe4/0x1d0
dev_attr_show+0x4a/0x90
sysfs_kf_seq_show+0x29e/0x4a0
Allocated by task 411:
ideapad_acpi_add+0xd1f/0x2420 [ideapad_laptop]
Freed by task 7150:
kfree+0x1c7/0x500
ideapad_acpi_remove+0x148/0x3d0 [ideapad_laptop]
device_release_driver_internal+0x35c/0x560
unbind_store+0xde/0x100
Subsequent reads through the stale drvdata also observe corrupted
values. They trigger WARN_ON(val >= PLATFORM_PROFILE_LAST) in
get_class_profile() and fail with -EINVAL.
Register the platform profile explicitly and remove it in
ideapad_dytc_profile_exit() before destroying the mutex and freeing
dytc. This keeps the profile device and its drvdata alive for the same
interval on both removal and probe failure.
Fixes: 0d882fae334b ("platform/x86: ideapad-laptop: Use devm_platform_profile_register()")
Signed-off-by: Luo Qiu <luoqiu@kylinsec.com.cn>
---
drivers/platform/x86/lenovo/ideapad-laptop.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 91a8d11c79c5..2cbd0b87defc 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -1185,9 +1185,9 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
priv->dytc->priv = priv;
/* Create platform_profile structure and register */
- priv->dytc->ppdev = devm_platform_profile_register(&priv->platform_device->dev,
- "ideapad-laptop", priv->dytc,
- &dytc_profile_ops);
+ priv->dytc->ppdev = platform_profile_register(&priv->platform_device->dev,
+ "ideapad-laptop", priv->dytc,
+ &dytc_profile_ops);
if (IS_ERR(priv->dytc->ppdev)) {
err = PTR_ERR(priv->dytc->ppdev);
goto pp_reg_failed;
@@ -1211,6 +1211,7 @@ static void ideapad_dytc_profile_exit(struct ideapad_private *priv)
if (!priv->dytc)
return;
+ platform_profile_remove(priv->dytc->ppdev);
mutex_destroy(&priv->dytc->mutex);
kfree(priv->dytc);
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free
2026-11-22 13:34 [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free Luo Qiu
@ 2026-11-23 16:39 ` Mark Pearson
2026-11-23 18:22 ` Ilpo Järvinen
2026-11-23 16:57 ` Rong Zhang
1 sibling, 1 reply; 4+ messages in thread
From: Mark Pearson @ 2026-11-23 16:39 UTC (permalink / raw)
To: Luo Qiu, Ike Panhc, Derek J . Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86@vger.kernel.org
On Sun, Nov 22, 2026, at 8:34 AM, Luo Qiu wrote:
> ideapad_dytc_profile_exit() is called from both ideapad_acpi_remove()
> and the probe failure path. It destroys priv->dytc->mutex and frees
> priv->dytc, but the platform profile device is registered with
> devm_platform_profile_register().
>
> Devres cleanup runs after the driver remove callback, so the profile
> device remains registered after its drvdata has been freed. A concurrent
> read of its profile sysfs attribute then calls into the driver with the
> stale pointer:
>
> BUG: KASAN: slab-use-after-free in dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
>
> Call Trace:
> dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
> profile_show+0xe4/0x1d0
> dev_attr_show+0x4a/0x90
> sysfs_kf_seq_show+0x29e/0x4a0
>
> Allocated by task 411:
> ideapad_acpi_add+0xd1f/0x2420 [ideapad_laptop]
>
> Freed by task 7150:
> kfree+0x1c7/0x500
> ideapad_acpi_remove+0x148/0x3d0 [ideapad_laptop]
> device_release_driver_internal+0x35c/0x560
> unbind_store+0xde/0x100
>
> Subsequent reads through the stale drvdata also observe corrupted
> values. They trigger WARN_ON(val >= PLATFORM_PROFILE_LAST) in
> get_class_profile() and fail with -EINVAL.
>
> Register the platform profile explicitly and remove it in
> ideapad_dytc_profile_exit() before destroying the mutex and freeing
> dytc. This keeps the profile device and its drvdata alive for the same
> interval on both removal and probe failure.
>
> Fixes: 0d882fae334b ("platform/x86: ideapad-laptop: Use
> devm_platform_profile_register()")
> Signed-off-by: Luo Qiu <luoqiu@kylinsec.com.cn>
> ---
> drivers/platform/x86/lenovo/ideapad-laptop.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c
> b/drivers/platform/x86/lenovo/ideapad-laptop.c
> index 91a8d11c79c5..2cbd0b87defc 100644
> --- a/drivers/platform/x86/lenovo/ideapad-laptop.c
> +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
> @@ -1185,9 +1185,9 @@ static int ideapad_dytc_profile_init(struct
> ideapad_private *priv)
> priv->dytc->priv = priv;
>
> /* Create platform_profile structure and register */
> - priv->dytc->ppdev =
> devm_platform_profile_register(&priv->platform_device->dev,
> - "ideapad-laptop", priv->dytc,
> - &dytc_profile_ops);
> + priv->dytc->ppdev =
> platform_profile_register(&priv->platform_device->dev,
> + "ideapad-laptop", priv->dytc,
> + &dytc_profile_ops);
> if (IS_ERR(priv->dytc->ppdev)) {
> err = PTR_ERR(priv->dytc->ppdev);
> goto pp_reg_failed;
> @@ -1211,6 +1211,7 @@ static void ideapad_dytc_profile_exit(struct
> ideapad_private *priv)
> if (!priv->dytc)
> return;
>
> + platform_profile_remove(priv->dytc->ppdev);
> mutex_destroy(&priv->dytc->mutex);
> kfree(priv->dytc);
>
Seems a shame, but agreed on the issue and that the commit needing reversing. Any other fix seems messier.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free
2026-11-22 13:34 [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free Luo Qiu
2026-11-23 16:39 ` Mark Pearson
@ 2026-11-23 16:57 ` Rong Zhang
1 sibling, 0 replies; 4+ messages in thread
From: Rong Zhang @ 2026-11-23 16:57 UTC (permalink / raw)
To: Luo Qiu, Ike Panhc, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86
Hi Luo,
On Sun, 2026-11-22 at 21:34 +0800, Luo Qiu wrote:
> ideapad_dytc_profile_exit() is called from both ideapad_acpi_remove()
> and the probe failure path. It destroys priv->dytc->mutex and frees
> priv->dytc, but the platform profile device is registered with
> devm_platform_profile_register().
>
> Devres cleanup runs after the driver remove callback, so the profile
> device remains registered after its drvdata has been freed. A concurrent
> read of its profile sysfs attribute then calls into the driver with the
> stale pointer:
>
> BUG: KASAN: slab-use-after-free in dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
>
> Call Trace:
> dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
> profile_show+0xe4/0x1d0
> dev_attr_show+0x4a/0x90
> sysfs_kf_seq_show+0x29e/0x4a0
>
> Allocated by task 411:
> ideapad_acpi_add+0xd1f/0x2420 [ideapad_laptop]
>
> Freed by task 7150:
> kfree+0x1c7/0x500
> ideapad_acpi_remove+0x148/0x3d0 [ideapad_laptop]
> device_release_driver_internal+0x35c/0x560
> unbind_store+0xde/0x100
>
> Subsequent reads through the stale drvdata also observe corrupted
> values. They trigger WARN_ON(val >= PLATFORM_PROFILE_LAST) in
> get_class_profile() and fail with -EINVAL.
>
> Register the platform profile explicitly and remove it in
> ideapad_dytc_profile_exit() before destroying the mutex and freeing
> dytc. This keeps the profile device and its drvdata alive for the same
> interval on both removal and probe failure.
>
> Fixes: 0d882fae334b ("platform/x86: ideapad-laptop: Use devm_platform_profile_register()")
Reviewed-by: Rong Zhang <i@rong.moe>
Thanks,
Rong
> Signed-off-by: Luo Qiu <luoqiu@kylinsec.com.cn>
> ---
> drivers/platform/x86/lenovo/ideapad-laptop.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
> index 91a8d11c79c5..2cbd0b87defc 100644
> --- a/drivers/platform/x86/lenovo/ideapad-laptop.c
> +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
> @@ -1185,9 +1185,9 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
> priv->dytc->priv = priv;
>
> /* Create platform_profile structure and register */
> - priv->dytc->ppdev = devm_platform_profile_register(&priv->platform_device->dev,
> - "ideapad-laptop", priv->dytc,
> - &dytc_profile_ops);
> + priv->dytc->ppdev = platform_profile_register(&priv->platform_device->dev,
> + "ideapad-laptop", priv->dytc,
> + &dytc_profile_ops);
> if (IS_ERR(priv->dytc->ppdev)) {
> err = PTR_ERR(priv->dytc->ppdev);
> goto pp_reg_failed;
> @@ -1211,6 +1211,7 @@ static void ideapad_dytc_profile_exit(struct ideapad_private *priv)
> if (!priv->dytc)
> return;
>
> + platform_profile_remove(priv->dytc->ppdev);
> mutex_destroy(&priv->dytc->mutex);
> kfree(priv->dytc);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free
2026-11-23 16:39 ` Mark Pearson
@ 2026-11-23 18:22 ` Ilpo Järvinen
0 siblings, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2026-11-23 18:22 UTC (permalink / raw)
To: Mark Pearson
Cc: Luo Qiu, Ike Panhc, Derek J . Clark, Rong Zhang, Hans de Goede,
platform-driver-x86@vger.kernel.org
On Mon, 23 Nov 2026, Mark Pearson wrote:
> On Sun, Nov 22, 2026, at 8:34 AM, Luo Qiu wrote:
> > ideapad_dytc_profile_exit() is called from both ideapad_acpi_remove()
> > and the probe failure path. It destroys priv->dytc->mutex and frees
> > priv->dytc, but the platform profile device is registered with
> > devm_platform_profile_register().
> >
> > Devres cleanup runs after the driver remove callback, so the profile
> > device remains registered after its drvdata has been freed. A concurrent
> > read of its profile sysfs attribute then calls into the driver with the
> > stale pointer:
> >
> > BUG: KASAN: slab-use-after-free in dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
> >
> > Call Trace:
> > dytc_profile_get+0xb1/0xe0 [ideapad_laptop]
> > profile_show+0xe4/0x1d0
> > dev_attr_show+0x4a/0x90
> > sysfs_kf_seq_show+0x29e/0x4a0
> >
> > Allocated by task 411:
> > ideapad_acpi_add+0xd1f/0x2420 [ideapad_laptop]
> >
> > Freed by task 7150:
> > kfree+0x1c7/0x500
> > ideapad_acpi_remove+0x148/0x3d0 [ideapad_laptop]
> > device_release_driver_internal+0x35c/0x560
> > unbind_store+0xde/0x100
> >
> > Subsequent reads through the stale drvdata also observe corrupted
> > values. They trigger WARN_ON(val >= PLATFORM_PROFILE_LAST) in
> > get_class_profile() and fail with -EINVAL.
> >
> > Register the platform profile explicitly and remove it in
> > ideapad_dytc_profile_exit() before destroying the mutex and freeing
> > dytc. This keeps the profile device and its drvdata alive for the same
> > interval on both removal and probe failure.
> >
> > Fixes: 0d882fae334b ("platform/x86: ideapad-laptop: Use
> > devm_platform_profile_register()")
> > Signed-off-by: Luo Qiu <luoqiu@kylinsec.com.cn>
> > ---
> > drivers/platform/x86/lenovo/ideapad-laptop.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c
> > b/drivers/platform/x86/lenovo/ideapad-laptop.c
> > index 91a8d11c79c5..2cbd0b87defc 100644
> > --- a/drivers/platform/x86/lenovo/ideapad-laptop.c
> > +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
> > @@ -1185,9 +1185,9 @@ static int ideapad_dytc_profile_init(struct
> > ideapad_private *priv)
> > priv->dytc->priv = priv;
> >
> > /* Create platform_profile structure and register */
> > - priv->dytc->ppdev =
> > devm_platform_profile_register(&priv->platform_device->dev,
> > - "ideapad-laptop", priv->dytc,
> > - &dytc_profile_ops);
> > + priv->dytc->ppdev =
> > platform_profile_register(&priv->platform_device->dev,
> > + "ideapad-laptop", priv->dytc,
> > + &dytc_profile_ops);
> > if (IS_ERR(priv->dytc->ppdev)) {
> > err = PTR_ERR(priv->dytc->ppdev);
> > goto pp_reg_failed;
> > @@ -1211,6 +1211,7 @@ static void ideapad_dytc_profile_exit(struct
> > ideapad_private *priv)
> > if (!priv->dytc)
> > return;
> >
> > + platform_profile_remove(priv->dytc->ppdev);
> > mutex_destroy(&priv->dytc->mutex);
> > kfree(priv->dytc);
> >
> Seems a shame, but agreed on the issue and that the commit needing reversing. Any other fix seems messier.
One could consider using devm_*() for everything with
devm_add_action_or_reset() for those that do not have devm_*() from core.
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Mark
>
--
i.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 18:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 13:34 [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free Luo Qiu
2026-11-23 16:39 ` Mark Pearson
2026-11-23 18:22 ` Ilpo Järvinen
2026-11-23 16:57 ` Rong Zhang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.