Date: Fri, 19 Dec 2008 15:32:48 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r186325 - in stable/7/sys: . compat/linprocfs contrib/pf dev/cxgb fs/procfs kern Message-ID: <200812191532.mBJFWmFr075735@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Fri Dec 19 15:32:48 2008 New Revision: 186325 URL: http://svn.freebsd.org/changeset/base/186325 Log: MFC r185984: Reference the vmspace of the process being inspected by procfs, linprocfs and sysctl kern_proc_vmmap handlers. Approved by: re (kensmith) Modified: stable/7/sys/ (props changed) stable/7/sys/compat/linprocfs/linprocfs.c stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/cxgb/ (props changed) stable/7/sys/fs/procfs/procfs_map.c stable/7/sys/kern/kern_proc.c Modified: stable/7/sys/compat/linprocfs/linprocfs.c ============================================================================== --- stable/7/sys/compat/linprocfs/linprocfs.c Fri Dec 19 15:24:18 2008 (r186324) +++ stable/7/sys/compat/linprocfs/linprocfs.c Fri Dec 19 15:32:48 2008 (r186325) @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$"); #include <net/if.h> #include <vm/vm.h> +#include <vm/vm_extern.h> #include <vm/pmap.h> #include <vm/vm_map.h> #include <vm/vm_param.h> @@ -868,7 +869,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; @@ -893,6 +895,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) { @@ -979,6 +985,7 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); return (error); } Modified: stable/7/sys/fs/procfs/procfs_map.c ============================================================================== --- stable/7/sys/fs/procfs/procfs_map.c Fri Dec 19 15:24:18 2008 (r186324) +++ stable/7/sys/fs/procfs/procfs_map.c Fri Dec 19 15:32:48 2008 (r186325) @@ -53,6 +53,7 @@ #include <fs/procfs/procfs.h> #include <vm/vm.h> +#include <vm/vm_extern.h> #include <vm/pmap.h> #include <vm/vm_map.h> #include <vm/vm_page.h> @@ -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) { @@ -236,5 +242,6 @@ procfs_doprocmap(PFS_FILL_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); return (error); } Modified: stable/7/sys/kern/kern_proc.c ============================================================================== --- stable/7/sys/kern/kern_proc.c Fri Dec 19 15:24:18 2008 (r186324) +++ stable/7/sys/kern/kern_proc.c Fri Dec 19 15:32:48 2008 (r186325) @@ -1358,6 +1358,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) @@ -1372,7 +1373,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? */ @@ -1503,6 +1508,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A } } vm_map_unlock_read(map); + vmspace_free(vm); PRELE(p); free(kve, M_TEMP); return (error); @@ -1524,6 +1530,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; @@ -1539,10 +1546,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) { @@ -1674,6 +1685,7 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR } } vm_map_unlock_read(map); + vmspace_free(vm); PRELE(p); free(kve, M_TEMP); return (error);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812191532.mBJFWmFr075735>