From owner-svn-src-head@FreeBSD.ORG Fri Dec 12 12:12:37 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EAE0C106564A; Fri, 12 Dec 2008 12:12:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D98C88FC12; Fri, 12 Dec 2008 12:12:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBCCCaIh097169; Fri, 12 Dec 2008 12:12:36 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBCCCaEn097166; Fri, 12 Dec 2008 12:12:36 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200812121212.mBCCCaEn097166@svn.freebsd.org> From: Konstantin Belousov Date: Fri, 12 Dec 2008 12:12:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185984 - in head/sys: compat/linprocfs fs/procfs kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Dec 2008 12:12:37 -0000 Author: kib Date: Fri Dec 12 12:12:36 2008 New Revision: 185984 URL: http://svn.freebsd.org/changeset/base/185984 Log: Reference the vmspace of the process being inspected by procfs, linprocfs and sysctl kern_proc_vmmap handlers. Reported and tested by: pho Reviewed by: rwatson, des MFC after: 1 week Modified: head/sys/compat/linprocfs/linprocfs.c head/sys/fs/procfs/procfs_map.c head/sys/kern/kern_proc.c Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Fri Dec 12 12:06:28 2008 (r185983) +++ head/sys/compat/linprocfs/linprocfs.c Fri Dec 12 12:12:36 2008 (r185984) @@ -79,6 +79,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -874,7 +875,8 @@ linprocfs_doprocenviron(PFS_FILL_ARGS) static int linprocfs_doprocmaps(PFS_FILL_ARGS) { - vm_map_t map = &p->p_vmspace->vm_map; + struct vmspace *vm; + vm_map_t map; vm_map_entry_t entry, tmp_entry; vm_object_t obj, tobj, lobj; vm_offset_t e_start, e_end; @@ -899,6 +901,10 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) return (EOPNOTSUPP); error = 0; + vm = vmspace_acquire_ref(p); + if (vm == NULL) + return (ESRCH); + map = &vm->vm_map; vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { @@ -985,6 +991,7 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); return (error); } Modified: head/sys/fs/procfs/procfs_map.c ============================================================================== --- head/sys/fs/procfs/procfs_map.c Fri Dec 12 12:06:28 2008 (r185983) +++ head/sys/fs/procfs/procfs_map.c Fri Dec 12 12:12:36 2008 (r185984) @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -82,7 +83,8 @@ extern struct sysentvec ia32_freebsd_sys int procfs_doprocmap(PFS_FILL_ARGS) { - vm_map_t map = &p->p_vmspace->vm_map; + struct vmspace *vm; + vm_map_t map; vm_map_entry_t entry, tmp_entry; struct vnode *vp; char *fullpath, *freepath; @@ -109,6 +111,10 @@ procfs_doprocmap(PFS_FILL_ARGS) } #endif + vm = vmspace_acquire_ref(p); + if (vm == NULL) + return (ESRCH); + map = &vm->vm_map; vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { @@ -235,5 +241,6 @@ procfs_doprocmap(PFS_FILL_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); return (error); } Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Fri Dec 12 12:06:28 2008 (r185983) +++ head/sys/kern/kern_proc.c Fri Dec 12 12:12:36 2008 (r185984) @@ -1357,6 +1357,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A struct vnode *vp; struct proc *p; vm_map_t map; + struct vmspace *vm; name = (int *)arg1; if ((p = pfind((pid_t)name[0])) == NULL) @@ -1371,7 +1372,11 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A } _PHOLD(p); PROC_UNLOCK(p); - + vm = vmspace_acquire_ref(p); + if (vm == NULL) { + PRELE(p); + return (ESRCH); + } kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK); map = &p->p_vmspace->vm_map; /* XXXRW: More locking required? */ @@ -1501,6 +1506,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A } } vm_map_unlock_read(map); + vmspace_free(vm); PRELE(p); free(kve, M_TEMP); return (error); @@ -1523,6 +1529,7 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR int error, *name; struct vnode *vp; struct proc *p; + struct vmspace *vm; vm_map_t map; name = (int *)arg1; @@ -1538,10 +1545,14 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR } _PHOLD(p); PROC_UNLOCK(p); - + vm = vmspace_acquire_ref(p); + if (vm == NULL) { + PRELE(p); + return (ESRCH); + } kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK); - map = &p->p_vmspace->vm_map; /* XXXRW: More locking required? */ + map = &vm->vm_map; /* XXXRW: More locking required? */ vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { @@ -1672,6 +1683,7 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR } } vm_map_unlock_read(map); + vmspace_free(vm); PRELE(p); free(kve, M_TEMP); return (error);