Patch series "fix parsing of reboot= cmdline", v3. The parsing of the reboot= cmdline has two major errors: - a missing bound check can crash the system on reboot - parsing of the cpu number only works if specified last Fix both. This patch (of 2): This reverts commit 616feab753972b97. kstrtoint() and simple_strtoul() have a subtle difference which makes them non interchangeable: if a non digit character is found amid the parsing, the former will return an error, while the latter will just stop parsing, e.g. simple_strtoul("123xyx") = 123. The kernel cmdline reboot= argument allows to specify the CPU used for rebooting, with the syntax `s####` among the other flags, e.g. "reboot=warm,s31,force", so if this flag is not the last given, it's silently ignored as well as the subsequent ones.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -551,22 +551,15 @@ static int __init reboot_setup(char *str) · 550 unmodified lines | ||
| 551 | 551 | break; |
| 552 | 552 | |
| 553 | 553 | case 's': |
| 554 | − { | |
| 555 | − int rc; | |
| 556 | − | |
| 557 | − if (isdigit(*(str+1))) { | |
| 558 | − rc = kstrtoint(str+1, 0, &reboot_cpu); | |
| 559 | − if (rc) | |
| 560 | − return rc; | |
| 561 | − } else if (str[1] == 'm' && str[2] == 'p' && | |
| 562 | − isdigit(*(str+3))) { | |
| 563 | − rc = kstrtoint(str+3, 0, &reboot_cpu); | |
| 564 | − if (rc) | |
| 565 | − return rc; | |
| 566 | − } else | |
| 554 | + if (isdigit(*(str+1))) | |
| 555 | + reboot_cpu = simple_strtoul(str+1, NULL, 0); | |
| 556 | + else if (str[1] == 'm' && str[2] == 'p' && | |
| 557 | + isdigit(*(str+3))) | |
| 558 | + reboot_cpu = simple_strtoul(str+3, NULL, 0); | |
| 559 | + else | |
| 567 | 560 | *mode = REBOOT_SOFT; |
| 568 | 561 | break; |
| 569 | − } | |
| 562 | + | |
| 570 | 563 | case 'g': |
| 571 | 564 | *mode = REBOOT_GPIO; |
| 572 | 565 | break; |