From: Ryan Brue <ryanbrue.dev@gmail.com>
To: sashiko-reviews@lists.linux.dev
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, 9 Oct 2026 14:42:43 -0500 [thread overview]
Message-ID: <d5dc6491-ace6-414e-8c1b-577f9b253bd2@gmail.com> (raw)
In-Reply-To: <sashiko-outbox-165965@kernel.org>
On 10/9/26 1:43 PM, sashiko-bot@kernel.org wrote:
> [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.
The suspend OPP is read once, from ->init, into policy->suspend_freq.
mediatek-cpufreq adds the whole OPP table in probe before
cpufreq_register_driver(), and never adds, removes, or disables
individual OPPs, and has no .remove, so the table can't change or go
away while ->init can run. cpufreq-dt makes the same call.
I also realized that I forgot my sign-off on the commits. I will send
out a v2 that has the sign-off. My apologies.
Best regards,
Ryan Brue
next prev parent reply other threads:[~2026-10-09 19:42 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
2026-10-09 19:42 ` Ryan Brue [this message]
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=d5dc6491-ace6-414e-8c1b-577f9b253bd2@gmail.com \
--to=ryanbrue.dev@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox