From e25303676e18a7947185a34e26dd08cf0c0ea573 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Wed, 7 Oct 2015 13:50:43 -0700 Subject: cpufreq: acpi_cpufreq: prevent crash on reading freqdomain_cpus When freqdomain_cpus attribute is read from an offlined cpu, it will cause crash. This change prevents calling cpufreq_show_cpus when policy driver_data is NULL. Crash info: [ 170.814949] BUG: unable to handle kernel NULL pointer dereference at 0000000000000018 [ 170.814990] IP: [] _find_next_bit.part.0+0x10/0x70 [ 170.815021] PGD 227d30067 PUD 229e56067 PMD 0 [ 170.815043] Oops: 0000 [#2] SMP [ 170.816022] CPU: 3 PID: 3121 Comm: cat Tainted: G D OE 4.3.0-rc3+ #33 ... ... [ 170.816657] Call Trace: [ 170.816672] [] ? find_next_bit+0x15/0x20 [ 170.816696] [] cpufreq_show_cpus+0x5c/0xd0 [ 170.816722] [] show_freqdomain_cpus+0x19/0x20 [acpi_cpufreq] [ 170.816749] [] show+0x3b/0x60 [ 170.816769] [] sysfs_kf_seq_show+0xbc/0x130 [ 170.816793] [] kernfs_seq_show+0x23/0x30 [ 170.816816] [] seq_read+0xec/0x390 [ 170.816837] [] kernfs_fop_read+0x10a/0x160 [ 170.816861] [] __vfs_read+0x37/0x100 [ 170.816883] [] ? security_file_permission+0xa0/0xc0 [ 170.816909] [] vfs_read+0x83/0x130 [ 170.816930] [] SyS_read+0x55/0xc0 ... ... [ 170.817185] ---[ end trace bc6eadf82b2b965a ]--- Signed-off-by: Srinivas Pandruvada Acked-by: Viresh Kumar Cc: 4.2+ # 4.2+ Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/acpi-cpufreq.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/cpufreq') diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index 798277227de7..cec1ee2d2f74 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -149,6 +149,9 @@ static ssize_t show_freqdomain_cpus(struct cpufreq_policy *policy, char *buf) { struct acpi_cpufreq_data *data = policy->driver_data; + if (unlikely(!data)) + return -ENODEV; + return cpufreq_show_cpus(data->freqdomain_cpus, buf); } -- cgit v1.2.3-55-g7522 From 55582bccdc1e89ecc973c260d46e247df675d4df Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Wed, 7 Oct 2015 13:50:44 -0700 Subject: cpufreq: prevent lockup on reading scaling_available_frequencies When scaling_available_frequencies is read on an offlined cpu, then either lockup or junk values are displayed. This is caused by freed freq_table, which policy is using. Signed-off-by: Srinivas Pandruvada Acked-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/cpufreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/cpufreq') diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ef5ed9470de9..25c4c15103a0 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1436,8 +1436,10 @@ static void cpufreq_offline_finish(unsigned int cpu) * since this is a core component, and is essential for the * subsequent light-weight ->init() to succeed. */ - if (cpufreq_driver->exit) + if (cpufreq_driver->exit) { cpufreq_driver->exit(policy); + policy->freq_table = NULL; + } } /** -- cgit v1.2.3-55-g7522