Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3231523imu; Mon, 28 Jan 2019 00:51:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN5RMQWh4NXetj26xW5TEFW8CG2MF4u4VmACxTUAoDZp4seNxuYv0iY6AyyE+zFbaRbsAdFU X-Received: by 2002:a63:d208:: with SMTP id a8mr18735257pgg.77.1548665513606; Mon, 28 Jan 2019 00:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548665513; cv=none; d=google.com; s=arc-20160816; b=vvX7c291ylIwZI4m5sr+iHmsUSHL0XELX4mXoE+ZoLdxs66BqQ/PP52PFQgUeMdygW CpWaz6MOrP33r80fZpY7pcran351X5K+hm7ArWdKU7U+Jb0m2qe2NrAsEKGdBO5Ltx7A Zzj1jClxor3Vwdj7Ee2EkTDZc8uF2dzsReBl/YE/e+vFYGLoCX9GG0JCa6Qmr3k0RY4k jPBRG/HTPsMG15yhHFlRmT6AfZv6iIf+eWsKsGJ14IgrLQt5Oy96cPDW7dUx0GaZBjW0 Zi+oV2gOKf9xPlfGV7dfGkT830Fz2rrJLuh+uxy6CwDB2kejq6QxSwqI/Hw2BlosT8eP PSIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=nEh9XnGJps+ebjGPItycEWKyHg5oyo0NdQrZDmdmUXI=; b=B4dNk+jbXFAfVS/0BO3OSAQ7DuOu0hKLRFP739k32dYSnYTrbNpP2EY4XjFsgA6odL +ZCY/IZOQEAzbNdJrSMrVaetho64ZbW8OPVi9V8HDF+InF2Yyi/n/QaRJDF2Vtnpx/oy 940X0JcqiewJF7MQYG8pDIIhPw1qCPjJombaL+sUv5I6fTpNzID5U55yS6I6cqIZdvJT jiNUjWRyEIvhe/X7V4BKuw9Bv1m0cSrK2+3ojjiPtnRed09/2HVHO+cLQR3icNXUGF3S aFnjFehs1Mmeqil+Bm37HQOIYCvSAOQKjMwXHI2dzNIWei47h2FNDLLJU9pobUAUpXn0 Ursw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j39si4301907plb.272.2019.01.28.00.51.38; Mon, 28 Jan 2019 00:51:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbfA1IuL (ORCPT + 99 others); Mon, 28 Jan 2019 03:50:11 -0500 Received: from bastet.se.axis.com ([195.60.68.11]:54270 "EHLO bastet.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbfA1IuL (ORCPT ); Mon, 28 Jan 2019 03:50:11 -0500 Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id 23ABA180C0; Mon, 28 Jan 2019 09:50:09 +0100 (CET) X-Axis-User: NO X-Axis-NonUser: YES X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id gby93N2I57df; Mon, 28 Jan 2019 09:50:08 +0100 (CET) Received: from boulder02.se.axis.com (boulder02.se.axis.com [10.0.8.16]) by bastet.se.axis.com (Postfix) with ESMTPS id 261B4183E8; Mon, 28 Jan 2019 09:50:08 +0100 (CET) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B40771A069; Mon, 28 Jan 2019 09:50:07 +0100 (CET) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A84031A067; Mon, 28 Jan 2019 09:50:07 +0100 (CET) Received: from seth.se.axis.com (unknown [10.0.2.172]) by boulder02.se.axis.com (Postfix) with ESMTP; Mon, 28 Jan 2019 09:50:07 +0100 (CET) Received: from lnxartpec.se.axis.com (lnxartpec.se.axis.com [10.88.4.9]) by seth.se.axis.com (Postfix) with ESMTP id 9BDFDF8; Mon, 28 Jan 2019 09:50:07 +0100 (CET) Received: by lnxartpec.se.axis.com (Postfix, from userid 10564) id 9874F80126; Mon, 28 Jan 2019 09:50:07 +0100 (CET) From: Vincent Whitchurch To: akpm@linux-foundation.org Cc: mcgrof@kernel.org, keescook@chromium.org, linux-kernel@vger.kernel.org, Vincent Whitchurch Subject: [PATCH v2] sysctl: Add panic-fatal-signals Date: Mon, 28 Jan 2019 09:49:59 +0100 Message-Id: <20190128084959.13060-1-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a sysctl which asks the kernel to panic when any userspace process receives a fatal signal which would trigger a core dump. This has proven to be quite useful when debugging problems seen during testing of embedded systems: When combined with kernel core dumps (saved due to the panic), it allows easier debugging of crashes which have their origin in system-wide problems such as buggy drivers or other kernel or hardware-related issues. The crashing process's core dump can be extracted from the kernel core dump using tools such as the crash utility's gcore extension. Signed-off-by: Vincent Whitchurch --- v2: Put the sysctl behind a config option include/linux/signal.h | 1 + init/Kconfig | 14 ++++++++++++++ kernel/signal.c | 5 ++++- kernel/sysctl.c | 9 +++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/signal.h b/include/linux/signal.h index cc7e2c1cd444..109efd1432e9 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -10,6 +10,7 @@ struct task_struct; /* for sysctl */ extern int print_fatal_signals; +extern int panic_fatal_signals; static inline void copy_siginfo(kernel_siginfo_t *to, const kernel_siginfo_t *from) diff --git a/init/Kconfig b/init/Kconfig index d47cb77a220e..875442f6ab53 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1242,6 +1242,20 @@ config SYSCTL_SYSCALL If unsure say N here. +config SYSCTL_PANIC_FATAL_SIGNALS + bool "panic-fatal-signals sysctl" if EXPERT + depends on PROC_SYSCTL + help + If you say Y here, a kernel.panic-fatal-signals sysctl will be + offered. If this sysctl is turned on, the kernel will panic if any + userspace process receives a fatal signal which would trigger a core + dump. + + When used together with kernel core dumps, this can be useful for + debugging some system-wide problems, primarily on embedded systems. + + If unsure, say N. + config FHANDLE bool "open by fhandle syscalls" if EXPERT select EXPORTFS diff --git a/kernel/signal.c b/kernel/signal.c index e1d7ad8e6ab1..83c6877b0182 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -59,6 +59,7 @@ static struct kmem_cache *sigqueue_cachep; int print_fatal_signals __read_mostly; +int panic_fatal_signals __read_mostly; static void __user *sig_handler(struct task_struct *t, int sig) { @@ -2497,8 +2498,10 @@ bool get_signal(struct ksignal *ksig) current->flags |= PF_SIGNALED; if (sig_kernel_coredump(signr)) { - if (print_fatal_signals) + if (print_fatal_signals || panic_fatal_signals) print_fatal_signal(ksig->info.si_signo); + if (panic_fatal_signals) + panic("Fatal signal and panic_fatal_signals=1"); proc_coredump_connector(current); /* * If it was able to dump core, this kills all diff --git a/kernel/sysctl.c b/kernel/sysctl.c index ba4d9e85feb8..48023bad5b08 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -557,6 +557,15 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, +#ifdef CONFIG_SYSCTL_PANIC_FATAL_SIGNALS + { + .procname = "panic-fatal-signals", + .data = &panic_fatal_signals, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, +#endif #ifdef CONFIG_SPARC { .procname = "reboot-cmd", -- 2.20.0