Page MenuHomeFreeBSD

D24813.id71690.diff
No OneTemporary

D24813.id71690.diff

Index: sbin/devd/devd.conf.5
===================================================================
--- sbin/devd/devd.conf.5
+++ sbin/devd/devd.conf.5
@@ -272,6 +272,8 @@
Name of attached/detached device.
.It Li endpoints
Endpoint count (USB).
+.It Li euid
+Effective UID (corestop).
.It Li function
Card functions.
.It Li interface
@@ -295,7 +297,8 @@
.It Li parent
Parent device.
.It Li pid
-PID of the process triggering the rule (RCTL).
+PID of the process triggering the rule (RCTL),
+or the process that crashed (corestop).
.It Li port
Hub port number (USB).
.It Li product
@@ -521,6 +524,9 @@
.It Sy Type
.It Li coredump
Notification that a process has crashed and dumped core.
+.It Li corestop
+Notification that a process would crash, but was stopped
+just before executing the offending instruction.
.El
.El
.Pp
Index: sys/kern/kern_sig.c
===================================================================
--- sys/kern/kern_sig.c
+++ sys/kern/kern_sig.c
@@ -189,6 +189,10 @@
SYSCTL_INT(_kern, OID_AUTO, coredump, CTLFLAG_RW,
&do_coredump, 0, "Enable/Disable coredumps");
+static int do_corestop = 0;
+SYSCTL_INT(_kern, OID_AUTO, corestop, CTLFLAG_RW,
+ &do_corestop, 0, "Send SIGSTOP before dumping core");
+
static int set_core_nodump_flag = 0;
SYSCTL_INT(_kern, OID_AUTO, nodump_coredump, CTLFLAG_RW, &set_core_nodump_flag,
0, "Enable setting the NODUMP flag on coredump files");
@@ -2004,7 +2008,8 @@
struct sigacts *ps;
struct proc *p;
sigset_t sigmask;
- int code, sig;
+ char strbuf[32];
+ int code, sig, rv;
p = td->td_proc;
sig = ksi->ksi_signo;
@@ -2018,6 +2023,26 @@
sigmask = td->td_sigmask;
if (td->td_sigblock_val != 0)
SIGSETOR(sigmask, fastblock_mask);
+
+ if (do_corestop && (sigprop(sig) & SIGPROP_CORE) &&
+ (p->p_flag2 & P2_CORESTOPPED) == 0) {
+ if (kern_logsigexit) {
+ log(LOG_INFO,
+ "pid %d (%s), jid %d, uid %d: would exit on "
+ "signal %d, corestopped\n", p->p_pid, p->p_comm,
+ p->p_ucred->cr_prison->pr_id,
+ td->td_ucred->cr_uid,
+ sig &~ WCOREFLAG);
+ }
+ rv = snprintf(strbuf, sizeof(strbuf),
+ "pid=%d euid=%d", p->p_pid, p->p_ucred->cr_uid);
+ KASSERT(rv > 0 && rv < sizeof(strbuf),
+ ("%s: snprintf failed\n", __func__));
+ devctl_notify("kernel", "signal", "corestop", strbuf);
+ ksi->ksi_signo = sig = SIGSTOP;
+ p->p_flag2 |= P2_CORESTOPPED;
+ }
+
if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(ps->ps_sigcatch, sig) &&
!SIGISMEMBER(sigmask, sig)) {
#ifdef KTRACE
Index: sys/sys/proc.h
===================================================================
--- sys/sys/proc.h
+++ sys/sys/proc.h
@@ -782,6 +782,7 @@
#define P2_PROTMAX_DISABLE 0x00000400 /* Force disable implied PROT_MAX. */
#define P2_STKGAP_DISABLE 0x00000800 /* Disable stack gap for MAP_STACK */
#define P2_STKGAP_DISABLE_EXEC 0x00001000 /* Stack gap disabled after exec */
+#define P2_CORESTOPPED 0x00002000 /* Crashed, got SIGSTOP */
/* Flags protected by proctree_lock, kept in p_treeflags. */
#define P_TREE_ORPHANED 0x00000001 /* Reparented, on orphan list */

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 29, 3:52 AM (53 m, 14 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32268314
Default Alt Text
D24813.id71690.diff (3 KB)

Event Timeline