Commit e6e8df07 authored by Kai Shen's avatar Kai Shen Committed by Rafael J. Wysocki

cpufreq: Add NULL checks to show() and store() methods of cpufreq

Add NULL checks to show() and store() in cpufreq.c to avoid attempts
to invoke a NULL callback.

Though some interfaces of cpufreq are set as read-only, users can
still get write permission using chmod which can lead to a kernel
crash, as follows:

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 in linux 4.19.
Signed-off-by: default avatarKai Shen <shenkai8@huawei.com>
Reported-by: default avatarFeilong Lin <linfeilong@huawei.com>
Reviewed-by: default avatarFeilong Lin <linfeilong@huawei.com>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
[ rjw: Subject & changelog ]
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 8d2eecea
...@@ -933,6 +933,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) ...@@ -933,6 +933,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
struct freq_attr *fattr = to_attr(attr); struct freq_attr *fattr = to_attr(attr);
ssize_t ret; ssize_t ret;
if (!fattr->show)
return -EIO;
down_read(&policy->rwsem); down_read(&policy->rwsem);
ret = fattr->show(policy, buf); ret = fattr->show(policy, buf);
up_read(&policy->rwsem); up_read(&policy->rwsem);
...@@ -947,6 +950,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, ...@@ -947,6 +950,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
struct freq_attr *fattr = to_attr(attr); struct freq_attr *fattr = to_attr(attr);
ssize_t ret = -EINVAL; ssize_t ret = -EINVAL;
if (!fattr->store)
return -EIO;
/* /*
* cpus_read_trylock() is used here to work around a circular lock * cpus_read_trylock() is used here to work around a circular lock
* dependency problem with respect to the cpufreq_register_driver(). * dependency problem with respect to the cpufreq_register_driver().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment