mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Avi Weiss <thnkslprpt@gmail.com>
Cc: mcroce@microsoft.com, pmladek@suse.com, brads@mainlining.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] reboot: validate reboot CPU against the possible mask
Date: Tue, 24 Nov 2026 14:58:20 -0800	[thread overview]
Message-ID: <20261124145820.6701d413360b75a5828d13ce@linux-foundation.org> (raw)
In-Reply-To: <20261124082914.564587-1-thnkslprpt@gmail.com>

On Tue, 24 Nov 2026 10:29:14 +0200 Avi Weiss <thnkslprpt@gmail.com> wrote:

> 
> reboot_setup() and cpu_store() compare CPU IDs with
> num_possible_cpus(), which is a count rather than an upper bound.
> With a sparse possible mask, this rejects valid CPUs and accepts
> impossible IDs. reboot_setup() also narrows the parsed CPU number
> to int before checking it, allowing large values to be truncated.
> 
> Validate against nr_cpu_ids and cpu_possible() in both interfaces.
> Use simple_strtoull() and unsigned long long for the boot option,
> so the value is not narrowed before validation on 32- or 64-bit
> kernels. Preserve the comma-separated reboot= syntax.

So we're supporting num_possible_cpus>4G?  That's future-safety!

> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index 9a84401adde5..f57b9aaef3f0 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -1144,12 +1144,11 @@ static int __init reboot_setup(char *str)

but it's __init so who cares.

>  			str += str[1] == 'm' && str[2] == 'p' ? 3 : 1;
>  
>  			if (isdigit(str[0])) {
> -				int cpu = simple_strtoul(str, NULL, 0);
> +				unsigned long long cpu = simple_strtoull(str, NULL, 0);
>  
> -				if (cpu >= num_possible_cpus()) {
> -					pr_err("Ignoring the CPU number in reboot= option. "
> -					"CPU %d exceeds possible cpu number %d\n",
> -					cpu, num_possible_cpus());
> +				if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) {
> +					pr_err("Ignoring invalid CPU %llu in reboot= option\n",
> +					       cpu);
>  					break;
>  				}
>  				reboot_cpu = cpu;
> @@ -1351,7 +1350,7 @@ static ssize_t cpu_store(struct kobject *kobj, struct kobj_attribute *attr,
>  	if (rc)
>  		return rc;
>  
> -	if (cpunum >= num_possible_cpus())
> +	if (cpunum >= nr_cpu_ids || !cpu_possible(cpunum))
>  		return -ERANGE;

lgtm, thanks.

      parent reply	other threads:[~2026-11-24 22:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  8:29 Avi Weiss
2026-11-24 16:11 ` Bradley Morgan
2026-11-24 17:46   ` Bradley Morgan
2026-11-24 22:58 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124145820.6701d413360b75a5828d13ce@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=brads@mainlining.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcroce@microsoft.com \
    --cc=pmladek@suse.com \
    --cc=thnkslprpt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®