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

[Xen-changelog] [xen master] x86/cpuidle: prevent out of bounds array access



commit 1cfb320b88588bb42e95eb49fba69358802b771e
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Fri May 22 17:34:51 2015 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri May 22 17:34:51 2015 +0200

    x86/cpuidle: prevent out of bounds array access
    
    ... resulting from fbeef5570c ("x86/cpuidle: get accurate C0 value with
    xenpm tool"). For consistency also no longer account an unknown state
    to C0 in pmstat_get_cx_stat().
    
    Reported-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/acpi/cpu_idle.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/acpi/cpu_idle.c b/xen/arch/x86/acpi/cpu_idle.c
index 95676dd..36bbb8b 100644
--- a/xen/arch/x86/acpi/cpu_idle.c
+++ b/xen/arch/x86/acpi/cpu_idle.c
@@ -279,7 +279,7 @@ static void print_acpi_power(uint32_t cpu, struct 
acpi_processor_power *power)
     uint64_t usage[ACPI_PROCESSOR_MAX_POWER] = { 0 };
     uint64_t res_tick[ACPI_PROCESSOR_MAX_POWER] = { 0 };
     unsigned int i;
-    u8 last_state_idx;
+    signed int last_state_idx;
 
     printk("==cpu%d==\n", cpu);
     last_state_idx = power->last_state ? power->last_state->idx : -1;
@@ -298,8 +298,12 @@ static void print_acpi_power(uint32_t cpu, struct 
acpi_processor_power *power)
     last_state_update_tick = power->last_state_update_tick;
     spin_unlock_irq(&power->stat_lock);
 
-    res_tick[last_state_idx] += ticks_elapsed(last_state_update_tick, 
current_tick);
-    usage[last_state_idx]++;
+    if ( last_state_idx >= 0 )
+    {
+        res_tick[last_state_idx] += ticks_elapsed(last_state_update_tick,
+                                                  current_tick);
+        usage[last_state_idx]++;
+    }
 
     for ( i = 1; i < power->count; i++ )
     {
@@ -1233,6 +1237,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat 
*stat)
     else
     {
         struct hw_residencies hw_res;
+        signed int last_state_idx;
 
         stat->nr = power->count;
 
@@ -1245,11 +1250,18 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct 
pm_cx_stat *stat)
             res[i] = power->states[i].time;
         }
         last_state_update_tick = power->last_state_update_tick;
-        stat->last = power->last_state ? power->last_state->idx : 0;
+        last_state_idx = power->last_state ? power->last_state->idx : -1;
         spin_unlock_irq(&power->stat_lock);
 
-        usage[stat->last]++;
-        res[stat->last] += ticks_elapsed(last_state_update_tick, current_tick);
+        if ( last_state_idx >= 0 )
+        {
+            usage[last_state_idx]++;
+            res[last_state_idx] += ticks_elapsed(last_state_update_tick,
+                                                 current_tick);
+            stat->last = last_state_idx;
+        }
+        else
+            stat->last = 0;
 
         for ( i = 1; i < nr; i++ )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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