]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.69/cpufreq-governor-avoid-accessing-invalid-governor_data.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.14.69 / cpufreq-governor-avoid-accessing-invalid-governor_data.patch
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
5
6 From: Henry Willard <henry.willard@oracle.com>
7
8 commit 2a3eb51e30b9ac66fe1b75877627a7e4aaeca24a upstream.
9
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.
15
16 This patch uses gov_dbs_data_mutex to synchronize access.
17
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>
24
25 ---
26 drivers/cpufreq/cpufreq_governor.c | 12 ++++++++++--
27 1 file changed, 10 insertions(+), 2 deletions(-)
28
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
32
33 void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy)
34 {
35 - struct policy_dbs_info *policy_dbs = policy->governor_data;
36 + struct policy_dbs_info *policy_dbs;
37 +
38 + /* Protect gov->gdbs_data against cpufreq_dbs_governor_exit() */
39 + mutex_lock(&gov_dbs_data_mutex);
40 + policy_dbs = policy->governor_data;
41 + if (!policy_dbs)
42 + goto out;
43
44 mutex_lock(&policy_dbs->update_mutex);
45 cpufreq_policy_apply_limits(policy);
46 gov_update_sample_delay(policy_dbs, 0);
47 -
48 mutex_unlock(&policy_dbs->update_mutex);
49 +
50 +out:
51 + mutex_unlock(&gov_dbs_data_mutex);
52 }
53 EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_limits);