All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Mark Pearson <mpearson-lenovo@squebb.ca>
Cc: Luo Qiu <luoqiu@kylinsec.com.cn>, Ike Panhc <ikepanhc@gmail.com>,
	 "Derek J . Clark" <derekjohn.clark@gmail.com>,
	Rong Zhang <i@rong.moe>,  Hans de Goede <hansg@kernel.org>,
	 "platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>
Subject: Re: [PATCH] platform/x86: ideapad-laptop: Fix DYTC profile use-after-free
Date: Mon, 23 Nov 2026 20:22:20 +0200 (EET)	[thread overview]
Message-ID: <4130b5c2-34e8-8a3f-562a-a39f64a314b7@linux.intel.com> (raw)
In-Reply-To: <a634e184-67f7-4aa0-b50e-c09a1f03a144@app.fastmail.com>

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.


  reply	other threads:[~2026-11-23 18:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-23 16:57 ` Rong Zhang

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=4130b5c2-34e8-8a3f-562a-a39f64a314b7@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=i@rong.moe \
    --cc=ikepanhc@gmail.com \
    --cc=luoqiu@kylinsec.com.cn \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=platform-driver-x86@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 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.