diff options
author | dyson <dyson@FreeBSD.org> | 1996-06-11 23:52:27 +0000 |
---|---|---|
committer | dyson <dyson@FreeBSD.org> | 1996-06-11 23:52:27 +0000 |
commit | 94ca54ddd28985e6cbd836d5352b0cd5dfdeb4ff (patch) | |
tree | 74deff0db4cf6ea826ac408497cbc503af50cbf4 /sys | |
parent | 1ad26364cdbfce3d346200a3d9879eea363f25ba (diff) | |
download | FreeBSD-src-94ca54ddd28985e6cbd836d5352b0cd5dfdeb4ff.zip FreeBSD-src-94ca54ddd28985e6cbd836d5352b0cd5dfdeb4ff.tar.gz |
Properly lock the vm space when accessing the memory in a process. This
fix could solve some "interesting" problems that could happen during
process rundown.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/fs/procfs/procfs_mem.c | 16 | ||||
-rw-r--r-- | sys/miscfs/procfs/procfs_mem.c | 16 |
2 files changed, 28 insertions, 4 deletions
diff --git a/sys/fs/procfs/procfs_mem.c b/sys/fs/procfs/procfs_mem.c index 04b3a37..34d7f35 100644 --- a/sys/fs/procfs/procfs_mem.c +++ b/sys/fs/procfs/procfs_mem.c @@ -37,7 +37,7 @@ * * @(#)procfs_mem.c 8.4 (Berkeley) 1/21/94 * - * $Id: procfs_mem.c,v 1.16 1996/01/24 18:41:06 peter Exp $ + * $Id: procfs_mem.c,v 1.17 1996/01/25 06:05:38 peter Exp $ */ /* @@ -73,6 +73,17 @@ procfs_rwmem(p, uio) { int error; int writing; + struct vmspace *vm; + + /* + * if the vmspace is in the midst of being deallocated or the + * process is exiting, don't try to grab anything. The page table + * usage in that process can be messed up. + */ + vm = p->p_vmspace; + if ((p->p_flag & P_WEXIT) || (vm->vm_refcnt < 1)) + return EFAULT; + ++vm->vm_refcnt; writing = uio->uio_rw == UIO_WRITE; @@ -144,7 +155,7 @@ procfs_rwmem(p, uio) /* * The map we want... */ - map = &p->p_vmspace->vm_map; + map = &vm->vm_map; /* * Check the permissions for the area we're interested @@ -230,6 +241,7 @@ procfs_rwmem(p, uio) VM_PROT_READ|VM_PROT_EXECUTE, 0); } while (error == 0 && uio->uio_resid > 0); + vmspace_free(vm); return (error); } diff --git a/sys/miscfs/procfs/procfs_mem.c b/sys/miscfs/procfs/procfs_mem.c index 04b3a37..34d7f35 100644 --- a/sys/miscfs/procfs/procfs_mem.c +++ b/sys/miscfs/procfs/procfs_mem.c @@ -37,7 +37,7 @@ * * @(#)procfs_mem.c 8.4 (Berkeley) 1/21/94 * - * $Id: procfs_mem.c,v 1.16 1996/01/24 18:41:06 peter Exp $ + * $Id: procfs_mem.c,v 1.17 1996/01/25 06:05:38 peter Exp $ */ /* @@ -73,6 +73,17 @@ procfs_rwmem(p, uio) { int error; int writing; + struct vmspace *vm; + + /* + * if the vmspace is in the midst of being deallocated or the + * process is exiting, don't try to grab anything. The page table + * usage in that process can be messed up. + */ + vm = p->p_vmspace; + if ((p->p_flag & P_WEXIT) || (vm->vm_refcnt < 1)) + return EFAULT; + ++vm->vm_refcnt; writing = uio->uio_rw == UIO_WRITE; @@ -144,7 +155,7 @@ procfs_rwmem(p, uio) /* * The map we want... */ - map = &p->p_vmspace->vm_map; + map = &vm->vm_map; /* * Check the permissions for the area we're interested @@ -230,6 +241,7 @@ procfs_rwmem(p, uio) VM_PROT_READ|VM_PROT_EXECUTE, 0); } while (error == 0 && uio->uio_resid > 0); + vmspace_free(vm); return (error); } |