summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_fork.c
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2006-11-29 12:24:15 +0000
committermiod <miod@openbsd.org>2006-11-29 12:24:15 +0000
commit46718002fd92ad6071bc17d0a8671800e19e703e (patch)
treec3e4d563248952d16989ab42dacbccaf45ff4422 /sys/kern/kern_fork.c
parentAdd an alignment parameter to uvm_km_alloc1(), and change all callers to (diff)
downloadwireguard-openbsd-46718002fd92ad6071bc17d0a8671800e19e703e.tar.xz
wireguard-openbsd-46718002fd92ad6071bc17d0a8671800e19e703e.zip
Kernel stack can be swapped. This means that stuff that's on the stack
should never be referenced outside the context of the process to which this stack belongs unless we do the PHOLD/PRELE dance. Loads of code doesn't follow the rules here. Instead of trying to track down all offenders and fix this hairy situation, it makes much more sense to not swap kernel stacks. From art@, tested by many some time ago.
Diffstat (limited to 'sys/kern/kern_fork.c')
-rw-r--r--sys/kern/kern_fork.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index a68f5b09815..3c8d6f3c011 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.84 2006/04/30 15:37:07 kettenis Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.85 2006/11/29 12:24:17 miod Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -191,10 +191,7 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
return (EAGAIN);
}
- /*
- * Allocate a pcb and kernel stack for the process
- */
- uaddr = uvm_km_valloc_align(kernel_map, USPACE, USPACE_ALIGN);
+ uaddr = uvm_km_alloc1(kernel_map, USPACE, USPACE_ALIGN, 1);
if (uaddr == 0) {
chgproccnt(uid, -1);
nprocs--;
@@ -237,7 +234,7 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
* Increase reference counts on shared objects.
* The p_stats and p_sigacts substructs are set in vm_fork.
*/
- p2->p_flag = P_INMEM;
+ p2->p_flag = 0;
p2->p_emul = p1->p_emul;
if (p1->p_flag & P_PROFIL)
startprofclock(p2);
@@ -331,11 +328,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
*/
if (p2->p_emul->e_proc_fork)
(*p2->p_emul->e_proc_fork)(p2, p1);
- /*
- * This begins the section where we must prevent the parent
- * from being swapped.
- */
- PHOLD(p1);
p2->p_addr = (struct user *)uaddr;
@@ -407,11 +399,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
SCHED_UNLOCK(s);
/*
- * Now can be swapped.
- */
- PRELE(p1);
-
- /*
* Notify any interested parties about the new process.
*/
KNOTE(&p1->p_klist, NOTE_FORK | p2->p_pid);