From 6fba33142428c35a7ad60b3a566c1425b41f5aa9 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 11 Jun 2000 06:22:01 +0000 Subject: [PATCH] cpu_fork(): Check "flags" before dereferencing "p2". Otherwise, the call "vm_fork(p1, 0, flags);" early in fork1 can cause a kernel panic. --- sys/alpha/alpha/vm_machdep.c | 5 ++--- sys/powerpc/aim/vm_machdep.c | 5 ++--- sys/powerpc/powerpc/vm_machdep.c | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sys/alpha/alpha/vm_machdep.c b/sys/alpha/alpha/vm_machdep.c index 17fe49455702..68bbf298045e 100644 --- a/sys/alpha/alpha/vm_machdep.c +++ b/sys/alpha/alpha/vm_machdep.c @@ -121,8 +121,6 @@ cpu_fork(p1, p2, flags) register struct proc *p1, *p2; int flags; { - struct user *up = p2->p_addr; - if ((flags & RFPROC) == 0) return; @@ -133,7 +131,7 @@ cpu_fork(p1, p2, flags) * Cache the physical address of the pcb, so we can * swap to it easily. */ - p2->p_md.md_pcbpaddr = (void*) vtophys((vm_offset_t) &up->u_pcb); + p2->p_md.md_pcbpaddr = (void*)vtophys((vm_offset_t)&p2->p_addr->u_pcb); /* * Copy floating point state from the FP chip to the PCB @@ -176,6 +174,7 @@ cpu_fork(p1, p2, flags) * create the child's kernel stack, from scratch. */ { + struct user *up = p2->p_addr; struct trapframe *p2tf; /* diff --git a/sys/powerpc/aim/vm_machdep.c b/sys/powerpc/aim/vm_machdep.c index 17fe49455702..68bbf298045e 100644 --- a/sys/powerpc/aim/vm_machdep.c +++ b/sys/powerpc/aim/vm_machdep.c @@ -121,8 +121,6 @@ cpu_fork(p1, p2, flags) register struct proc *p1, *p2; int flags; { - struct user *up = p2->p_addr; - if ((flags & RFPROC) == 0) return; @@ -133,7 +131,7 @@ cpu_fork(p1, p2, flags) * Cache the physical address of the pcb, so we can * swap to it easily. */ - p2->p_md.md_pcbpaddr = (void*) vtophys((vm_offset_t) &up->u_pcb); + p2->p_md.md_pcbpaddr = (void*)vtophys((vm_offset_t)&p2->p_addr->u_pcb); /* * Copy floating point state from the FP chip to the PCB @@ -176,6 +174,7 @@ cpu_fork(p1, p2, flags) * create the child's kernel stack, from scratch. */ { + struct user *up = p2->p_addr; struct trapframe *p2tf; /* diff --git a/sys/powerpc/powerpc/vm_machdep.c b/sys/powerpc/powerpc/vm_machdep.c index 17fe49455702..68bbf298045e 100644 --- a/sys/powerpc/powerpc/vm_machdep.c +++ b/sys/powerpc/powerpc/vm_machdep.c @@ -121,8 +121,6 @@ cpu_fork(p1, p2, flags) register struct proc *p1, *p2; int flags; { - struct user *up = p2->p_addr; - if ((flags & RFPROC) == 0) return; @@ -133,7 +131,7 @@ cpu_fork(p1, p2, flags) * Cache the physical address of the pcb, so we can * swap to it easily. */ - p2->p_md.md_pcbpaddr = (void*) vtophys((vm_offset_t) &up->u_pcb); + p2->p_md.md_pcbpaddr = (void*)vtophys((vm_offset_t)&p2->p_addr->u_pcb); /* * Copy floating point state from the FP chip to the PCB @@ -176,6 +174,7 @@ cpu_fork(p1, p2, flags) * create the child's kernel stack, from scratch. */ { + struct user *up = p2->p_addr; struct trapframe *p2tf; /*