All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bradley Morgan <include@grrlz.net>
To: Bradley Morgan <include@grrlz.net>, Kees Cook <kees@kernel.org>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: [PATCH v2] reboot: log the task that requested a reboot or shutdown
Date: Sun, 19 Jul 2026 16:09:38 +0000	[thread overview]
Message-ID: <20260719160938.3692-1-include@grrlz.net> (raw)

When a machine reboots or powers off, the kernel log records what
happened but not who asked for it.  The reboot syscall throws the
caller identity away, and reconstructing it afterwards from userspace
logs is unreliable and more likely than not impossible.
"What made this reboot?" is a question every fleet operator has had to
answer with guesswork.

Log the comm and pid of the calling task in the reboot syscall, once
the requested command is committed and can no longer fail, e.g:

  reboot: initiated by systemd-shutdow[1]
  reboot: Restarting system

The existing "Restarting system", "System halted" and "Power down"
lines are left untouched, so anything parsing dmesg today keeps
working. The two ctrl alt del toggle commands are excluded so init
setting the mode does not add a line to dmesg on every boot.

Signed-off-by: Bradley Morgan <include@grrlz.net>
---
 kernel/reboot.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index c10ac6a0200d..ecf9535078f5 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -718,6 +718,12 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
 
 DEFINE_MUTEX(system_transition_mutex);
 
+static void reboot_log_initiator(void)
+{
+	pr_info("initiated by %s[%d]\n",
+		current->comm, task_pid_nr(current));
+}
+
 /*
  * Reboot system call: for obvious reasons only root may call it,
  * and even root needs to set up some magic numbers in the registers
@@ -765,6 +771,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	mutex_lock(&system_transition_mutex);
 	switch (cmd) {
 	case LINUX_REBOOT_CMD_RESTART:
+		reboot_log_initiator();
 		kernel_restart(NULL);
 		break;
 
@@ -777,11 +784,13 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 		break;
 
 	case LINUX_REBOOT_CMD_HALT:
+		reboot_log_initiator();
 		kernel_halt();
 		/* machine_halt() was expected to not return. */
 		make_task_dead(SIGKILL);
 
 	case LINUX_REBOOT_CMD_POWER_OFF:
+		reboot_log_initiator();
 		kernel_power_off();
 		/* machine_power_off() was expected to not return. */
 		make_task_dead(SIGKILL);
@@ -795,6 +804,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 		}
 		buffer[sizeof(buffer) - 1] = '\0';
 
+		reboot_log_initiator();
 		kernel_restart(buffer);
 		break;
 
-- 
2.53.0


             reply	other threads:[~2026-07-19 16:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-19 16:09 Bradley Morgan [this message]
2026-07-20  6:15 ` [PATCH v2] reboot: log the task that requested a reboot or shutdown Andrew Morton
2026-07-20  7:51   ` Bradley Morgan

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=20260719160938.3692-1-include@grrlz.net \
    --to=include@grrlz.net \
    --cc=akpm@linux-foundation.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.