Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Add a paranoid racy lock check in child_return()
details: https://anonhg.NetBSD.org/src/rev/a02b1e9bd8e1
branches: trunk
changeset: 455610:a02b1e9bd8e1
user: kamil <kamil%NetBSD.org@localhost>
date: Sun Apr 07 14:50:41 2019 +0000
description:
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.
diffstat:
sys/kern/kern_fork.c | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diffs (44 lines):
diff -r cf618f15b7e4 -r a02b1e9bd8e1 sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Sun Apr 07 14:44:51 2019 +0000
+++ b/sys/kern/kern_fork.c Sun Apr 07 14:50:41 2019 +0000
@@ -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 @@
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);
/*
Home |
Main Index |
Thread Index |
Old Index