[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200727114303.GA57241@gmail.com>
Date: Mon, 27 Jul 2020 13:43:03 +0200
From: Ingo Molnar <mingo@...nel.org>
To: Muchun Song <songmuchun@...edance.com>
Cc: peterz@...radead.org, tglx@...utronix.de, bigeasy@...utronix.de,
namit@...are.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] smp: Fix a potential usage of stale nr_cpus
* Muchun Song <songmuchun@...edance.com> wrote:
> 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@...edance.com>
> ---
> changelog in v3:
> 1) Return -EINVAL when the parameter is bogus.
>
> changelog in v2:
> 1) Rework the commit log.
> 2) Rework the return value check.
>
> kernel/smp.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/smp.c b/kernel/smp.c
> index a5a66fc28f4e..0dacfcfcf00b 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -772,9 +772,13 @@ static int __init nrcpus(char *str)
> {
> int nr_cpus;
>
> - get_option(&str, &nr_cpus);
> + if (get_option(&str, &nr_cpus) != 1)
> + return -EINVAL;
> +
> if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
> nr_cpu_ids = nr_cpus;
> + else
> + return -EINVAL;
Exactly what does 'not valid' mean, and why doesn't get_option()
return -EINVAL in that case?
Thanks,
Ingo
Powered by blists - more mailing lists