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

[Xen-changelog] [xen-unstable] Update cpufreq statistic protection



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1224578936 -3600
# Node ID 687601e210551b99530f80304b071c9447bb2af7
# Parent  27eec3c54d08b8941eb06c1fae6fea5f98013e43
Update cpufreq statistic protection

For struct pm_px, there are 3 pointer: pxpt, pt, trans_pt.
Partly free pointer 'pt' and 'trans_pt' will result in little memory
leak, and what is more, will result in protection issue when user
access px statistic info through libxc.

Signed-off-by: Liu, Jinsong <jinsong.liu@xxxxxxxxx>
---
 xen/drivers/cpufreq/utility.c |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff -r 27eec3c54d08 -r 687601e21055 xen/drivers/cpufreq/utility.c
--- a/xen/drivers/cpufreq/utility.c     Tue Oct 21 09:48:08 2008 +0100
+++ b/xen/drivers/cpufreq/utility.c     Tue Oct 21 09:48:56 2008 +0100
@@ -73,27 +73,30 @@ int cpufreq_statistic_init(unsigned int 
     struct pm_px *pxpt = cpufreq_statistic_data[cpuid];
     const struct processor_pminfo *pmpt = processor_pminfo[cpuid];
 
+    if ( !pmpt )
+        return -EINVAL;
+
+    if ( pxpt )
+        return 0;
+
     count = pmpt->perf.state_count;
 
-    if ( !pmpt )
-        return -EINVAL;
-
+    pxpt = xmalloc(struct pm_px);
     if ( !pxpt )
-    {
-        pxpt = xmalloc(struct pm_px);
-        if ( !pxpt )
-            return -ENOMEM;
-        memset(pxpt, 0, sizeof(*pxpt));
-        cpufreq_statistic_data[cpuid] = pxpt;
-    }
+        return -ENOMEM;
+    memset(pxpt, 0, sizeof(*pxpt));
+    cpufreq_statistic_data[cpuid] = pxpt;
 
     pxpt->u.trans_pt = xmalloc_array(uint64_t, count * count);
-    if (!pxpt->u.trans_pt)
+    if (!pxpt->u.trans_pt) {
+        xfree(pxpt);
         return -ENOMEM;
+    }
 
     pxpt->u.pt = xmalloc_array(struct pm_px_val, count);
     if (!pxpt->u.pt) {
         xfree(pxpt->u.trans_pt);
+        xfree(pxpt);
         return -ENOMEM;
     }
 
@@ -120,7 +123,8 @@ void cpufreq_statistic_exit(unsigned int
         return;
     xfree(pxpt->u.trans_pt);
     xfree(pxpt->u.pt);
-    memset(pxpt, 0, sizeof(struct pm_px));
+    xfree(pxpt);
+    cpufreq_statistic_data[cpuid] = NULL;
 }
 
 void cpufreq_statistic_reset(unsigned int cpuid)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
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®.