diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2021-03-23 10:30:41 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2021-03-23 10:30:41 +0000 |
commit | 4c1d248d16915e972e7b863d8bc72c2d20d24fa8 (patch) | |
tree | cd19695ec0c337cca11c09d36f12bb6d96e2bf61 /sys | |
parent | a04c027eec71104e37c2e945b7e3929766b72bf4 (diff) |
Make a child execute fork_return() only if PTRACE_FORK has been specified.
fork_return() does an additional check to send a SIGTRAP (for a debugger)
but this signal might overwrite the SIGSTOP generated by the parent doing
a PT_ATTACH before the child has a change to execute any instruction.
Prevent a race visible only on SP system with regress/sys/kern/ptrace2.
ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_fork.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 2c84a9abf52..9ae645f2ac2 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.234 2021/02/15 09:35:59 mpi Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.235 2021/03/23 10:30:40 mpi Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -95,12 +95,15 @@ fork_return(void *arg) int sys_fork(struct proc *p, void *v, register_t *retval) { + void (*func)(void *) = child_return; int flags; flags = FORK_FORK; - if (p->p_p->ps_ptmask & PTRACE_FORK) + if (p->p_p->ps_ptmask & PTRACE_FORK) { flags |= FORK_PTRACE; - return fork1(p, flags, fork_return, NULL, retval, NULL); + func = fork_return; + } + return fork1(p, flags, func, NULL, retval, NULL); } int |