smp: Fix a potential usage of stale nr_cpus
PATCH RESEND 1/1 smp: Fix a potential usage of stale nr_cpus
The get_option() maybe return 0, it means that the nr_cpus is not initialized. Then we will use the stale nr_cpus to initialize the nr_cpu_ids. So fix it.
--- kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/smp.c +1 -2
@@ -634,8 +634,7 @@ 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) && nr_cpus >0 && nr_cpus < nr_cpu_ids) nr_cpu_ids = nr_cpus;return 0 ;
Signature · 1 line
2.11.0
Muchun,
Quoted 2 lines · Muchun Song
The
get_option()maybe return 0, it means that thenr_cpusis not initialized.
Good catch, but see below.
Quoted 1 line
Then we will use the stale
nr_cpusto initialize
We use nothing. Please describe your changes in technical neutral language.
Quoted 1 line
the
nr_cpu_ids. So fix it.
'So fix it.' is not much valuable information. What about:
Check the return value to prevent this.
Hmm?
Quoted 10 lines
Signed-off-by Muchun Song <[email protected]>--- kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/smp.c +0
-0
kernel/smp.c static int __init nrcpus(char *str) · line 640
Quoted 9 lines
kernel/smp.c +1
-2@@ -634,8 +634,7 @@ 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) && nr_cpus >0 && nr_cpus < nr_cpu_ids) nr_cpu_ids = nr_cpus;return 0 ;
get_option() can return 0 - 3:
* 0 - no int in string * 1 - int found, no subsequent comma * 2 - int found including a subsequent comma * 3 - hyphen found to denote a range
For this parameter exists only one valid format: '1 - int found, no comma', right?
So why fixing it just half and why returning '0' aka success if the parameter is bogus?
Thanks,
tglx
Quoted 15 lines · Thomas Gleixner
Muchun,
Quoted 2 lines · Muchun Song
The
get_option()maybe return 0, it means that thenr_cpusis not initialized.Good catch, but see below.
Quoted 1 line
Then we will use the stale
nr_cpusto initializeWe use nothing. Please describe your changes in technical neutral language.
Quoted 7 lines
Quoted 1 line
the
nr_cpu_ids. So fix it.'So fix it.' is not much valuable information. What about:
Check the return value to prevent this.
Hmm?
Looks fine to me. Thanks.
Quoted 23 lines
Quoted 11 lines
Signed-off-by Muchun Song <[email protected]>--- kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/smp.c +0
-0kernel/smp.c static int __init nrcpus(char *str) · line 640
Quoted 9 lines
kernel/smp.c +1
-2@@ -634,8 +634,7 @@ 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) && nr_cpus >0 && nr_cpus < nr_cpu_ids) nr_cpu_ids = nr_cpus;return 0 ;
get_option()can return 0 - 3:
Quoted 7 lines
* 0 - no int in string * 1 - int found, no subsequent comma * 2 - int found including a subsequent comma * 3 - hyphen found to denote a rangeFor this parameter exists only one valid format: '1 - int found, no comma', right?
Yeah.
Quoted 3 lines
So why fixing it just half and why returning '0' aka success if the parameter is bogus?
Thanks. Will fix it.
Quoted 4 lines
Thanks,
tglx
Signature · 2 lines
Yours, Muchun
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 589343569d7b58a64ec2446e6686c8e79aea7fcf Gitweb: https://git.kernel.org/tip/589343569d7b58a64ec2446e6686c8e79aea7fcf Author: Muchun Song <[email protected]> AuthorDate: Thu, 16 Jul 2020 15:04:57 +08:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 22 Jul 2020 10:22:04 +02:00
smp: Fix a potential usage of stale nr_cpus
The get_option() maybe return 0, it means that the nr_cpus is not initialized. Then we will use the stale nr_cpus to initialize the nr_cpu_ids. So fix it.
--- kernel/smp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/smp.c +1 -2
@@ -634,8 +634,7 @@ 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) && nr_cpus >0 && nr_cpus < nr_cpu_ids) nr_cpu_ids = nr_cpus;return 0 ;