From: Shuah Khan <skhan@linuxfoundation.org>
To: Lukas Beckmann <lbckmnn@mailbox.org>,
Thomas Renninger <trenn@suse.com>, Shuah Khan <shuah@kernel.org>,
"John B. Wyatt IV" <jwyatt@redhat.com>,
John Kacur <jkacur@redhat.com>,
Dominik Brodowski <linux@dominikbrodowski.net>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v3] cpupower: fix use-after-free and stale limits in frequency-set
Date: Fri, 20 Nov 2026 13:41:52 -0700 [thread overview]
Message-ID: <69cde473-bd68-4bf5-be03-c68f411ec116@linuxfoundation.org> (raw)
In-Reply-To: <20261118-cpupower-freq-set-use-after-free-v3-1-3e021315b579@mailbox.org>
On 11/18/26 13:06, Lukas Beckmann wrote:
> do_new_policy() directly fills the unset fields of new_pol from the
> current CPU's policy. This is problematic because do_new_policy() is
> called with the same new_pol for multiple CPUs by do_one_cpu() in the
> slow path. This results in stale values in new_pol being applied
> (starting from the second CPU that should be changed), and even a
> use-after-free (for the governor string).
>
> Fix this by building the target policy from new_pol and the current
> policy in do_new_policy() instead of filling the missing values into
> new_pol.
>
> Fixes: 7fe2f6399a84 ("cpupowerutils - cpufrequtils extended with quite some features")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lukas Beckmann <lbckmnn@mailbox.org>
> ---
> Testing and minimal reproducer:
>
> Running the command
>
> ./cpupower frequency-set --max 2500MHz --min 2500MHz
>
> with ASAN reports the use-after-free before, but not after the patch.
>
> Run the following commands:
>
> # set CPU 0 to a different maximum than CPU 1
> echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
> echo 3000000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
>
> # Change min and governor (but not max) of CPU 0 and 1
> ./cpupower -c 0,1 frequency-set --min 1GHz -g performance
>
> # See if max got changed
> cat /sys/devices/system/cpu/cpu[0,1]/cpufreq/scaling_max_freq
>
> This shows that the stale maximum of CPU0 is used for CPU1 before the
> patch, but not after the patch.
> ---
> Changes in v3:
> - Keep the original if conditions (no functional change)
> - Link to v2: https://patch.msgid.link/20261115-cpupower-freq-set-use-after-free-v2-1-6b91f1630165@mailbox.org
>
> Changes in v2:
> - use a shorter changelog and testing section
> - build temp_pol from new_pol and cur_pol instead of copying new_pol
> - Link to v1: https://patch.msgid.link/20261112-cpupower-freq-set-use-after-free-v1-1-4e0034927b3f@mailbox.org
> ---
> tools/power/cpupower/utils/cpufreq-set.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c
> index 06cd4b280132..0bbf303d3317 100644
> --- a/tools/power/cpupower/utils/cpufreq-set.c
> +++ b/tools/power/cpupower/utils/cpufreq-set.c
> @@ -141,9 +141,10 @@ static unsigned long string_to_frequency(const char *str)
> }
> }
>
> -static int do_new_policy(unsigned int cpu, struct cpufreq_policy *new_pol)
> +static int do_new_policy(unsigned int cpu, const struct cpufreq_policy *new_pol)
Why do you need the above change?
> {
> struct cpufreq_policy *cur_pol = cpufreq_get_policy(cpu);
> + struct cpufreq_policy temp_pol;
> int ret;
>
> if (!cur_pol) {
> @@ -152,15 +153,21 @@ static int do_new_policy(unsigned int cpu, struct cpufreq_policy *new_pol)
> }
>
> if (!new_pol->min)
> - new_pol->min = cur_pol->min;
> + temp_pol.min = cur_pol->min;
> + else
> + temp_pol.min = new_pol->min;
>
> if (!new_pol->max)
> - new_pol->max = cur_pol->max;
> + temp_pol.max = cur_pol->max;
> + else
> + temp_pol.max = new_pol->max;
>
> if (!new_pol->governor)
> - new_pol->governor = cur_pol->governor;
> + temp_pol.governor = cur_pol->governor;
> + else
> + temp_pol.governor = new_pol->governor;
>
> - ret = cpufreq_set_policy(cpu, new_pol);
> + ret = cpufreq_set_policy(cpu, &temp_pol);
>
> cpufreq_put_policy(cur_pol);
>
>
thanks,
-- Shuah
next prev parent reply other threads:[~2026-11-20 20:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 20:06 [PATCH v3] cpupower: fix use-after-free and stale limits in frequency-set Lukas Beckmann
2026-11-20 20:41 ` Shuah Khan [this message]
2026-11-20 22:24 ` Lukas Beckmann
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=69cde473-bd68-4bf5-be03-c68f411ec116@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=jkacur@redhat.com \
--cc=jwyatt@redhat.com \
--cc=lbckmnn@mailbox.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@dominikbrodowski.net \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=trenn@suse.com \
/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.