Re: [PATCH v2] reboot: validate reboot CPU against the possible mask
From: Bradley Morgan
Date: Tue Nov 24 2026 - 11:11:27 EST
On 24 November 2026 08:29:14 GMT, Avi Weiss <thnkslprpt@xxxxxxxxx> 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.
>
>Fixes: df5b0ab3e08a ("reboot: fix overflow parsing reboot cpu number")
>Fixes: 2c622ed0eaa3 ("reboot: allow to specify reboot mode via sysfs")
>Reported-by: Bradley Morgan <include@xxxxxxxxx>
>Link: https://lore.kernel.org/r/20260622154216.10064-1-include@xxxxxxxxx
>Suggested-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
>Link: https://lore.kernel.org/r/D92156F5-5924-45CD-BCFE-AF385BDD15CF@xxxxxxxxxxxxxx
>Signed-off-by: Avi Weiss <thnkslprpt@xxxxxxxxx>
How did you account for this?
https://lore.kernel.org/all/20260624174642.da2cc6912a9b19accd378538@xxxxxxxxxxxxxxxxxxxx/
>---
>
>v2:
>- apply Bradley Morgan's unsigned parsing review, widening to 64 bits
> for consistent behavior on 32- and 64-bit kernels
>
>v1: https://lore.kernel.org/r/20261031060602.2949895-2-thnkslprpt@xxxxxxxxx
>
> kernel/reboot.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
>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)
> 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;
>
> reboot_default = 0;
>
>base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
>
--- Thanks!