Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Reintroduce struct proc::p_oppid
details: https://anonhg.NetBSD.org/src/rev/afaa4396b482
branches: trunk
changeset: 1008930:afaa4396b482
user: kamil <kamil%NetBSD.org@localhost>
date: Mon Apr 06 08:20:05 2020 +0000
description:
Reintroduce struct proc::p_oppid
Relying on p_opptr is not safe as there is a race between:
- spawner giving a birth to a child process and being killed
- spawnee accessng p_opptr and reporting TRAP_CHLD
PR kern/54786 by Andreas Gustafsson
diffstat:
sys/kern/kern_exec.c | 5 +++--
sys/kern/kern_fork.c | 8 +++++---
sys/kern/kern_proc.c | 5 +++--
sys/kern/kern_sig.c | 8 ++++----
sys/sys/proc.h | 3 ++-
5 files changed, 17 insertions(+), 12 deletions(-)
diffs (132 lines):
diff -r 54e3cb09a9c5 -r afaa4396b482 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Mon Apr 06 06:41:34 2020 +0000
+++ b/sys/kern/kern_exec.c Mon Apr 06 08:20:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.494 2020/04/05 20:53:17 christos Exp $ */
+/* $NetBSD: kern_exec.c,v 1.495 2020/04/06 08:20:05 kamil Exp $ */
/*-
* Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.494 2020/04/05 20:53:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.495 2020/04/06 08:20:05 kamil Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -2660,6 +2660,7 @@
if ((p1->p_slflag & (PSL_TRACEPOSIX_SPAWN|PSL_TRACED)) ==
(PSL_TRACEPOSIX_SPAWN|PSL_TRACED)) {
proc_changeparent(p2, p1->p_pptr);
+ p2->p_oppid = p1->p_pid;
}
LIST_INSERT_AFTER(p1, p2, p_pglist);
diff -r 54e3cb09a9c5 -r afaa4396b482 sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Mon Apr 06 06:41:34 2020 +0000
+++ b/sys/kern/kern_fork.c Mon Apr 06 08:20:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.220 2020/04/05 20:53:17 christos Exp $ */
+/* $NetBSD: kern_fork.c,v 1.221 2020/04/06 08:20:05 kamil Exp $ */
/*-
* Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008, 2019
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.220 2020/04/05 20:53:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.221 2020/04/06 08:20:05 kamil Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@@ -511,8 +511,10 @@
/*
* Trace fork(2) and vfork(2)-like events on demand in a debugger.
*/
- if (tracefork(p1, flags) || tracevfork(p1, flags))
+ if (tracefork(p1, flags) || tracevfork(p1, flags)) {
proc_changeparent(p2, p1->p_pptr);
+ p2->p_oppid = p1->p_pid;
+ }
LIST_INSERT_AFTER(p1, p2, p_pglist);
LIST_INSERT_HEAD(&allproc, p2, p_list);
diff -r 54e3cb09a9c5 -r afaa4396b482 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c Mon Apr 06 06:41:34 2020 +0000
+++ b/sys/kern/kern_proc.c Mon Apr 06 08:20:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_proc.c,v 1.242 2020/02/23 22:14:03 ad Exp $ */
+/* $NetBSD: kern_proc.c,v 1.243 2020/04/06 08:20:05 kamil Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.242 2020/02/23 22:14:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.243 2020/04/06 08:20:05 kamil Exp $");
#ifdef _KERNEL_OPT
#include "opt_kstack.h"
@@ -2270,6 +2270,7 @@
COND_SET_VALUE(p->p_sigpend, psrc->p_sigpend, allowaddr);
COND_SET_VALUE(p->p_lwpctl, psrc->p_lwpctl, allowaddr);
p->p_ppid = psrc->p_ppid;
+ p->p_oppid = psrc->p_oppid;
COND_SET_VALUE(p->p_path, psrc->p_path, allowaddr);
COND_SET_VALUE(p->p_sigctx, psrc->p_sigctx, allowaddr);
p->p_nice = psrc->p_nice;
diff -r 54e3cb09a9c5 -r afaa4396b482 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c Mon Apr 06 06:41:34 2020 +0000
+++ b/sys/kern/kern_sig.c Mon Apr 06 08:20:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sig.c,v 1.386 2020/04/05 20:53:17 christos Exp $ */
+/* $NetBSD: kern_sig.c,v 1.387 2020/04/06 08:20:05 kamil Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.386 2020/04/05 20:53:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.387 2020/04/06 08:20:05 kamil Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@@ -1693,12 +1693,12 @@
{
mutex_enter(proc_lock);
mutex_enter(p->p_lock);
- if (!(p->p_slflag & PSL_TRACED) || p->p_opptr == NULL) {
+ if (!(p->p_slflag & PSL_TRACED)) {
mutex_exit(p->p_lock);
mutex_exit(proc_lock);
return;
}
- eventswitch(code, pe_report_event, p->p_opptr->p_pid);
+ eventswitch(code, pe_report_event, p->p_oppid);
}
/*
diff -r 54e3cb09a9c5 -r afaa4396b482 sys/sys/proc.h
--- a/sys/sys/proc.h Mon Apr 06 06:41:34 2020 +0000
+++ b/sys/sys/proc.h Mon Apr 06 08:20:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.361 2020/04/05 20:53:46 christos Exp $ */
+/* $NetBSD: proc.h,v 1.362 2020/04/06 08:20:05 kamil Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -311,6 +311,7 @@
sigpend_t p_sigpend; /* p: pending signals */
struct lcproc *p_lwpctl; /* p, a: _lwp_ctl() information */
pid_t p_ppid; /* :: cached parent pid */
+ pid_t p_oppid; /* :: cached original parent pid */
char *p_path; /* :: full pathname of executable */
/*
Home |
Main Index |
Thread Index |
Old Index