All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ryan Brue" <ryanbrue.dev@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 1/2] cpufreq: mediatek: Enter system sleep at the suspend OPP
Date: Fri, 09 Oct 2026 18:43:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-165965@kernel.org> (raw)
In-Reply-To: <20261009-rbrue-suez-upstreaming-mtk-cpufreq-suspend-opp-v1-1-9100f79b4080@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] opp: UAF and data race on opp_table->suspend_opp
--

commit e45cc103dadbac91ac1b6c64b8b61a195f1c5f95
Author: Ryan Brue <ryanbrue.dev@gmail.com>

cpufreq: mediatek: Enter system sleep at the suspend OPP

This commit updates the mediatek-cpufreq driver to use the generic
suspend-frequency support. It allows the driver to enter system sleep at the
suspend OPP, reducing power consumption during suspend-to-RAM.

> diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
> index 052ca7cd2f4fd..f9b1eca176eb8 100644
> --- a/drivers/cpufreq/mediatek-cpufreq.c
> +++ b/drivers/cpufreq/mediatek-cpufreq.c
> @@ -603,6 +603,7 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
>  	policy->freq_table = freq_table;
>  	policy->driver_data = info;
>  	policy->clk = info->cpu_clk;
> +	policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(info->cpu_dev) / 1000;

[Severity: High]
Is it safe to call dev_pm_opp_get_suspend_opp_freq() here?

In drivers/opp/core.c, dev_pm_opp_get_suspend_opp_freq() locklessly
dereferences opp_table->suspend_opp:

	if (opp_table->suspend_opp && opp_table->suspend_opp->available)
		freq = dev_pm_opp_get_freq(opp_table->suspend_opp);

However, in drivers/opp/of.c, _opp_add_static_v2() modifies
opp_table->suspend_opp dynamically without holding opp_table->lock, creating a
data race:

				opp_table->suspend_opp->suspend = false;
				new_opp->suspend = true;
				opp_table->suspend_opp = new_opp;

Furthermore, when an OPP is removed, _opp_kref_release() in drivers/opp/core.c
frees the dev_pm_opp object without checking or clearing
opp_table->suspend_opp:

	_of_clear_opp(opp_table, opp);
	opp_debug_remove_one(opp);
	kfree(opp);

This leaves a permanent dangling pointer if opp_table->suspend_opp pointed to
the dying OPP. Any subsequent call to dev_pm_opp_get_suspend_opp_freq()
will locklessly dereference the now-dangling pointer, potentially causing a
use-after-free.

>  
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009-rbrue-suez-upstreaming-mtk-cpufreq-suspend-opp-v1-0-9100f79b4080@gmail.com?part=1

  reply	other threads:[~2026-10-09 18:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 18:31 [PATCH 0/2] cpufreq: mediatek: Suspend at the opp-suspend OPP, and mark one on MT8173 Ryan Brue
2026-10-09 18:31 ` [PATCH 1/2] cpufreq: mediatek: Enter system sleep at the suspend OPP Ryan Brue
2026-10-09 18:43   ` sashiko-bot [this message]
2026-10-09 19:42     ` Ryan Brue
2026-10-09 18:31 ` [PATCH 2/2] arm64: dts: mediatek: mt8173: Mark the lowest CPU OPPs for suspend Ryan Brue

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=sashiko-outbox-165965@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=ryanbrue.dev@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.