Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] cpufreq: pcc: fix use-after-free and double free in _OSC evaluation
@ 2026-05-13 12:06 Hongyan Xu
  2026-05-13 12:53 ` Zhongqiu Han
  0 siblings, 1 reply; 2+ messages in thread
From: Hongyan Xu @ 2026-05-13 12:06 UTC (permalink / raw)
  To: rafael
  Cc: viresh.kumar, linux-pm, linux-kernel, getshell, jianhao.xu,
	Slavin Liu

pcc_cpufreq_do_osc() uses a two-phase _OSC evaluation and frees the
output buffer returned by the first acpi_evaluate_object() call before
reusing the same acpi_buffer in the second call.

However, output.pointer and output.length are not reset after the
first kfree(). That can make the second acpi_evaluate_object() treat
the stale metadata as a caller-provided buffer and write into freed
memory. The shared out_free path can then free the same pointer again.

Reset the output buffer state after the first kfree() so ACPICA
allocates a fresh buffer for the second _OSC evaluation.

Fixes: 0f1d683fb35d ("[CPUFREQ] Processor Clocking Control interface driver")
Issue found using a prototype static analysis tool
and confirmed by code review.

Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
Signed-off-by: Slavin Liu <220245772@seu.edu.cn>
---
 drivers/cpufreq/pcc-cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c
index ac2e90a65f0c..a355ec4f3dd4 100644
--- a/drivers/cpufreq/pcc-cpufreq.c
+++ b/drivers/cpufreq/pcc-cpufreq.c
@@ -352,6 +352,8 @@ static int __init pcc_cpufreq_do_osc(acpi_handle *handle)
 	}
 
 	kfree(output.pointer);
+	output.pointer = NULL;
+	output.length = ACPI_ALLOCATE_BUFFER;
 	capabilities[0] = 0x0;
 	capabilities[1] = 0x1;
 
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cpufreq: pcc: fix use-after-free and double free in _OSC evaluation
  2026-05-13 12:06 [PATCH] cpufreq: pcc: fix use-after-free and double free in _OSC evaluation Hongyan Xu
@ 2026-05-13 12:53 ` Zhongqiu Han
  0 siblings, 0 replies; 2+ messages in thread
From: Zhongqiu Han @ 2026-05-13 12:53 UTC (permalink / raw)
  To: Hongyan Xu, rafael
  Cc: viresh.kumar, linux-pm, linux-kernel, jianhao.xu, Slavin Liu,
	zhongqiu.han

On 5/13/2026 8:06 PM, Hongyan Xu wrote:
> pcc_cpufreq_do_osc() uses a two-phase _OSC evaluation and frees the
> output buffer returned by the first acpi_evaluate_object() call before
> reusing the same acpi_buffer in the second call.
> 
> However, output.pointer and output.length are not reset after the
> first kfree(). That can make the second acpi_evaluate_object() treat
> the stale metadata as a caller-provided buffer and write into freed
> memory. The shared out_free path can then free the same pointer again.
> 
> Reset the output buffer state after the first kfree() so ACPICA
> allocates a fresh buffer for the second _OSC evaluation.
> 
> Fixes: 0f1d683fb35d ("[CPUFREQ] Processor Clocking Control interface driver")
> Issue found using a prototype static analysis tool
> and confirmed by code review.
> 
> Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
> Signed-off-by: Slavin Liu <220245772@seu.edu.cn>
> ---
>   drivers/cpufreq/pcc-cpufreq.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c
> index ac2e90a65f0c..a355ec4f3dd4 100644
> --- a/drivers/cpufreq/pcc-cpufreq.c
> +++ b/drivers/cpufreq/pcc-cpufreq.c
> @@ -352,6 +352,8 @@ static int __init pcc_cpufreq_do_osc(acpi_handle *handle)
>   	}
>   
>   	kfree(output.pointer);
> +	output.pointer = NULL;
> +	output.length = ACPI_ALLOCATE_BUFFER;


Hi Hongyan, Slavin,

Thanks for the patch and for looking into this issue.

There is already a similar patch under discussion:
v1: https://lore.kernel.org/all/20260415165139.14113-1-dbgh9129@gmail.com/
v2: https://lore.kernel.org/all/20260416144621.93964-1-dbgh9129@gmail.com/

You may want to review that thread and see if your findings or testing
can be contributed there.


>   	capabilities[0] = 0x0;
>   	capabilities[1] = 0x1;
>   


-- 
Thx and BRs,
Zhongqiu Han

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-13 12:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 12:06 [PATCH] cpufreq: pcc: fix use-after-free and double free in _OSC evaluation Hongyan Xu
2026-05-13 12:53 ` Zhongqiu Han

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox