1 From 2a3eb51e30b9ac66fe1b75877627a7e4aaeca24a Mon Sep 17 00:00:00 2001
2 From: Henry Willard <henry.willard@oracle.com>
3 Date: Tue, 14 Aug 2018 17:01:02 -0700
4 Subject: cpufreq: governor: Avoid accessing invalid governor_data
6 From: Henry Willard <henry.willard@oracle.com>
8 commit 2a3eb51e30b9ac66fe1b75877627a7e4aaeca24a upstream.
10 If cppc_cpufreq.ko is deleted at the same time that tuned-adm is
11 changing profiles, there is a small chance that a race can occur
12 between cpufreq_dbs_governor_exit() and cpufreq_dbs_governor_limits()
13 resulting in a system failure when the latter tries to use
14 policy->governor_data that has been freed by the former.
16 This patch uses gov_dbs_data_mutex to synchronize access.
18 Fixes: e788892ba3cc (cpufreq: governor: Get rid of governor events)
19 Signed-off-by: Henry Willard <henry.willard@oracle.com>
20 [ rjw: Subject, minor white space adjustment ]
21 Cc: 4.8+ <stable@vger.kernel.org> # 4.8+
22 Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 drivers/cpufreq/cpufreq_governor.c | 12 ++++++++++--
27 1 file changed, 10 insertions(+), 2 deletions(-)
29 --- a/drivers/cpufreq/cpufreq_governor.c
30 +++ b/drivers/cpufreq/cpufreq_governor.c
31 @@ -555,12 +555,20 @@ EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_s
33 void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy)
35 - struct policy_dbs_info *policy_dbs = policy->governor_data;
36 + struct policy_dbs_info *policy_dbs;
38 + /* Protect gov->gdbs_data against cpufreq_dbs_governor_exit() */
39 + mutex_lock(&gov_dbs_data_mutex);
40 + policy_dbs = policy->governor_data;
44 mutex_lock(&policy_dbs->update_mutex);
45 cpufreq_policy_apply_limits(policy);
46 gov_update_sample_delay(policy_dbs, 0);
48 mutex_unlock(&policy_dbs->update_mutex);
51 + mutex_unlock(&gov_dbs_data_mutex);
53 EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_limits);