Module Name:    src
Committed By:   kamil
Date:           Mon May 28 13:12:54 UTC 2018

Modified Files:
        src/sys/kern: kern_sig.c

Log Message:
Enhance the signal routing of a trapsignal under a debugger

Stop resetting signal masks for crash signals under a debugger.

If we set a trap (either software or hardware one) in the code, we don't
want to see reset of signal handlers in a traced child as a knock-on effect
in the original code.

Maintain the vfork(2) + ptrace(2) special case functional.

No regressions are observed in ATF ptrace(2) and kernel/t_trapsignal tests.

Sponsored by <The NetBSD Foundation>


To generate a diff of this commit:
cvs rdiff -u -r1.347 -r1.348 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.347 src/sys/kern/kern_sig.c:1.348
--- src/sys/kern/kern_sig.c:1.347	Sun May 20 04:00:35 2018
+++ src/sys/kern/kern_sig.c	Mon May 28 13:12:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.347 2018/05/20 04:00:35 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.348 2018/05/28 13:12:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.347 2018/05/20 04:00:35 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.348 2018/05/28 13:12:54 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -904,13 +904,24 @@ trapsignal(struct lwp *l, ksiginfo_t *ks
 	KASSERT(!cpu_intr_p());
 	mutex_enter(proc_lock);
 	mutex_enter(p->p_lock);
+
+	if (ISSET(p->p_slflag, PSL_TRACED) && (p->p_pptr != p->p_opptr)) {
+		p->p_xsig = signo;
+		p->p_sigctx.ps_faked = true; // XXX
+		p->p_sigctx.ps_info._signo = signo;
+		p->p_sigctx.ps_info._code = ksi->ksi_code;
+		sigswitch(0, signo, false);
+		// XXX ktrpoint(KTR_PSIG)
+		mutex_exit(p->p_lock);
+		return;
+	}
+
 	mask = &l->l_sigmask;
 	ps = p->p_sigacts;
 
-	const bool traced = (p->p_slflag & PSL_TRACED) != 0;
 	const bool caught = sigismember(&p->p_sigctx.ps_sigcatch, signo);
 	const bool masked = sigismember(mask, signo);
-	if (!traced && caught && !masked) {
+	if (caught && !masked) {
 		mutex_exit(proc_lock);
 		l->l_ru.ru_nsignals++;
 		kpsendsig(l, ksi, mask);

Reply via email to