[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.19] xenpm: sanitize allocations in show_cpufreq_para_by_cpuid()



commit 748be9a974d95056763828bbb2572fdbc7b71ef7
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Mar 27 15:04:48 2025 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Mar 27 15:04:48 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 336d246346..db658ebadd 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -840,8 +840,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,
@@ -907,7 +908,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,
@@ -916,7 +918,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#staging-4.19



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.