Commit c8d14edf authored by Schspa Shi's avatar Schspa Shi Committed by openeuler-sync-bot
Browse files

cpufreq: Abort show()/store() for half-initialized policies

mainline inclusion
from mainline-v5.19-rc1
commit d4627a28
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8EI9L
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d4627a287e251efed59f2b4bda82c5950768c963



--------------------------------

If policy initialization fails after the sysfs files are created,
there is a possibility to end up running show()/store() callbacks
for half-initialized policies, which may have unpredictable
outcomes.

Abort show()/store() in such a case by making sure the policy is active.

Also dectivate the policy on such failures.

Signed-off-by: default avatarSchspa Shi <schspa@gmail.com>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
[ rjw: Subject and changelog edits ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>

Conflicts:
	drivers/cpufreq/cpufreq.c

Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
(cherry picked from commit ae440cc2)
parent 1049f3bb
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -946,12 +946,13 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
{
	struct cpufreq_policy *policy = to_policy(kobj);
	struct freq_attr *fattr = to_attr(attr);
	ssize_t ret;
	ssize_t ret = -EBUSY;

	if (!fattr->show)
		return -EIO;

	down_read(&policy->rwsem);
	if (likely(!policy_is_inactive(policy)))
		ret = fattr->show(policy, buf);
	up_read(&policy->rwsem);

@@ -963,7 +964,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
{
	struct cpufreq_policy *policy = to_policy(kobj);
	struct freq_attr *fattr = to_attr(attr);
	ssize_t ret = -EINVAL;
	ssize_t ret = -EBUSY;

	if (!fattr->store)
		return -EIO;
@@ -977,6 +978,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,

	if (cpu_online(policy->cpu)) {
		down_write(&policy->rwsem);
		if (likely(!policy_is_inactive(policy)))
			ret = fattr->store(policy, buf, count);
		up_write(&policy->rwsem);
	}
@@ -1515,6 +1517,7 @@ static int cpufreq_online(unsigned int cpu)
	for_each_cpu(j, policy->real_cpus)
		remove_cpu_dev_symlink(policy, get_cpu_device(j));

	cpumask_clear(policy->cpus);
	up_write(&policy->rwsem);

out_offline_policy: