From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from confino.investici.org (confino.investici.org [93.190.126.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3B2B3A48E9 for ; Sun, 19 Jul 2026 16:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.190.126.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784477385; cv=none; b=j0wGCK8kY0w5/eECXL6E8Cq2dh5VsilVFSZNMZ5EDs7TCOZFb+XWZFrS5cyXy/6MZ8mvlH+ZKmRD7er/d/pyhNyRBtAN45Effd2EjlmM/LvD3jOaH/h3h5pGCoDyaMmHjzARbip9HBjYnf2rAQXTZoZIrJnbgGYMxE/Kjx0lbWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784477385; c=relaxed/simple; bh=JAjX0d+dpn4xWwf9/4zQKgX9YFFvl98e1Sle/gSHr3o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fFBjZh9eRIs+bPObQ0VO5MqvrcJPsjJqocHOuJqxbkyz5OegDNxaK4yphgo3KUB6+8jXHZZXd0/nNCIqMckIj44TFothzun0geIzZgZr6IjYBAAtIu/GC4G7J8w0ftzOI2EetoyJLEl+aK4kfdJ4Rb3ciyXO18jU8S9JDPOye4g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net; spf=pass smtp.mailfrom=grrlz.net; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b=HA3WZWMj; arc=none smtp.client-ip=93.190.126.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grrlz.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b="HA3WZWMj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grrlz.net; s=stigmate; t=1784477380; bh=mNLiy5T4gnrnD9kV5NW1KaRJZvEegFMc6eRyGnkYZq4=; h=From:To:Cc:Subject:Date:From; b=HA3WZWMjXi6DNqaxE0UD8IIe3ZOm4N3/Wlb+yYkW5Ggin9OV22hwcXOJTy4ytWOKr Ykuvr1wUiEfqt83/91LiK0rhj3dihsYyIohd0n1EhpYT9/cwiDsKT48a0oJ3Vg3pr0 kIRHWrO/RyUScR417qhhIaFbGj7M1p20xRJXi2Hc= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4h37rh3d9Nz10v3; Sun, 19 Jul 2026 16:09:40 +0000 (UTC) Received: by mx1.investici.org (Postfix) id 4h37rh0nptz10vD; Sun, 19 Jul 2026 16:09:40 +0000 (UTC) From: Bradley Morgan To: Bradley Morgan , Kees Cook 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 Message-ID: <20260719160938.3692-1-include@grrlz.net> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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