public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]cpufreq: add NULL check to the store method of cpufreq
@ 2019-11-06  7:46 Shen Kai
  2019-11-06 12:32 ` Rafael J. Wysocki
  0 siblings, 1 reply; 10+ messages in thread
From: Shen Kai @ 2019-11-06  7:46 UTC (permalink / raw)
  To: viresh.kumar, rjw; +Cc: hushiyuan, linfeilong, linux-pm

From: shenkai <shenkai8@huawei.com>

Add NULL check in the store function here to avoid NULL callback invoking.
Though some interfaces of cpufreq are set as read-only, user can still get 
write permission using chmod which can lead to a kernel crash.

The following operations can lead to a kernel crash.

chmod +w /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
echo 1 >  /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

This bug was found on linux 4.19

Signed-off-by: shenkai <shenkai8@huawei.com>
Reported-by: linfeilong <linfeilong@huawei.com>
Reviewed-by: linfeilong <linfeilong@huawei.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index bffc11b..4ccaa96 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
 	struct freq_attr *fattr = to_attr(attr);
 	ssize_t ret = -EINVAL;
 
+	if (!fattr->store)
+		return ret;
+
 	/*
 	 * cpus_read_trylock() is used here to work around a circular lock
 	 * dependency problem with respect to the cpufreq_register_driver().
-- 
2.6.4.windows.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-11-08 11:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-06  7:46 [PATCH]cpufreq: add NULL check to the store method of cpufreq Shen Kai
2019-11-06 12:32 ` Rafael J. Wysocki
2019-11-07  1:53   ` Shen Kai
2019-11-07  2:32     ` Viresh Kumar
2019-11-07  2:34       ` Viresh Kumar
2019-11-07  2:53         ` Shen Kai
2019-11-07  3:06           ` Viresh Kumar
2019-11-07  5:08             ` [PATCH v3]cpufreq: " Shen Kai
2019-11-07  5:48               ` Viresh Kumar
2019-11-08 11:11               ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox