Module Name: src
Committed By: kamil
Date: Sun Apr 7 14:50:41 UTC 2019
Modified Files:
src/sys/kern: kern_fork.c
Log Message:
Add a paranoid racy lock check in child_return()
In theory a child could be detached for some reason or another during
the time window between checking for PSL_TRACED and acquiring proc_lock.
Acquire the proc_lock mutex and recheck for PSL_TRACED before emitting
SIGTRAP. sigswitch() must acquite it internally anyway so this does not
have a negative impact and adds an extra sanity check.
For !PSL_TRACED case there is no impact.
To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/kern_fork.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_fork.c
diff -u src/sys/kern/kern_fork.c:1.208 src/sys/kern/kern_fork.c:1.209
--- src/sys/kern/kern_fork.c:1.208 Sat Apr 6 11:54:21 2019
+++ src/sys/kern/kern_fork.c Sun Apr 7 14:50:41 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.208 2019/04/06 11:54:21 kamil Exp $ */
+/* $NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $ */
/*-
* Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.208 2019/04/06 11:54:21 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@@ -619,16 +619,24 @@ child_return(void *arg)
struct proc *p = l->l_proc;
if (p->p_slflag & PSL_TRACED) {
+ /* Paranoid check */
+ mutex_enter(proc_lock);
+ if (!(p->p_slflag & PSL_TRACED)) {
+ mutex_exit(proc_lock);
+ goto my_tracer_is_gone;
+ }
+
mutex_enter(p->p_lock);
p->p_xsig = SIGTRAP;
p->p_sigctx.ps_faked = true; // XXX
p->p_sigctx.ps_info._signo = p->p_xsig;
p->p_sigctx.ps_info._code = TRAP_CHLD;
- sigswitch(0, SIGTRAP, true);
+ sigswitch(0, SIGTRAP, false);
// XXX ktrpoint(KTR_PSIG)
mutex_exit(p->p_lock);
}
+my_tracer_is_gone:
md_child_return(l);
/*