[CPUFREQ] Fix use after free of struct powernow_k8_data
authorThomas Renninger <trenn@suse.de>
Mon, 14 Dec 2009 10:44:15 +0000 (11:44 +0100)
committerDave Jones <davej@redhat.com>
Wed, 13 Jan 2010 15:55:15 +0000 (10:55 -0500)
Easy fix for a regression introduced in 2.6.31.

On managed CPUs the cpufreq.c core will call driver->exit(cpu) on the
managed cpus and powernow_k8 will free the core's data.

Later driver->get(cpu) function might get called trying to read out the
current freq of a managed cpu and the NULL pointer check does not work on
the freed object -> better set it to NULL.

->get() is unsigned and must return 0 as invalid frequency.

Reference:
http://bugzilla.kernel.org/show_bug.cgi?id=14391

Signed-off-by: Thomas Renninger <trenn@suse.de>
Tested-by: Michal Schmidt <mschmidt@redhat.com>
CC: stable@kernel.org
Signed-off-by: Dave Jones <davej@redhat.com>
arch/x86/kernel/cpu/cpufreq/powernow-k8.c

index a9df9441a9a240cd138b6492896cc0788a04cf1b..2da4fa3bf6e9be47e8b5453b26614883e9339ba3 100644 (file)
@@ -1356,6 +1356,7 @@ static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol)
 
        kfree(data->powernow_table);
        kfree(data);
+       per_cpu(powernow_data, pol->cpu) = NULL;
 
        return 0;
 }
@@ -1375,7 +1376,7 @@ static unsigned int powernowk8_get(unsigned int cpu)
        int err;
 
        if (!data)
-               return -EINVAL;
+               return 0;
 
        smp_call_function_single(cpu, query_values_on_cpu, &err, true);
        if (err)