Skip to contentSkip to conversation

smp: Fix a potential usage of stale nr_cpus

PATCH Superseded Muchun Song 2 participants 2 messages Jul 18, 2020 – Jul 19, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 smp: Fix a potential usage of stale nr_cpus

When the cmdline of "nr_cpus" is not valid, the @nr_cpu_ids is assigned a stale value. The nr_cpus is only valid when get_option() return 1. So check the return value to prevent this.

---
changelog in v2:
1) Rework the commit log.
2) Rework the return value check.

 kernel/smp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/smp.c +2 -2
index a5a66fc28f4e..0bc260158047 100644
@@ -772,8 +772,8 @@ static int __init nrcpus(char *str)
 {
 	int nr_cpus;
 
-	get_option(&str, &nr_cpus);
-	if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
+	if ((get_option(&str, &nr_cpus) == 1) &&
+	    nr_cpus > 0 && nr_cpus < nr_cpu_ids)
 		nr_cpu_ids = nr_cpus;
 
 	return 0;
Signature · 1 line
2.11.0
#1 lore raw
Quoted 9 lines · Muchun Song

When the cmdline of "nr_cpus" is not valid, the @nr_cpu_ids is assigned a stale value. The nr_cpus is only valid when get_option() return 1. So check the return value to prevent this.

---
changelog in v2:
1) Rework the commit log.
2) Rework the return value check.

I asked:

Quoted 2 lines
Quoted 2 lines

So why fixing it just half and why returning '0' aka success if the parameter is bogus?

And this still returns 0 if the parameter is bogus or malformatted....

Thanks,

tglx