linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] smp: Fix a potential usage of stale nr_cpus
@ 2020-07-18  6:11 Muchun Song
  2020-07-19 12:09 ` Thomas Gleixner
  0 siblings, 1 reply; 2+ messages in thread
From: Muchun Song @ 2020-07-18  6:11 UTC (permalink / raw)
  To: peterz, tglx, mingo, bigeasy, namit; +Cc: linux-kernel, 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.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
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(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index a5a66fc28f4e..0bc260158047 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -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;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] smp: Fix a potential usage of stale nr_cpus
  2020-07-18  6:11 [PATCH v2] smp: Fix a potential usage of stale nr_cpus Muchun Song
@ 2020-07-19 12:09 ` Thomas Gleixner
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2020-07-19 12:09 UTC (permalink / raw)
  To: Muchun Song, peterz, mingo, bigeasy, namit; +Cc: linux-kernel, Muchun Song

Muchun Song <songmuchun@bytedance.com> writes:

> 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.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
> changelog in v2:
>  1) Rework the commit log.
>  2) Rework the return value check.

I asked:

>> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-19 12:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-18  6:11 [PATCH v2] smp: Fix a potential usage of stale nr_cpus Muchun Song
2020-07-19 12:09 ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).