Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f4eedd6 authored by Pracheer's avatar Pracheer Committed by Tapas Kumar Kundu
Browse files

soc: qcom: Avoid accessing invalid CPU ids



While getting input for min and max freq from userspace,
checking against just the number of present CPUs can
cause an access to an invalid CPU id if the userspace
input is not properly constructed for a particular
target.
This change prevents that from happening by
checking against num_present_cpus() - 1 so that
invalid CPU ids are not considered while accepting
input from userspace.

Change-Id: I9e52a175ff8ea9448a0676695a63ffddfa12419e
Signed-off-by: default avatarPracheer <pracheer@codeaurora.org>
parent 6fccfe92
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ static int set_cpu_min_freq(const char *buf, const struct kernel_param *kp)
	for (i = 0; i < ntokens; i += 2) {
		if (sscanf(cp, "%u:%u", &cpu, &val) != 2)
			return -EINVAL;
		if (cpu > num_present_cpus())
		if (cpu > (num_present_cpus() - 1))
			return -EINVAL;

		i_cpu_stats = &per_cpu(cpu_stats, cpu);
@@ -331,7 +331,7 @@ static int set_cpu_max_freq(const char *buf, const struct kernel_param *kp)
	for (i = 0; i < ntokens; i += 2) {
		if (sscanf(cp, "%u:%u", &cpu, &val) != 2)
			return -EINVAL;
		if (cpu > num_present_cpus())
		if (cpu > (num_present_cpus() - 1))
			return -EINVAL;

		i_cpu_stats = &per_cpu(cpu_stats, cpu);