[PATCH v2] reboot: don't rely on the poweroff/reboot helper before init has started
From: Zak Brighton Knight
Date: Tue Nov 17 2026 - 17:31:10 EST
__hw_protection_trigger() asks userspace to power off through
orderly_poweroff(true). The kernel forces the power-off only if
running poweroff_cmd fails, and run_cmd() waits for the exec only.
Before init has started that exec can succeed and do nothing. Usermode
helpers work once the initramfs is unpacked, so a built-in driver that
triggers during device initcalls runs the initramfs /sbin/poweroff.
On a systemd initramfs that is systemctl, which exits 0 without doing
anything. The default CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
arms no backup timer and only the first request is acted on. The
machine then runs without critical temperature protection until the
next boot.
A ThinkPad T520 booted while still hot hit this. Its ACPI zone read
101 C against a 100 C _CRT 0.29 s into boot and the machine ran on for
90 minutes.
Skip the helper until system_state reaches SYSTEM_RUNNING where the
caller can force the action itself. __orderly_poweroff(true) then
syncs and powers off and __orderly_reboot() syncs and restarts.
orderly_poweroff(false) has no fallback so it runs the helper as
before.
SYSTEM_RUNNING is set before do_sysctl_args() and before init is
exec'd. From there until init can handle the request the helper can
still do nothing. A non-zero CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS
covers that window.
Fixes: 10a0a8d4e3f6 ("Add common orderly_poweroff()")
Signed-off-by: Zak Brighton Knight <zakbrightonknight@xxxxxxxxx>
---
Changes in v2:
- Skip the helper only where the caller forces the action itself.
orderly_poweroff(false) runs it as before (from the review Andrew
forwarded).
- The check moved from run_cmd() into its two callers. New subject.
- Shorter comment (Bradley) and commit message.
- Say which window is left (same review). The kernel cannot tell when
init is ready so I don't see how to close it here.
- Dropped the Reviewed-by tags from Bradley and Matti because the code
changed. Please have another look.
v1: https://lore.kernel.org/all/20261107143129.875202-1-zakbrightonknight@xxxxxxxxx/
An AI coding assistant (Claude by Anthropic) helped find the cause,
build the reproducer and draft this patch.
Tested in QEMU only, not on the T520. An early trip now powers off or
restarts within a few milliseconds. A trip after init still runs
/sbin/poweroff. An early orderly_poweroff(false) from a test-only
initcall still runs the helper. I can send the reproducer.
Firmware that reports a bogus critical temperature only in early boot
will now power the machine off at boot.
kernel/reboot.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 9a84401adde5..546abe42964e 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -871,9 +871,14 @@ static int run_cmd(const char *cmd)
static int __orderly_reboot(void)
{
- int ret;
+ int ret = -EBUSY;
- ret = run_cmd(reboot_cmd);
+ /*
+ * Before init has started the command can exec from the initramfs
+ * and do nothing. Don't rely on it then.
+ */
+ if (system_state >= SYSTEM_RUNNING)
+ ret = run_cmd(reboot_cmd);
if (ret) {
pr_warn("Failed to start orderly reboot: forcing the issue\n");
@@ -886,9 +891,11 @@ static int __orderly_reboot(void)
static int __orderly_poweroff(bool force)
{
- int ret;
+ int ret = -EBUSY;
- ret = run_cmd(poweroff_cmd);
+ /* As in __orderly_reboot(), but only if we can force the poweroff. */
+ if (!force || system_state >= SYSTEM_RUNNING)
+ ret = run_cmd(poweroff_cmd);
if (ret && force) {
pr_warn("Failed to start orderly shutdown: forcing the issue\n");
base-commit: 141b164bbe186423e295b139e40e8e2d11cf1341
--
2.56.0