reboot: keep parsed reboot CPU in range
PATCH 1/1 reboot: keep parsed reboot CPU in range
reboot=s... parses the CPU number with simple_strtoul(), but stores it in an int before checking it against num_possible_cpus(). Very large values can wrap negative and bypass the range check, leaving reboot_cpu invalid for migrate_to_reboot_cpu().
Keep the parsed value unsigned until after the range check.
--- kernel/reboot.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/reboot.c +3 -4
@@ -1134,12 +1134,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 cpu =simple_strtoul (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 ()); +pr_err ("Ignoring the CPU number in reboot= option. CPU %lu exceeds possible cpu number %u\n" , + cpu,num_possible_cpus ());break ; } reboot_cpu = cpu;
Signature · 1 line
2.53.0
Quoted 4 lines · On Mon, 22 Jun 2026 15:42:16 +0000 Bradley Morgan <[email protected]> wrote:
reboot=s... parses the CPU number with
simple_strtoul(), but stores it in an int before checking it againstnum_possible_cpus(). Very large values can wrap negative and bypass the range check, leavingreboot_cpuinvalid formigrate_to_reboot_cpu().
Thanks. kstrtoXX() is the modern way.
Quoted 4 lines
Keep the parsed value unsigned until after the range check.
Fixes f9a90501faac ("reboot: refactor and comment the cpu selection code")
I don't think this is serious enough to warrant backporting.