|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen stable-4.18] xenpm: sanitize allocations in show_cpufreq_para_by_cpuid()
commit 204701a9488b6e19fbc22528aef3946590d0c2ad
Author: Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Mar 27 15:25:30 2025 +0100
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Mar 27 15:25:30 2025 +0100
xenpm: sanitize allocations in show_cpufreq_para_by_cpuid()
malloc(), when passed zero size, may return NULL (the behavior is
implementation defined). Mirror the ->gov_num check to the other two
allocations as well. Don't chance then actually using a NULL in
print_cpufreq_para().
Fixes: 75e06d089d48 ("xenpm: add cpu frequency control interface, through
which user can")
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
master commit: 6c0dc87bb0e08fb31a68bf4c4149a18b92628f14
master date: 2025-03-26 12:30:57 +0100
---
tools/misc/xenpm.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c
index d982482a3f..f6661851d4 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -827,8 +827,9 @@ static void print_cpufreq_para(int cpuid, struct
xc_get_cpufreq_para *p_cpufreq)
}
else
{
- printf("scaling_avail_gov : %s\n",
- p_cpufreq->scaling_available_governors);
+ if ( p_cpufreq->gov_num )
+ printf("scaling_avail_gov : %s\n",
+ p_cpufreq->scaling_available_governors);
printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor);
if ( !strncmp(p_cpufreq->u.s.scaling_governor,
@@ -894,7 +895,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface
*xc_handle, int cpuid)
p_cpufreq->scaling_available_frequencies = NULL;
p_cpufreq->scaling_available_governors = NULL;
- if (!(p_cpufreq->affected_cpus =
+ if (p_cpufreq->cpu_num &&
+ !(p_cpufreq->affected_cpus =
malloc(p_cpufreq->cpu_num * sizeof(uint32_t))))
{
fprintf(stderr,
@@ -903,7 +905,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface
*xc_handle, int cpuid)
ret = -ENOMEM;
goto out;
}
- if (!(p_cpufreq->scaling_available_frequencies =
+ if (p_cpufreq->freq_num &&
+ !(p_cpufreq->scaling_available_frequencies =
malloc(p_cpufreq->freq_num * sizeof(uint32_t))))
{
fprintf(stderr,
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.18
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |